コード例 #1
0
/* NOTE: For now, since this function has special significance only for
 * 'string' type properties, callers should (preferably) use it for fetching
 * such properties alone. If callers are sure that proptag would, for instance,
 * return an 'int' or a 'systime', they should prefer find_SPropValue_data.
 */
gconstpointer
e_mapi_util_find_row_propval (struct SRow *aRow, uint32_t proptag)
{
	if (((proptag & 0xFFFF) == PT_STRING8) ||
	    ((proptag & 0xFFFF) == PT_UNICODE)) {
		const void	*str = NULL;

		proptag = (proptag & 0xFFFF0000) | PT_UNICODE;
		str = find_SPropValue_data(aRow, proptag);
		if (str)
			return str;

		proptag = (proptag & 0xFFFF0000) | PT_STRING8;
		str = find_SPropValue_data(aRow, proptag);
		if (str)
			return str;

		return NULL;
	}

	/* NOTE: Similar generalizations (if any) for other property types
	 * can be made here.
	 */

	return (find_SPropValue_data(aRow, proptag));
}
コード例 #2
0
ファイル: mapidump.c プロジェクト: ThHirsch/openchange
/**
   \details This function dumps message information retrieved from
   OpenMessage call. It provides a quick method to print message
   summaries with information such as subject and recipients.

   \param obj_message pointer to the MAPI message object to use
 */
_PUBLIC_ void mapidump_message_summary(mapi_object_t *obj_message)
{
	mapi_object_message_t		*msg;
	int				*recipient_type;
	const char			*recipient;
	uint32_t			i;

	if (!obj_message) return;
	if (!obj_message->private_data) return;

	msg = (mapi_object_message_t *) obj_message->private_data;

	printf("Subject: ");
	if (msg->SubjectPrefix) {
		printf("[%s] ", msg->SubjectPrefix);
	}

	if (msg->NormalizedSubject) {
		printf("%s", msg->NormalizedSubject);
	}
	printf("\n");

	if (!&(msg->SRowSet)) return;
	for (i = 0; i < msg->SRowSet.cRows; i++) {
		recipient_type = (int *) find_SPropValue_data(&(msg->SRowSet.aRow[i]), PR_RECIPIENT_TYPE);
		recipient = (const char *) find_SPropValue_data(&(msg->SRowSet.aRow[i]), PR_SMTP_ADDRESS_UNICODE);
		if (!recipient) {
			recipient = (const char *) find_SPropValue_data(&(msg->SRowSet.aRow[i]), PR_SMTP_ADDRESS);
		}
		if (recipient_type && recipient) {
			switch (*recipient_type) {
			case MAPI_ORIG:
				printf("From: %s\n", recipient);
				break;
			case MAPI_TO:
				printf("To: %s\n", recipient);
				break;
			case MAPI_CC:
				printf("Cc: %s\n", recipient);
				break;
			case MAPI_BCC:
				printf("Bcc: %s\n", recipient);
				break;
			}
		}
	}
	printf("\n");
}
コード例 #3
0
static void *fetchmail_get_propval(struct SRow *aRow, 
				   uint32_t proptag)
{
	const char	*str;

	if (((proptag & 0xFFFF) == PT_STRING8) ||
	    ((proptag & 0xFFFF) == PT_UNICODE)) {
		proptag = (proptag & 0xFFFF0000) | PT_UNICODE;
		str = (const char *) find_SPropValue_data(aRow, proptag);
		if (str) return (void *)str;

		proptag = (proptag & 0xFFFF0000) | PT_STRING8;
		str = (const char *) find_SPropValue_data(aRow, proptag);
		return (void *)str;
	} 

	return (void *)find_SPropValue_data(aRow, proptag);
}
コード例 #4
0
static uint32_t _module_fetchmail_run(TALLOC_CTX *mem_ctx, 
				      struct mapi_session *session)
{
	enum MAPISTATUS		retval;
	mapi_object_t		obj_store;
	mapi_object_t		obj_inbox;
	mapi_object_t		obj_table;
	mapi_object_t		obj_message;
	mapi_object_t		obj_table_attach;
	mapi_object_t		obj_attach;
	mapi_object_t		obj_stream;
	uint64_t		id_inbox = 0;
	struct SPropTagArray	*SPropTagArray;
	struct SRowSet		SRowSet;
	struct SRowSet		SRowSet_attach;
	uint32_t		i, j;
	uint32_t		count;
	const uint8_t		*has_attach;
	const uint32_t		*attach_num;
	uint16_t		read_size;
	unsigned char		buf[MAX_READ_SIZE];

	/* Log onto the store */
	memset(&obj_store, 0, sizeof(mapi_object_t));
	memset(&obj_inbox, 0, sizeof(mapi_object_t));
	memset(&obj_table, 0, sizeof(mapi_object_t));
	memset(&obj_message, 0, sizeof(mapi_object_t));
	memset(&obj_table_attach, 0, sizeof(mapi_object_t));
	memset(&obj_attach, 0, sizeof(mapi_object_t));
	memset(&obj_stream, 0, sizeof(mapi_object_t));

	mapi_object_init(&obj_store);
	retval = OpenMsgStore(session, &obj_store);
	if (retval) {
		mapi_errstr("OpenMsgStore", GetLastError());
		return OCSIM_ERROR;
	}

	/* Open default receive folder (Inbox) */
	retval = GetReceiveFolder(&obj_store, &id_inbox, NULL);
	if (retval) {
		mapi_errstr("GetReceiveFolder", GetLastError());
		return OCSIM_ERROR;
	}

	retval = OpenFolder(&obj_store, id_inbox, &obj_inbox);
	if (retval) {
		mapi_errstr("OpenFolder", GetLastError());
		return OCSIM_ERROR;
	}

	/* Open the contents table and customize the view */
	mapi_object_init(&obj_table);
	retval = GetContentsTable(&obj_inbox, &obj_table, 0, &count);
	if (retval) {
		mapi_errstr("GetContentsTable", GetLastError());
		return OCSIM_ERROR;
	}

	SPropTagArray = set_SPropTagArray(mem_ctx, 0x5,
					  PR_FID,
					  PR_MID,
					  PR_INST_ID,
					  PR_INSTANCE_NUM,
					  PR_SUBJECT);
	retval = SetColumns(&obj_table, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	if (retval) {
		mapi_errstr("SetColumns", GetLastError());		
		return OCSIM_ERROR;
	}

	/* Retrieve the messages and attachments */
	while ((retval = QueryRows(&obj_table, count, TBL_ADVANCE, &SRowSet)) != MAPI_E_NOT_FOUND && SRowSet.cRows) {
		count -= SRowSet.cRows;
		for (i = 0; i < SRowSet.cRows; i++) {
			mapi_object_init(&obj_message);
			retval = OpenMessage(&obj_store,
					     SRowSet.aRow[i].lpProps[0].value.d,
					     SRowSet.aRow[i].lpProps[0].value.d,
					     &obj_message, 0);
			if (GetLastError() == MAPI_E_SUCCESS) {
				struct SPropValue	*lpProps;
				struct SRow		aRow;

				SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_HASATTACH);
				lpProps = talloc_zero(mem_ctx, struct SPropValue);
				retval = GetProps(&obj_message, 0, SPropTagArray, &lpProps, &count);
				MAPIFreeBuffer(SPropTagArray);
				if (retval) {
					mapi_errstr("GetProps", GetLastError());
					return OCSIM_ERROR;
				}

				aRow.ulAdrEntryPad = 0;
				aRow.cValues = count;
				aRow.lpProps = lpProps;

				retval = fetchmail_get_contents(mem_ctx, &obj_message);

				has_attach = (const uint8_t *) get_SPropValue_SRow_data(&aRow, PR_HASATTACH);
				if (has_attach && *has_attach) {
					mapi_object_init(&obj_table_attach);
					retval = GetAttachmentTable(&obj_message, &obj_table_attach);
					if (retval == MAPI_E_SUCCESS) {
						SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ATTACH_NUM);
						retval = SetColumns(&obj_table_attach, SPropTagArray);
						if (retval != MAPI_E_SUCCESS) return retval;
						MAPIFreeBuffer(SPropTagArray);

						retval = QueryRows(&obj_table_attach, 0xA, TBL_ADVANCE, &SRowSet_attach);
						if (retval != MAPI_E_SUCCESS) return retval;

						for (j = 0; j < SRowSet_attach.cRows; j++) {
							attach_num = (const uint32_t *) find_SPropValue_data(&(SRowSet_attach.aRow[j]), PR_ATTACH_NUM);
							mapi_object_init(&obj_attach);
							retval = OpenAttach(&obj_message, *attach_num, &obj_attach);
							if (retval == MAPI_E_SUCCESS) {
								struct SPropValue	*lpProps2;
								uint32_t		count2;

								SPropTagArray = set_SPropTagArray(mem_ctx, 0x3,
												  PR_ATTACH_FILENAME,
												  PR_ATTACH_LONG_FILENAME,
												  PR_ATTACH_SIZE);
								lpProps2 = talloc_zero(mem_ctx, struct SPropValue);
								retval = GetProps(&obj_attach, 0, SPropTagArray, &lpProps2, &count2);
								MAPIFreeBuffer(SPropTagArray);
								if (retval != MAPI_E_SUCCESS) {
									MAPIFreeBuffer(lpProps2);
									return retval;
								}
								MAPIFreeBuffer(lpProps2);

								mapi_object_init(&obj_stream);
								retval = OpenStream(&obj_attach, PR_ATTACH_DATA_BIN, 0, &obj_stream);
								if (retval != MAPI_E_SUCCESS) return retval;

								read_size = 0;
								do {
									retval = ReadStream(&obj_stream, buf, MAX_READ_SIZE, &read_size);
									if (retval != MAPI_E_SUCCESS) break;
								} while (read_size);

								mapi_object_release(&obj_stream);
								mapi_object_release(&obj_attach);
							}
						}
					}
				}

				MAPIFreeBuffer(lpProps);
			}
			mapi_object_release(&obj_message);
		}
コード例 #5
0
ファイル: exchange2ical.c プロジェクト: ThHirsch/openchange
static uint8_t exchange2ical_exception_from_EmbeddedObj(struct exchange2ical *exchange2ical, struct exchange2ical_check *exchange2ical_check)
{
	mapi_object_t			obj_tb_attach;
	mapi_object_t			obj_attach;
	struct SRowSet			rowset_attach;
	struct SPropTagArray		*SPropTagArray;
	const uint32_t			*attach_num;
	struct SPropValue		*lpProps;
	enum MAPISTATUS			retval;
	unsigned int			i;
	uint32_t			count;
	struct SRow			aRow2;
	struct SRow			aRowT;
	
	mapi_object_init(&obj_tb_attach);
	retval = GetAttachmentTable(&exchange2ical->obj_message, &obj_tb_attach);
	if (retval != MAPI_E_SUCCESS) {
		return 1;
	}else {
		SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x1, PR_ATTACH_NUM);
		retval = SetColumns(&obj_tb_attach, SPropTagArray);
		MAPIFreeBuffer(SPropTagArray);
		retval = QueryRows(&obj_tb_attach, 0xa, TBL_ADVANCE, TBL_FORWARD_READ, &rowset_attach);

		for (i = 0; i < rowset_attach.cRows; i++) {
			
			attach_num = (const uint32_t *)find_SPropValue_data(&(rowset_attach.aRow[i]), PR_ATTACH_NUM);
			retval = OpenAttach(&exchange2ical->obj_message, *attach_num, &obj_attach);

			if (retval != MAPI_E_SUCCESS) {
				return 1;
			}else {
				SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x3,
									  PR_ATTACH_METHOD,
									  PR_ATTACHMENT_FLAGS,
									  PR_ATTACHMENT_HIDDEN
									  );
									  
				lpProps = NULL;
				retval = GetProps(&obj_attach, 0, SPropTagArray, &lpProps, &count);
				MAPIFreeBuffer(SPropTagArray);
				if (retval != MAPI_E_SUCCESS) {
					return 1;
				}else {
					aRow2.ulAdrEntryPad = 0;
					aRow2.cValues = count;
					aRow2.lpProps = lpProps;
					
					uint32_t	*attachmentFlags;
					uint32_t	*attachMethod;
					uint8_t		*attachmentHidden;
					
					attachmentFlags	 = (uint32_t *) octool_get_propval(&aRow2, PR_ATTACHMENT_FLAGS);
					attachMethod	 = (uint32_t *) octool_get_propval(&aRow2, PR_ATTACH_METHOD);
					attachmentHidden = (uint8_t *) octool_get_propval(&aRow2, PR_ATTACHMENT_HIDDEN);

					if(attachmentFlags && (*attachmentFlags & 0x00000002) 
						&& (*attachMethod == 0x00000005) 
						&& (attachmentHidden && (*attachmentHidden))) {
					
						struct exchange2ical exception;
						exchange2ical_init(exchange2ical->mem_ctx,&exception);
					
						mapi_object_init(&exception.obj_message);
						
						retval = OpenEmbeddedMessage(&obj_attach, &exception.obj_message, MAPI_READONLY);
						if (retval != MAPI_E_SUCCESS) {
							return 1;
						}else {							
 							SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x2d,
												PidLidFExceptionalBody,
												PidLidRecurring,
												PidLidAppointmentRecur,
												PidLidAppointmentStateFlags,
												PidLidTimeZoneDescription,
												PidLidTimeZoneStruct,
												PidLidAppointmentStartWhole,
												PidLidAppointmentEndWhole,
												PidLidAppointmentSubType,
												PidLidOwnerCriticalChange,
												PidLidLocation,
												PidLidExceptionReplaceTime,
												PidLidNonSendableBcc,
												PidLidAppointmentSequence,
												PidLidBusyStatus,
												PidLidIntendedBusyStatus,
												PidLidCleanGlobalObjectId,
												PidLidAttendeeCriticalChange,
												PidLidAppointmentReplyTime,
												PidLidAppointmentNotAllowPropose,
												PidLidAllowExternalCheck,
												PidLidAppointmentLastSequence,
												PidLidAppointmentSequenceTime,
												PidLidAutoFillLocation,
												PidLidAutoStartCheck,
												PidLidCollaborateDoc,
												PidLidConferencingCheck,
												PidLidConferencingType,
												PidLidDirectory,
												PidLidNetShowUrl,
												PidLidOnlinePassword,
												PidLidOrganizerAlias,
												PidLidReminderSet,
												PidLidReminderDelta,
												PR_MESSAGE_CLASS_UNICODE,
												PR_BODY_UNICODE,
												PR_CREATION_TIME,
												PR_LAST_MODIFICATION_TIME,
												PR_IMPORTANCE,
												PR_RESPONSE_REQUESTED,
												PR_SUBJECT_UNICODE,
												PR_OWNER_APPT_ID,
												PR_SENDER_NAME,
												PR_SENDER_EMAIL_ADDRESS,
												PR_MESSAGE_LOCALE_ID
 								  );
								  
								  
		
							retval = GetProps(&exception.obj_message, MAPI_UNICODE, SPropTagArray, &lpProps, &count);
							
							if (retval == MAPI_E_SUCCESS) {	
								aRow2.ulAdrEntryPad = 0;
								aRow2.cValues = count;
								aRow2.lpProps = lpProps;
								
								
								/*Get required properties to check if right event*/
								exchange2ical_get_properties(exchange2ical->mem_ctx, &aRow2, &exception, exchange2ical_check->eFlags);
					
								/*Check to see if event is acceptable*/
								if (!checkEvent(&exception, exchange2ical_check, get_tm_from_FILETIME(exception.apptStartWhole))){
									break;
								}

								/*Grab Rest of Properties*/
								exchange2ical_get_properties(exchange2ical->mem_ctx, &aRow2, &exception, exchange2ical_check->eFlags | EntireFlag);
								uint8_t *dBody = (uint8_t *) octool_get_propval(&aRow2, PidLidFExceptionalBody);
								retval = GetRecipientTable(&exception.obj_message, 
									&exception.Recipients.SRowSet,
									&exception.Recipients.SPropTagArray);
									
								/*Check for set subject*/
								if (!exception.Subject){
									exception.Subject=exchange2ical->Subject;
								}
								/*Check for a set apptSubType*/
								if (!exception.apptSubType){
									exception.apptSubType=exchange2ical->apptSubType;
								}
								/*check for a set Location*/
								if (!exception.Location){
									exception.Location=exchange2ical->Location;
								}
								/*check for set valarm info*/
								if(!exception.ReminderSet){
									exception.ReminderSet=exchange2ical->ReminderSet;
								}
								if(!exception.ReminderDelta){
									exception.ReminderDelta=exchange2ical->ReminderDelta;
								}
								
								/*Set to same vcalendar as parent*/
								exception.vcalendar=exchange2ical->vcalendar;
								
								/*Set to same uid fallback in case GlobalObjId is missing*/
								exception.idx=exchange2ical->idx;
								
								
								/*has a modified summary*/
								if(dBody && *dBody){
									SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x1, PR_BODY_HTML_UNICODE);
									retval = GetProps(&exception.obj_message, MAPI_UNICODE, SPropTagArray, &lpProps, &count);
									MAPIFreeBuffer(SPropTagArray);
									if (retval == MAPI_E_SUCCESS) {
										aRowT.ulAdrEntryPad = 0;
										aRowT.cValues = count;
										aRowT.lpProps = lpProps;
										exception.bodyHTML = (const char *)octool_get_propval(&aRowT, PR_BODY_HTML_UNICODE);
									}
								/* has the same summary as parent*/
								} else{
									exception.body=exchange2ical->body;
									exception.bodyHTML=exchange2ical->bodyHTML;
								}
								
								ical_component_VEVENT(&exception);
								exception.vcalendar=NULL;
								exchange2ical_clear(&exception);
							}
						} 							
						mapi_object_release(&exception.obj_message);
					}
					MAPIFreeBuffer(lpProps);
				}
			}
			
		}

	}
	mapi_object_release(&obj_tb_attach);
	return 0;	
}
コード例 #6
0
ファイル: import.c プロジェクト: AJStubzy/zentyal
static enum MAPISTATUS import_directory(TALLOC_CTX *mem_ctx,
                    const struct mbox_data *mdata,
                    mapi_object_t *obj_store,
                    mapi_object_t *obj_parent,
                    const char *base_path)
{
    enum MAPISTATUS retval;
    DIR     *dirp;
    struct dirent   *direntp;
    mapi_object_t   obj_folder;
    mapi_object_t   obj_inbox;
    mapi_object_t   obj_child;
    mapi_id_t   id_folder;
    char        *folder_id;
    char        *olFolderSrc;
    struct SPropTagArray        *SPropTagArray;
    struct SPropValue   *lpProps;
    uint32_t        cValues = 0;
    struct SRow          aRow;

    DEBUG(5,("[*] Importing directory %s\n", base_path));

    /* Open the filesystem folder */
    dirp = opendir(base_path);
    if (!dirp) {
        DEBUG(0, ("[!] Error opening directory %s: %s (%d)\n",
            base_path, strerror(errno), errno));
        return MAPI_E_NOT_FOUND; // TODO map to proper code
    }

    mapi_object_init(&obj_folder);
    mapi_object_init(&obj_child);
    mapi_object_init(&obj_inbox);

    /* I want to get the folder ID from the remote Exchange server and
    check in the systemfolder database if it matches with something.
    we can get the remote folder ID from the directory name */
    folder_id = import_get_folder_id(base_path);
    if (!folder_id) {
        DEBUG(0, ("[!] Error getting folder ID from directory name\n"));
        return MAPI_E_NOT_FOUND; // TODO map to proper code
    }

    if (!obj_parent) {
        DEBUG(5, ("parent is null\n"));

        retval = GetDefaultFolder(obj_store, &id_folder, olFolderInbox);
        if (retval != MAPI_E_SUCCESS) {
            DEBUG(0, ("[!] GetDefaultFolder: %s\n", mapi_get_errstr(GetLastError())));
            return retval;
        }
        DEBUG(4, ("[*] Opening folder %u\n", olFolderInbox));
        retval = OpenFolder(obj_store, id_folder, &obj_inbox);
        if (retval != MAPI_E_SUCCESS) {
            DEBUG(0, ("[!] OpenFolder: %s\n", mapi_get_errstr(GetLastError())));
            return retval;
        }
        obj_parent = &obj_inbox;
    }

    /* XXX Begin of hack */
#if 0
    olFolderSrc = import_is_system_folder(mdata, folder_id);
    if (!olFolderSrc) {
        DEBUG(5, ("[*] Not system folder, skip\n"));
        talloc_free(olFolderSrc);
        return MAPI_E_SUCCESS;
    }
    uint32_t olFolder = atoi(olFolderSrc);
    talloc_free(olFolderSrc);
    retval = MAPI_E_SUCCESS;
    if (olFolder == olFolderContacts) {
        retval = GetDefaultFolder(obj_store, &id_folder, olFolderContacts);
    } else if (olFolder == olFolderCalendar) {
        retval = GetDefaultFolder(obj_store, &id_folder, olFolderCalendar);
    } else if (olFolder == olFolderTopInformationStore) {
        retval = GetDefaultFolder(obj_store, &id_folder, olFolderInbox);
    }

    if (retval != MAPI_E_SUCCESS) {
        DEBUG(0, ("[!] GetDefaultFolder: %s\n", mapi_get_errstr(GetLastError())));
        return retval;
    }

    DEBUG(4, ("Opening folder %u\n", olFolder));
    retval = OpenFolder(obj_store, id_folder, &obj_folder);
    if (retval != MAPI_E_SUCCESS) {
        DEBUG(0, ("[!] OpenFolder: %s\n", mapi_get_errstr(GetLastError())));
        return retval;
    }
#endif
    /* XXX end of hack */
#if 1
    olFolderSrc = import_is_system_folder(mdata, folder_id);
    if (olFolderSrc) {
        char *folder_name = import_get_folder_name(mdata, folder_id);
        if (folder_name) {
            DEBUG(5, ("[*] Origin Folder '%s' mapped to name '%s'\n", folder_id, folder_name));
            talloc_free(folder_name);
            folder_name = NULL;
        }
        /* This is a system folder, then I am calling GetDefaultFolder
        to retrieve the id then I open the folder */
        uint32_t olFolder = atoi(olFolderSrc);
        talloc_free(olFolderSrc);

        retval = GetDefaultFolder(obj_store, &id_folder, olFolder);
        if (retval != MAPI_E_SUCCESS) {
            DEBUG(0, ("[!] GetDefaultFolder: %s\n", mapi_get_errstr(GetLastError())));
            return retval;
        }
        DEBUG(4, ("[*] Opening folder %u\n", olFolder));
        retval = OpenFolder(obj_store, id_folder, &obj_folder);
        if (retval != MAPI_E_SUCCESS) {
            DEBUG(0, ("[!] OpenFolder: %s\n", mapi_get_errstr(GetLastError())));
            return retval;
        }


        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PidTagDisplayName);
        retval = GetProps(&obj_folder, MAPI_UNICODE, SPropTagArray, &lpProps, &cValues);
        MAPIFreeBuffer(SPropTagArray);
        if (retval == MAPI_E_SUCCESS) {
            aRow.cValues = cValues;
            aRow.lpProps = lpProps;
            folder_name = (char *) find_SPropValue_data(&aRow, PidTagDisplayName);
            if (folder_name) {
                DEBUG(5, ("[*] Destination Folder: '%s'\n", folder_name));
            }
        }
    } else {
        /*  this is not a system folder, I know what is the root base where
         need to create it i and open it */
        char *folder_name = import_get_folder_name(mdata, folder_id);
        if (!folder_name) {
            DEBUG(0, ("[!] Invalid Folder Name\n"));
            return MAPI_E_INVALID_PARAMETER;
        }
        DEBUG(4, ("[*] Creating folder %s\n", folder_name));
        retval = CreateFolder(obj_parent, FOLDER_GENERIC, folder_name,
                      NULL, OPEN_IF_EXISTS|MAPI_UNICODE, &obj_folder);
        if (retval != MAPI_E_SUCCESS) {
            DEBUG(0, ("[!] CreateFolder: %s\n", mapi_get_errstr(GetLastError())));
            talloc_free(folder_name);
            return retval;
        }
        talloc_free(folder_name);
        return MAPI_E_SUCCESS;
    }
#endif

    /* Import the files and clildren folders */
    while ((direntp = readdir(dirp)) != NULL) {
        if (strcmp(direntp->d_name, ".") == 0) {
            continue;
        }
        if (strcmp(direntp->d_name, "..") == 0) {
            continue;
        }
        char *ext = strrchr(direntp->d_name, '.');
        if (!ext) {
            if (strncasecmp(direntp->d_name, "0x", 2) == 0) {
                char *child_path = talloc_asprintf(mem_ctx, "%s/%s", base_path, direntp->d_name);
                retval = import_directory(mem_ctx, mdata, obj_store, &obj_folder, child_path);
                if (retval != MAPI_E_SUCCESS) {
                        DEBUG(0, ("import_directory failed with %s\n", mapi_get_errstr(GetLastError())));
                        talloc_free(child_path);
                        return retval;
                }
                talloc_free(child_path);
            }
            continue;
        }
        if (strncasecmp(ext, ".ocpf", 5) == 0) {
            char *child_path = talloc_asprintf(mem_ctx, "%s/%s", base_path, direntp->d_name);
            import_ocpf_file(mem_ctx, mdata, obj_store, &obj_folder, child_path);
            talloc_free(child_path);
        }
    }

    mapi_object_release(&obj_folder);
    mapi_object_release(&obj_inbox);

    /* Close directory */
    closedir(dirp);

    return retval;
}
コード例 #7
0
ファイル: fetchmail.c プロジェクト: EasyLinux/Openchange
int main(int argc, char *argv[])
{
        enum MAPISTATUS                 retval;
	struct mapi_context		*mapi_ctx;
	TALLOC_CTX			*mem_ctx;
        struct mapi_session             *session = NULL;
        mapi_object_t                   obj_store;
        mapi_object_t                   obj_folder;
        mapi_object_t                   obj_table;
        mapi_object_t                   obj_message;
        struct mapi_SPropValue_array	props_all;
        struct SRowSet                  rowset;
        struct SPropTagArray            *SPropTagArray;
        mapi_id_t                       id_inbox;
        mapi_id_t                       *fid, *mid;
        char                            *profname;
	char				*profdb;
	uint32_t			Numerator;
	uint32_t			Denominator;
        uint32_t                        i;

	mem_ctx = talloc_named(NULL, 0, "fetchmail");

        /* Initialize MAPI */
	profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB, getenv("HOME"));
        retval = MAPIInitialize(&mapi_ctx, profdb);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Find Default Profile */
        retval = GetDefaultProfile(mapi_ctx, &profname);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Log on EMSMDB and NSPI */
        retval = MapiLogonEx(mapi_ctx, &session, profname, NULL);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Open Message Store */
        mapi_object_init(&obj_store);
        retval = OpenMsgStore(session, &obj_store);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Find Inbox default folder */
        retval = GetDefaultFolder(&obj_store, &id_inbox, olFolderInbox);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Open Inbox folder */
        mapi_object_init(&obj_folder);
        retval = OpenFolder(&obj_store, id_inbox, &obj_folder);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Retrieve Inbox content table */
        mapi_object_init(&obj_table);
        retval = GetContentsTable(&obj_folder, &obj_table, 0x0, NULL);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Create the MAPI table view */
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_FID, PR_MID);
        retval = SetColumns(&obj_table, SPropTagArray);
        MAPIFreeBuffer(SPropTagArray);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);
        talloc_free(mem_ctx);

        /* Get current cursor position */
        retval = QueryPosition(&obj_table, &Numerator, &Denominator);
        MAPI_RETVAL_IF(retval, retval, mem_ctx);

        /* Iterate through rows */
        while ((retval = QueryRows(&obj_table, Denominator, TBL_ADVANCE, &rowset)) 
	       != -1 && rowset.cRows) {
                for (i = 0; i < rowset.cRows; i++) {
			fid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_FID);
			mid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_MID);
			mapi_object_init(&obj_message);
                        retval = OpenMessage(&obj_store, *fid, *mid, &obj_message, 0x0);
                        if (retval != MAPI_E_NOT_FOUND) {
                                retval = GetPropsAll(&obj_message, MAPI_UNICODE, &props_all);
                                mapidump_message(&props_all, NULL, &obj_message);
                                mapi_object_release(&obj_message);
                        }
                }

        }

        /* Release MAPI objects */
        mapi_object_release(&obj_table);
        mapi_object_release(&obj_folder);

	Logoff(&obj_store);

        /* Uninitialize MAPI */
        MAPIUninitialize(mapi_ctx);
        return (0);
}
コード例 #8
0
void ical_property_ATTACH(struct exchange2ical *exchange2ical)
{
	mapi_object_t			obj_tb_attach;
	mapi_object_t			obj_attach;
	mapi_object_t			obj_stream;
	struct SRowSet			rowset_attach;
	struct SPropTagArray		*SPropTagArray = NULL;
	const uint32_t			*attach_num = NULL;
	struct SPropValue		*lpProps;
	enum MAPISTATUS			retval;
	unsigned int			i;
	uint32_t			count;
	struct SRow			aRow2;

	
	mapi_object_init(&obj_tb_attach);
	retval = GetAttachmentTable(&exchange2ical->obj_message, &obj_tb_attach);
	if (retval == MAPI_E_SUCCESS) {
		SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x1, PR_ATTACH_NUM);
		retval = SetColumns(&obj_tb_attach, SPropTagArray);
		MAPIFreeBuffer(SPropTagArray);
		retval = QueryRows(&obj_tb_attach, 0xa, TBL_ADVANCE, &rowset_attach);
		
		for (i = 0; i < rowset_attach.cRows; i++) {
			attach_num = (const uint32_t *)find_SPropValue_data(&(rowset_attach.aRow[i]), PR_ATTACH_NUM);
			retval = OpenAttach(&exchange2ical->obj_message, *attach_num, &obj_attach);

			if (retval == MAPI_E_SUCCESS) {

				SPropTagArray = set_SPropTagArray(exchange2ical->mem_ctx, 0x7,
									  PR_ATTACH_FILENAME,
									  PR_ATTACH_LONG_FILENAME,
									  PR_ATTACH_METHOD,
									  PR_ATTACHMENT_FLAGS,
									  PR_ATTACHMENT_HIDDEN,
									  PR_ATTACH_MIME_TAG,
									  PR_ATTACH_DATA_BIN
									  );
									  
				lpProps = NULL;
				retval = GetProps(&obj_attach, MAPI_UNICODE, SPropTagArray, &lpProps, &count);
				MAPIFreeBuffer(SPropTagArray);
				if (retval == MAPI_E_SUCCESS) {

					uint32_t		*attachmentFlags = NULL;
					uint32_t		*attachMethod = NULL;
					uint8_t			*attachmentHidden = NULL;
					const char 		*data = NULL;
					const char		*fmttype = NULL;
					const char		*attach_filename = NULL;
					DATA_BLOB		body;
					icalattach		*icalattach = NULL;
					icalproperty 		*prop = NULL;
					icalparameter 		*param = NULL;
						
					
					aRow2.ulAdrEntryPad = 0;
					aRow2.cValues = count;
					aRow2.lpProps = lpProps;
					
					attachmentFlags	 = octool_get_propval(&aRow2, PR_ATTACHMENT_FLAGS);
					attachMethod	 = octool_get_propval(&aRow2, PR_ATTACH_METHOD);
					attachmentHidden = octool_get_propval(&aRow2, PR_ATTACHMENT_HIDDEN);

					if(attachmentFlags && !(*attachmentFlags & 0x00000007) 
						&& (*attachMethod == 0x00000001) 
						&& (!attachmentHidden || !(*attachmentHidden))) {

						/* Get data of attachment */
						retval = OpenStream(&obj_attach, PR_ATTACH_DATA_BIN, 0, &obj_stream);
						retval = octool_get_stream(exchange2ical->mem_ctx, &obj_stream, &body);
						data=ldb_base64_encode(exchange2ical->mem_ctx, (const char *)body.data, body.length);
						
						/*Create a new icalattach from above data*/
#if HAVE_ICAL_0_46
						/* the function signature for icalattach_new_from_data() changed in 0.46, released 2010-08-30 */
						/* we can switch to just using the new signature after everyone has had a reasonable chance to update (say end of 2011) */
						icalattach = icalattach_new_from_data(data, 0, 0);
#else
						icalattach = icalattach_new_from_data((unsigned char *)data,0,0);
#endif
						/*Add attach property to vevent component*/
						prop = icalproperty_new_attach(icalattach);
						icalcomponent_add_property(exchange2ical->vevent, prop);

						/* Attachment filename for X-FILENAME parameter*/
						attach_filename = get_filename(octool_get_propval(&aRow2, PR_ATTACH_LONG_FILENAME));
						if (!attach_filename || (attach_filename && !strcmp(attach_filename, ""))) {
							attach_filename = get_filename(octool_get_propval(&aRow2, PR_ATTACH_FILENAME));
						}
						
						/* fmttype parameter */
						fmttype = (const char *) octool_get_propval(&aRow2, PR_ATTACH_MIME_TAG);
						if(fmttype) {
							param = icalparameter_new_fmttype(fmttype);
							icalproperty_add_parameter(prop, param);
						}
						
						/* ENCODING parameter */
						param =icalparameter_new_encoding(ICAL_ENCODING_BASE64);
						icalproperty_add_parameter(prop,param);
						
						/* VALUE parameter */
						param=icalparameter_new_value(ICAL_VALUE_BINARY);
						icalproperty_add_parameter(prop,param);
						
						/* X-FILENAME parameter */
						param = icalparameter_new_x(attach_filename);
						icalparameter_set_xname(param,"X-FILENAME");
						icalproperty_add_parameter(prop,param);
					}
					MAPIFreeBuffer(lpProps);
				}
			}
		}
	}
	mapi_object_release(&obj_tb_attach);
}