Exemplo n.º 1
0
/**
   \details Test #1863 NspiQueryRows and try to build PR_ENTRYID for
   AD user which is not part of OpenChange.

   \param mt pointer to the top level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_zentyal_1863(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	struct PropertyTagArray_r	*MIds;
	struct PropertyRowSet_r		*RowSet;
	struct SPropTagArray		*SPropTagArray;
	struct PropertyValue_r		*lpProp;
	struct Restriction_r		Filter;

	mem_ctx = talloc_named(NULL, 0, "mapitest_zentyal_1863");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	/* Build the array of columns we want to retrieve */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_DISPLAY_NAME,
					  PR_DISPLAY_TYPE);

	/* Build the restriction we want for NspiGetMatches on
	 * existing AD user but not OpenChange one
	 */
	lpProp = talloc_zero(mem_ctx, struct PropertyValue_r);
	lpProp->ulPropTag = PR_ACCOUNT;
	lpProp->dwAlignPad = 0;
	lpProp->value.lpszA = talloc_strdup(lpProp, mt->profile->username);

	Filter.rt = RES_PROPERTY;
	Filter.res.resProperty.relop = RES_PROPERTY;
	Filter.res.resProperty.ulPropTag = PR_ACCOUNT;
	Filter.res.resProperty.lpProp = lpProp;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds);
	MAPIFreeBuffer(lpProp);
	MAPIFreeBuffer(RowSet);
	MAPIFreeBuffer(SPropTagArray);
	mapitest_print_retval_clean(mt, "NspiGetMatches", retval);
	if (retval != MAPI_E_SUCCESS) {
		talloc_free(mem_ctx);
		return false;
	}

	/* Query the rows */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ENTRYID);
	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	retval = nspi_QueryRows(nspi_ctx, mem_ctx, SPropTagArray, MIds, 1, &RowSet);
	MAPIFreeBuffer(SPropTagArray);
	MAPIFreeBuffer(RowSet);
	mapitest_print_retval_clean(mt, "NspiQueryRows", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return false;
	}

	talloc_free(mem_ctx);

	return true;
}
Exemplo n.º 2
0
/**
   \details Test the NspiSeekEntries RPC operation (0x04)

   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_SeekEntries(struct mapitest *mt)
{
	TALLOC_CTX		*mem_ctx;
	enum MAPISTATUS		retval;
	struct nspi_context	*nspi_ctx;
	struct PropertyValue_r	pTarget;
	struct SPropTagArray	*pPropTags;
	struct PropertyRowSet_r		*RowSet;
	struct emsmdb_context	*emsmdb;
	bool			ret = true;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_SeekEntries");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	emsmdb = (struct emsmdb_context *) mt->session->emsmdb->ctx;
	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	
	pTarget.ulPropTag = PR_DISPLAY_NAME;
	pTarget.dwAlignPad = 0x0;
	pTarget.value.lpszA = emsmdb->info.szDisplayName;

	pPropTags = set_SPropTagArray(mem_ctx, 0x1, PR_ACCOUNT);
	retval = nspi_SeekEntries(nspi_ctx, mem_ctx, SortTypeDisplayName, &pTarget, pPropTags, NULL, &RowSet);
	if (retval != MAPI_E_SUCCESS) {
		ret = false;
	}

	mapitest_print_retval_clean(mt, "NspiSeekEntries", retval);
	MAPIFreeBuffer(RowSet);
	MAPIFreeBuffer(pPropTags);

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);

	pTarget.ulPropTag = PR_DISPLAY_NAME_UNICODE;
	pTarget.dwAlignPad = 0x0;
	pTarget.value.lpszA = emsmdb->info.szDisplayName;

	pPropTags = set_SPropTagArray(mem_ctx, 0x1, PR_ACCOUNT);
	retval = nspi_SeekEntries(nspi_ctx, mem_ctx, SortTypeDisplayName, &pTarget, pPropTags, NULL, &RowSet);
	if (retval != MAPI_E_SUCCESS) {
		ret = false;
	}

	mapitest_print_retval_clean(mt, "NspiSeekEntries", retval);
	MAPIFreeBuffer(RowSet);
	MAPIFreeBuffer(pPropTags);

	talloc_free(mem_ctx);

	return ret;
}
Exemplo n.º 3
0
/**
   \details Test the NspiGetPropList RPC operation (0x08)

   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_GetPropList(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	struct SPropTagArray		*pPropTags = 0;
	struct PropertyTagArray_r	*MIds;
	struct PropertyValue_r		*lpProp;
	struct Restriction_r		Filter;
	struct SPropTagArray		*SPropTagArray;
	struct PropertyRowSet_r		*RowSet;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_GetPropList");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	/* Step 1. Query for current profile username */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME);
	lpProp = talloc_zero(mem_ctx, struct PropertyValue_r);
	lpProp->ulPropTag = PR_ANR_UNICODE;
	lpProp->dwAlignPad = 0;
	lpProp->value.lpszW = mt->mapi_ctx->session->profile->username;

	Filter.rt = RES_PROPERTY;
	Filter.res.resProperty.relop = RES_PROPERTY;
	Filter.res.resProperty.ulPropTag = PR_ANR_UNICODE;
	Filter.res.resProperty.lpProp = lpProp;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds);
	MAPIFreeBuffer(SPropTagArray);
	MAPIFreeBuffer(lpProp);
	MAPIFreeBuffer(RowSet);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return retval;
	}


	/* Step 2. Call NspiGetPropList using the MId returned by NspiGetMatches */
	pPropTags = talloc_zero(mt->mem_ctx, struct SPropTagArray);
	retval = nspi_GetPropList(nspi_ctx, mem_ctx, 0, MIds->aulPropTag[0], &pPropTags);
	MAPIFreeBuffer(MIds);
	mapitest_print_retval(mt, "NspiGetPropList");

	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(pPropTags);
		talloc_free(mem_ctx);
		return false;
	}

	if (pPropTags) {
		mapitest_print(mt, "* %-35s: %d\n", "Properties number", pPropTags->cValues);
		MAPIFreeBuffer(pPropTags);
	}
	talloc_free(mem_ctx);

	return true;
}
Exemplo n.º 4
0
/**
   \details Test the SetColumns (0x12) operation

   This function:
   -# Opens the Inbox folder and gets the hierarchy table
   -# Calls the SetColumns operation
   -# Cleans up

   \param mt pointer to the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_oxctable_SetColumns(struct mapitest *mt)
{
	mapi_object_t		obj_htable;
	struct SPropTagArray	*SPropTagArray;

	/* Step 1. Logon */
	if (! mapitest_common_setup(mt, &obj_htable, NULL)) {
		return false;
	}

	/* Step 2. SetColumns */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x3,
					  PR_DISPLAY_NAME,
					  PR_FID,
					  PR_FOLDER_CHILD_COUNT);
	SetColumns(&obj_htable, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	mapitest_print_retval(mt, "SetColumns");
	if (GetLastError() != MAPI_E_SUCCESS) {
		return false;
	}

	/* Step 3. Release */
	mapi_object_release(&obj_htable);
	mapitest_common_cleanup(mt);

	return true;
}
Exemplo n.º 5
0
/**
   \details Test the CreateBookmark (0x1b) operation

   This function:
   -# Opens the Inbox folder and gets the hierarchy table
   -# Customize the MAPI table view
   -# CreateBookmark for each table's row
   -# Free Bookmark for each created bookmark
   -# Cleans up

   \param mt pointer on the top-level mapitest structure
   
   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_oxctable_CreateBookmark(struct mapitest *mt)
{
	enum MAPISTATUS		retval;
	mapi_object_t		obj_htable;
	uint32_t		*bkPosition;
	uint32_t		count;
	uint32_t		i;
	struct SPropTagArray	*SPropTagArray;
	struct SRowSet		SRowSet;


	/* Step 1. Logon */
	if (! mapitest_common_setup(mt, &obj_htable, &count)) {
		return false;
	}

	/* Step 2. Customize the table view */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x3,
					  PR_DISPLAY_NAME,
					  PR_FID,
					  PR_FOLDER_CHILD_COUNT);
	retval = SetColumns(&obj_htable, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	if (retval != MAPI_E_SUCCESS) {
		return false;
	}

	/* Step 3. Create Bookmarks */
	bkPosition = talloc_array(mt->mem_ctx, uint32_t, 1);
	retval = QueryRows(&obj_htable, 100, TBL_ADVANCE, &SRowSet);
	for (i = 0; i < SRowSet.cRows; i++) {
		bkPosition = talloc_realloc(mt->mem_ctx, bkPosition, uint32_t, i + 2);
		retval = CreateBookmark(&obj_htable, &(bkPosition[i]));
		mapitest_print_retval_fmt_clean(mt, "CreateBookmark", retval, "(%.2d)", i);
		if (retval != MAPI_E_SUCCESS) {
			return false;
		}
	}

	retval = mapi_object_bookmark_get_count(&obj_htable, &count);

	/* Step 4. Free Bookmarks */
	for (i = 0; i < count; i++) {
		retval = FreeBookmark(&obj_htable, bkPosition[i]);
		mapitest_print_retval_fmt_clean(mt, "FreeBookmark", retval, "(%.2d)", i);
		if (retval != MAPI_E_SUCCESS) {
			return false;
		}
	}

	/* Step 5. Release */
	mapi_object_release(&obj_htable);
	mapitest_common_cleanup(mt);
	talloc_free(bkPosition);

	return true;
}
Exemplo n.º 6
0
/**
   \details Test the GetGALTable function

   \param mt pointer to the top-level mapitest structure
   
   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_GetGALTable(struct mapitest *mt)
{
	struct SPropTagArray	*SPropTagArray;
	struct PropertyRowSet_r		*RowSet;
	enum MAPISTATUS		retval;
	uint32_t		i;
	uint32_t		count;
	uint8_t			ulFlags;
	uint32_t		rowsFetched = 0;
	uint32_t		totalRowsFetched = 0;
	bool			ret = true;

	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0xc,
					  PR_INSTANCE_KEY,
					  PR_ENTRYID,
					  PR_DISPLAY_NAME_UNICODE,
					  PR_EMAIL_ADDRESS_UNICODE,
					  PR_DISPLAY_TYPE,
					  PR_OBJECT_TYPE,
					  PR_ADDRTYPE_UNICODE,
					  PR_OFFICE_TELEPHONE_NUMBER_UNICODE,
					  PR_OFFICE_LOCATION_UNICODE,
					  PR_TITLE_UNICODE,
					  PR_COMPANY_NAME_UNICODE,
					  PR_ACCOUNT_UNICODE);

	count = 0x20;
	ulFlags = TABLE_START;
	do {
		retval = GetGALTable(mt->session, SPropTagArray, &RowSet, count, ulFlags);
		mapitest_print_retval_clean(mt, "GetGALTable", retval);
		if ((!RowSet) || (!(RowSet->aRow))) {
			ret = false;
			goto cleanup;
		}
		rowsFetched = RowSet->cRows;
		totalRowsFetched += rowsFetched;
		if (rowsFetched) {
			for (i = 0; i < rowsFetched; i++) {
				mapitest_print_PAB_entry(mt, &RowSet->aRow[i]);
			}
		}
		ulFlags = TABLE_CUR;
		MAPIFreeBuffer(RowSet);
	} while (rowsFetched == count);

	if (totalRowsFetched < 1) {
		/* We should always have at least ourselves in the list */
		/* So if we got no rows at all, there is a problem */
		ret = false;
	}
cleanup:
	MAPIFreeBuffer(SPropTagArray);

	return ret;
}
Exemplo n.º 7
0
/**
   \details Test dump using mapidump_SPropTagArray

   This function:
   -# Tests the mapidump_SPropTagArray() function 

   \param mt pointer to the top-level mapitest structure

   \return true on success, otherwise false
   
   \note This currently doesn't check the results are sane, so manual inspection is required
*/ 
_PUBLIC_ bool mapitest_mapidump_sproptagarray(struct mapitest *mt)
{
	struct SPropTagArray *tagarray;

	tagarray = set_SPropTagArray(mt->mem_ctx, 5, PR_SENDER_NAME,
						     PR_BODY,
						     PR_PERSONAL_HOME_PAGE,
						     PR_OTHER_ADDRESS_CITY,
						     (0xDDDD << 16 | PT_LONG));

	mapidump_SPropTagArray(tagarray);

	return true;
}
Exemplo n.º 8
0
static enum MAPISTATUS fetchmail_get_contents(TALLOC_CTX *mem_ctx,
					      mapi_object_t *obj_message)
{
	enum MAPISTATUS			retval;
	struct SPropTagArray		*SPropTagArray;
	struct SPropValue		*lpProps;
	struct SRow			aRow;
	uint32_t			count;
	DATA_BLOB			body;

	/* Build the array of properties we want to fetch */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x13,
					  PR_INTERNET_MESSAGE_ID,
					  PR_INTERNET_MESSAGE_ID_UNICODE,
					  PR_CONVERSATION_TOPIC,
					  PR_CONVERSATION_TOPIC_UNICODE,
					  PR_MSG_EDITOR_FORMAT,
					  PR_BODY,
					  PR_BODY_UNICODE,
					  PR_HTML,
					  PR_RTF_COMPRESSED,
					  PR_SENT_REPRESENTING_NAME,
					  PR_SENT_REPRESENTING_NAME_UNICODE,
					  PR_DISPLAY_TO,
					  PR_DISPLAY_TO_UNICODE,
					  PR_DISPLAY_CC,
					  PR_DISPLAY_CC_UNICODE,
					  PR_DISPLAY_BCC,
					  PR_DISPLAY_BCC_UNICODE,
					  PR_HASATTACH,
					  PR_MESSAGE_CODEPAGE);
	lpProps = talloc_zero(mem_ctx, struct SPropValue);
	retval = GetProps(obj_message, 0, SPropTagArray, &lpProps, &count);
	MAPIFreeBuffer(SPropTagArray);
	MAPI_RETVAL_IF(retval, retval, NULL);

	/* Build a SRow structure */
	aRow.ulAdrEntryPad = 0;
	aRow.cValues = count;
	aRow.lpProps = lpProps;

	retval = fetchmail_get_body(mem_ctx, obj_message, &aRow, &body);
	MAPI_RETVAL_IF(retval, GetLastError(), NULL);
	
	if (body.length) {
		talloc_free(body.data);
	} 

	return MAPI_E_SUCCESS;
}
Exemplo n.º 9
0
folder::message_container_type folder::fetch_messages() throw(mapi_exception)
{
	uint32_t 	contents_table_row_count = 0;
        mapi_object_t	contents_table;

	mapi_object_init(&contents_table);
	if (GetContentsTable(&m_object, &contents_table, 0, &contents_table_row_count) != MAPI_E_SUCCESS) {
		mapi_object_release(&contents_table);
		throw mapi_exception(GetLastError(), "folder::fetch_messages : GetContentsTable");
	}

	SPropTagArray* property_tag_array = set_SPropTagArray(m_session.get_memory_ctx(), 0x2, PR_FID,
											       PR_MID);

	if (SetColumns(&contents_table, property_tag_array) != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(property_tag_array);
		mapi_object_release(&contents_table);
		throw mapi_exception(GetLastError(), "folder::fetch_messages : SetColumns");
	}

	MAPIFreeBuffer(property_tag_array);

	uint32_t rows_to_read = contents_table_row_count;
	SRowSet  row_set;

	message_container_type message_container;
	message_container.reserve(contents_table_row_count);

	while( (QueryRows(&contents_table, rows_to_read, TBL_ADVANCE, &row_set) == MAPI_E_SUCCESS) && row_set.cRows) {
		rows_to_read -= row_set.cRows;
		for (unsigned int i = 0; i < row_set.cRows; ++i) {
			try {
				message_container.push_back(message_shared_ptr(new message(m_session,
											   m_id,
											   row_set.aRow[i].lpProps[1].value.d)));
			} catch(mapi_exception e) {
				mapi_object_release(&contents_table);
				throw;
			}
		}
	}

	mapi_object_release(&contents_table);

	return message_container;
}
Exemplo n.º 10
0
/**
   \details Test the NspiGetProps RPC operation (0x09)

   \param mt pointer to the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_GetProps(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	struct StringsArray_r		pNames;
	struct PropertyTagArray_r	*MId;
	struct SPropTagArray		*SPropTagArray;
	struct PropertyRowSet_r		*RowSet;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_GetProps");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	pNames.Count = 0x1;
	pNames.Strings = (const char **) talloc_array(mem_ctx, char *, 1);
	pNames.Strings[0] = mt->mapi_ctx->session->profile->homemdb;

	MId = talloc_zero(mem_ctx, struct PropertyTagArray_r);

	retval = nspi_DNToMId(nspi_ctx, mem_ctx, &pNames, &MId);
	MAPIFreeBuffer((char **)pNames.Strings);
	mapitest_print_retval(mt, "NspiDNToMId");

	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MId);
		talloc_free(mem_ctx);
		return false;
	}

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_EMS_AB_NETWORK_ADDRESS);
	retval = nspi_GetProps(nspi_ctx, mem_ctx, SPropTagArray, MId, &RowSet);
	mapitest_print_retval_clean(mt, "NspiGetProps", retval);
	MAPIFreeBuffer(SPropTagArray);
	MAPIFreeBuffer(MId);
	MAPIFreeBuffer(RowSet);

	talloc_free(mem_ctx);

	if (retval == MAPI_E_SUCCESS) {
	      return true;
	} else {
	      return false;
	}
}
Exemplo n.º 11
0
folder::hierarchy_container_type folder::fetch_hierarchy() throw(mapi_exception)
{
	mapi_object_t	hierarchy_table;
	uint32_t	hierarchy_table_row_count = 0;

	mapi_object_init(&hierarchy_table);
	if (GetHierarchyTable(&m_object, &hierarchy_table, 0, &hierarchy_table_row_count) != MAPI_E_SUCCESS) {
		mapi_object_release(&hierarchy_table);
		throw mapi_exception(GetLastError(), "folder::fetch_hierarchy : GetHierarchyTable");
	}

	SPropTagArray* property_tag_array = set_SPropTagArray(m_session.get_memory_ctx(), 0x1, PR_FID);

	if (SetColumns(&hierarchy_table, property_tag_array)) {
		MAPIFreeBuffer(property_tag_array);
		mapi_object_release(&hierarchy_table);
		throw mapi_exception(GetLastError(), "folder::fetch_hierarchy : SetColumns");
	}

	MAPIFreeBuffer(property_tag_array);

	uint32_t rows_to_read = hierarchy_table_row_count;
	SRowSet  row_set;

	hierarchy_container_type hierarchy_container;
	hierarchy_container.reserve(hierarchy_table_row_count);

	while( (QueryRows(&hierarchy_table, rows_to_read, TBL_ADVANCE, &row_set) == MAPI_E_SUCCESS) && row_set.cRows) {
		rows_to_read -= row_set.cRows;
		for (unsigned int i = 0; i < row_set.cRows; ++i) {
			try {
				hierarchy_container.push_back(folder_shared_ptr(new folder(*this,
							      row_set.aRow[i].lpProps[0].value.d)));
			} catch(mapi_exception e) {
				mapi_object_release(&hierarchy_table);
				throw;
			}
		}
	}

	mapi_object_release(&hierarchy_table);

	return hierarchy_container;
}
Exemplo n.º 12
0
message::attachment_container_type message::fetch_attachments()
{
	mapi_object_t   attachment_table;

	mapi_object_init(&attachment_table);
	if (GetAttachmentTable(&m_object, &attachment_table) != MAPI_E_SUCCESS) {
		mapi_object_release(&attachment_table);
		throw mapi_exception(GetLastError(), "message::fetch_attachments : GetAttachmentTable");
	}

	SPropTagArray* property_tag_array = set_SPropTagArray(m_session.get_memory_ctx(), 0x1, PR_ATTACH_NUM);

	if (SetColumns(&attachment_table, property_tag_array) != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(property_tag_array);
		mapi_object_release(&attachment_table);
		throw mapi_exception(GetLastError(), "message::fetch_attachments : SetColumns");
	}

	MAPIFreeBuffer(property_tag_array);

	SRowSet  row_set;
	attachment_container_type attachment_container;

	while( (QueryRows(&attachment_table, 0x32, TBL_ADVANCE, TBL_FORWARD_READ, &row_set) == MAPI_E_SUCCESS) && row_set.cRows) {
		for (unsigned int i = 0; i < row_set.cRows; ++i) {
			try {
				attachment_container.push_back(attachment_shared_ptr(new attachment(*this, row_set.aRow[i].lpProps[0].value.l)));
			}
			catch(mapi_exception e) {
				mapi_object_release(&attachment_table);
				throw;
			}
		}
	}
	mapi_object_release(&attachment_table);

	return attachment_container;
}
Exemplo n.º 13
0
static bool messages_dump(TALLOC_CTX *mem_ctx,
              mapi_object_t *obj_store,
              mapi_object_t *parent,
              struct mbox_tree_item *folder,
              struct mbox_data *mdata,
              const char *base_path)
{
    enum MAPISTATUS         retval;
    int             ret;
    mapi_object_t           obj_folder;
    mapi_object_t           obj_message;
    char                *filename = NULL;
    struct mapi_SPropValue_array    lpProps;
    uint32_t            context_id;
    mapi_object_t           obj_htable;
    struct SPropTagArray        *SPropTagArray;
    struct SRowSet          SRowSet;
    uint32_t            i;
    uint32_t            count;
    const uint64_t          *fid;
    const uint64_t          *mid;
    const uint32_t          *size;
    const char          *class;
    struct SPropValue           *lpProp;

    /* Search the folder from Top Information Store */
    mapi_object_init(&obj_folder);
    retval = OpenFolder(parent, folder->id, &obj_folder);
    if (retval != MAPI_E_SUCCESS) return false;

    /* Get container class */
    SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_CONTAINER_CLASS);
    retval = GetProps(&obj_folder, MAPI_UNICODE, SPropTagArray, &lpProp, &count);
    MAPIFreeBuffer(SPropTagArray);
    if ((lpProp[0].ulPropTag != PR_CONTAINER_CLASS) || (retval != MAPI_E_SUCCESS)) {
            class = IPF_NOTE;
    } else {
Exemplo n.º 14
0
icalcomponent * _Exchange2Ical(mapi_object_t *obj_folder, struct exchange2ical_check *exchange2ical_check)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	int				ret;
	struct SRowSet			SRowSet;
	struct SRow			aRow;
	struct SRow			aRowT;
	struct SPropValue		*lpProps;
	struct SPropTagArray		*SPropTagArray = NULL;
	struct exchange2ical		exchange2ical;
	mapi_object_t			obj_table;
	uint32_t			count;
	int				i;

	mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "exchange2ical");
	exchange2ical_init(mem_ctx, &exchange2ical);
	
	/* Open the contents table */
	mapi_object_init(&obj_table);
	retval = GetContentsTable(obj_folder, &obj_table, 0, &count);
	if (retval != MAPI_E_SUCCESS){
		talloc_free(mem_ctx);
		return NULL;
	}
	
	OC_DEBUG(0, "MAILBOX (%d appointments)", count);
	if (count == 0) {
		talloc_free(mem_ctx);
		return NULL;
	}

	SPropTagArray = set_SPropTagArray(mem_ctx, 0x2,
					  PR_FID,
					  PR_MID);
					  
	retval = SetColumns(&obj_table, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	if (retval != MAPI_E_SUCCESS) {
		mapi_errstr("SetColumns", retval);
		talloc_free(mem_ctx);
		return NULL;
	}
	
	while ((retval = QueryRows(&obj_table, count, TBL_ADVANCE, TBL_FORWARD_READ, &SRowSet)) != MAPI_E_NOT_FOUND && SRowSet.cRows) {
		count -= SRowSet.cRows;
		for (i = (SRowSet.cRows-1); i >= 0; i--) {
			mapi_object_init(&exchange2ical.obj_message);
			retval = OpenMessage(obj_folder,
					     SRowSet.aRow[i].lpProps[0].value.d,
					     SRowSet.aRow[i].lpProps[1].value.d,
					     &exchange2ical.obj_message, 0);
			if (retval != MAPI_E_NOT_FOUND) {
				SPropTagArray = set_SPropTagArray(mem_ctx, 0x30,
								  PidLidGlobalObjectId,
								  PidNameKeywords,
								  PidLidRecurring,
								  PidLidAppointmentRecur,
								  PidLidAppointmentStateFlags,
								  PidLidTimeZoneDescription,
								  PidLidTimeZoneStruct,
								  PidLidContacts,
								  PidLidAppointmentStartWhole,
								  PidLidAppointmentEndWhole,
								  PidLidAppointmentSubType,
								  PidLidOwnerCriticalChange,
								  PidLidLocation,
								  PidLidNonSendableBcc,
								  PidLidAppointmentSequence,
								  PidLidBusyStatus,
								  PidLidIntendedBusyStatus,
								  PidLidAttendeeCriticalChange,
								  PidLidAppointmentReplyTime,
								  PidLidAppointmentNotAllowPropose,
								  PidLidAllowExternalCheck,
								  PidLidAppointmentLastSequence,
								  PidLidAppointmentSequenceTime,
								  PidLidAutoFillLocation,
								  PidLidAutoStartCheck,
								  PidLidCollaborateDoc,
								  PidLidConferencingCheck,
								  PidLidConferencingType,
								  PidLidDirectory,
								  PidLidMeetingWorkspaceUrl,
								  PidLidNetShowUrl,
								  PidLidOnlinePassword,
								  PidLidOrganizerAlias,
								  PidLidReminderSet,
								  PidLidReminderDelta,
								  PidLidResponseStatus,
								  PR_MESSAGE_CLASS_UNICODE,
								  PR_SENSITIVITY,
								  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(&exchange2ical.obj_message, MAPI_UNICODE, SPropTagArray, &lpProps, &count);

				MAPIFreeBuffer(SPropTagArray);
	
				if (retval == MAPI_E_SUCCESS) {
					aRow.ulAdrEntryPad = 0;
					aRow.cValues = count;
					aRow.lpProps = lpProps;
					
					/*Get Vcal info if first event*/
					if(i==(SRowSet.cRows-1)){
						ret = exchange2ical_get_properties(mem_ctx, &aRow, &exchange2ical, VcalFlag);
						/*TODO: exit nicely*/
						ical_component_VCALENDAR(&exchange2ical);
					}
					
					
					/*Get required properties to check if right event*/
					ret = exchange2ical_get_properties(mem_ctx, &aRow, &exchange2ical, exchange2ical_check->eFlags);
					
					/*Check to see if event is acceptable*/
					if (!checkEvent(&exchange2ical, exchange2ical_check, get_tm_from_FILETIME(exchange2ical.apptStartWhole))){
						continue;
					}
					
					/*Set RecipientTable*/
					retval = GetRecipientTable(&exchange2ical.obj_message, 
							   &exchange2ical.Recipients.SRowSet,
							   &exchange2ical.Recipients.SPropTagArray);
					
					/*Set PR_BODY_HTML for x_alt_desc property*/
					SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_BODY_HTML_UNICODE);
					retval = GetProps(&exchange2ical.obj_message, MAPI_UNICODE, SPropTagArray, &lpProps, &count);
					MAPIFreeBuffer(SPropTagArray);
					if (retval == MAPI_E_SUCCESS) {
						aRowT.ulAdrEntryPad = 0;
						aRowT.cValues = count;
						aRowT.lpProps = lpProps;
						exchange2ical.bodyHTML = (const char *)octool_get_propval(&aRowT, PR_BODY_HTML_UNICODE);
					}
					
					/*Get rest of properties*/
					ret = exchange2ical_get_properties(mem_ctx, &aRow, &exchange2ical, (exchange2ical_check->eFlags | EntireFlag));
					
					/*add new vevent*/
					ical_component_VEVENT(&exchange2ical);
					
					/*Exceptions to event*/
					if(exchange2ical_check->eFlags != EventFlag){
						ret = exchange2ical_exception_from_EmbeddedObj(&exchange2ical, exchange2ical_check);
						if (ret){
							ret=exchange2ical_exception_from_ExceptionInfo(&exchange2ical, exchange2ical_check);
						}
					}
					
					/*REMOVE once globalobjid is fixed*/
					exchange2ical.idx++;
					
					MAPIFreeBuffer(lpProps);
					exchange2ical_reset(&exchange2ical);
				}
				
			}
			mapi_object_release(&exchange2ical.obj_message);
		}
	}

	icalcomponent *icalendar = exchange2ical.vcalendar;
	exchange2ical_clear(&exchange2ical);
	
	/* Uninitialize MAPI subsystem */
	mapi_object_release(&obj_table);
	talloc_free(mem_ctx);	
	return icalendar;
}
Exemplo n.º 15
0
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;	
}
Exemplo n.º 16
0
/**
   \details Build an EntryID for message from folder and message source ID

 */
_PUBLIC_ enum MAPISTATUS EntryIDFromSourceIDForMessage(TALLOC_CTX *mem_ctx,
						       mapi_object_t *obj_store,
						       mapi_object_t *obj_folder,
						       mapi_object_t *obj_message,
						       struct SBinary_short *entryID)
{
	enum MAPISTATUS			retval;
	struct ndr_push			*ndr;
	mapi_object_store_t		*store;
	const struct SBinary_short	*FolderSourceKey;
	const struct SBinary_short	*MessageSourceKey;
	struct SPropTagArray		*SPropTagArray;
	struct SPropValue		*lpPropsf;
	struct SPropValue		*lpPropsm;
	uint32_t			count;

	/* Sanity checks */
	OPENCHANGE_RETVAL_IF(!obj_store, MAPI_E_INVALID_PARAMETER, NULL);
	OPENCHANGE_RETVAL_IF(!obj_folder, MAPI_E_INVALID_PARAMETER, NULL);
	OPENCHANGE_RETVAL_IF(!obj_message, MAPI_E_INVALID_PARAMETER, NULL);
	OPENCHANGE_RETVAL_IF(!entryID, MAPI_E_INVALID_PARAMETER, NULL);

	store = (mapi_object_store_t *)obj_store->private_data;

	/* Step 1. Retrieve folder Source Key */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PidTagSourceKey);
	retval = GetProps(obj_folder, 0, SPropTagArray, &lpPropsf, &count);
	MAPIFreeBuffer(SPropTagArray);
	if (retval != MAPI_E_SUCCESS) return MAPI_E_NOT_FOUND;
	FolderSourceKey = (const struct SBinary_short *)get_SPropValue(lpPropsf, PidTagSourceKey);
	if (FolderSourceKey == NULL) return MAPI_E_NOT_FOUND;

	/* Step 2. Retrieve message Source Key */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PidTagSourceKey);
	retval = GetProps(obj_message, 0, SPropTagArray, &lpPropsm, &count);
	MAPIFreeBuffer(SPropTagArray);
	if (retval != MAPI_E_SUCCESS) return MAPI_E_NOT_FOUND;
	MessageSourceKey = (const struct SBinary_short *)get_SPropValue(lpPropsm, PidTagSourceKey);
	if (MessageSourceKey == NULL) return MAPI_E_NOT_FOUND;

	/* Step 3. Fill PidTagEntryID */
	/* PidTagEntryId size for message is 70 bytes */
	/* Flags (4 bytes) + store guid (16 bytes) + object type (2
	 * bytes) + Folder SourceKey (22 bytes) + Pad (2 bytes) +
	 * Message Source (22 bytes) + Pad (2 bytes) == 70 bytes */
	ndr = ndr_push_init_ctx(NULL);
	ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
	ndr->offset = 0;

	ndr_push_uint32(ndr, NDR_SCALARS, 0x0);
	if (store->store_type == PublicFolder) {
		const uint8_t	ProviderUID[16] = { 0x1A, 0x44, 0x73, 0x90, 0xAA, 0x66, 0x11, 0xCD, 0x9B, 0xC8, 0x00, 0xAA, 0x00, 0x2F, 0xC4, 0x5A };

		ndr_push_array_uint8(ndr, NDR_SCALARS, ProviderUID, 16);
		ndr_push_uint16(ndr, NDR_SCALARS, 0x0009);
	} else {
		ndr_push_GUID(ndr, NDR_SCALARS, &store->guid);
		ndr_push_uint16(ndr, NDR_SCALARS, 0x0007);
	}
	ndr_push_array_uint8(ndr, NDR_SCALARS, FolderSourceKey->lpb, FolderSourceKey->cb);
	ndr_push_uint16(ndr, NDR_SCALARS, 0x0);
	ndr_push_array_uint8(ndr, NDR_SCALARS, MessageSourceKey->lpb, MessageSourceKey->cb);
	ndr_push_uint16(ndr, NDR_SCALARS, 0x0);

	entryID->cb = ndr->offset;
	entryID->lpb = talloc_steal(mem_ctx, ndr->data);

	talloc_free(ndr);

	return MAPI_E_SUCCESS;
}
Exemplo n.º 17
0
/**
   \details Test the NspiResolveNames and NspiResolveNamesW RPC
   operations (0x13 and 0x14)

   \param mt pointer on the top-level mapitest structure
   
   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_ResolveNames(struct mapitest *mt)
{
	enum MAPISTATUS			retval;
	struct SPropTagArray		*SPropTagArray = NULL;
	struct PropertyRowSet_r		*RowSet = NULL;
	struct PropertyTagArray_r	*flaglist = NULL;
	const char			*username[2];
	const char     			*username_err[2];

	/* Build the username array */
	username[0] = (const char *)mt->profile->mailbox;
	username[1] = NULL;
	/* Build the err username array */
	username_err[0] = talloc_asprintf(mt->mem_ctx, "%s%s", mt->info.szDNPrefix, "nspi_resolve_testcase");
	username_err[1] = NULL;

	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0xd,
					  PR_ENTRYID,
					  PR_DISPLAY_NAME,
					  PR_ADDRTYPE,
					  PR_GIVEN_NAME,
					  PR_SMTP_ADDRESS,
					  PR_OBJECT_TYPE,
					  PR_DISPLAY_TYPE,
					  PR_EMAIL_ADDRESS,
					  PR_SEND_INTERNET_ENCODING,
					  PR_SEND_RICH_INFO,
					  PR_SEARCH_KEY,
					  PR_TRANSMITTABLE_DISPLAY_NAME,
					  PR_7BIT_DISPLAY_NAME);

	/* Test with existing username */
	/* NspiResolveNames (0x13) */
	retval = ResolveNames(mt->session, (const char **)username, SPropTagArray, &RowSet, &flaglist, 0);
	mapitest_print_retval_clean(mt, "NspiResolveNames - existing", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(SPropTagArray);
		return false;
	}
	if ( ! flaglist) {
		mapitest_print(mt, "\tNULL flaglist, which wasn't expected\n");
		MAPIFreeBuffer(SPropTagArray);
		return false;
	}
	if (flaglist->aulPropTag[0] != MAPI_RESOLVED) {
		mapitest_print(mt, "Expected 2 (MAPI_RESOLVED), but NspiResolveNames returned: %i\n", flaglist->aulPropTag[0]);
	} else {
		mapitest_print(mt, "\tGot expected resolution flag\n");
	}
	talloc_free(flaglist);
	talloc_free(RowSet);

	/* NspiResolveNamesW (0x14) */
	retval = ResolveNames(mt->session, (const char **)username, SPropTagArray, &RowSet, &flaglist, MAPI_UNICODE);
	mapitest_print_retval_clean(mt, "NspiResolveNamesW - existing", retval);
	if (flaglist->aulPropTag[0] != MAPI_RESOLVED) {
		mapitest_print(mt, "Expected 2 (MAPI_RESOLVED), but NspiResolveNamesW returned: %i\n", flaglist->aulPropTag[0]);
	} else {
		mapitest_print(mt, "\tGot expected resolution flag\n");
	}
	talloc_free(flaglist);
	talloc_free(RowSet);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(SPropTagArray);
		return false;
	}

	/* Test with non-existant username */
	/* NspiResolveNames (0x13) */
	retval = ResolveNames(mt->session, (const char **)username_err, SPropTagArray, &RowSet, &flaglist, 0);
	mapitest_print_retval_clean(mt, "NspiResolveNames - non existant user name", retval);
	if (flaglist->aulPropTag[0] != MAPI_UNRESOLVED) {
		mapitest_print(mt, "Expected 0 (MAPI_UNRESOLVED), but NspiResolveNames returned: %i\n", flaglist->aulPropTag[0]);
	} else {
		mapitest_print(mt, "\tGot expected resolution flag\n");
	}
	talloc_free(flaglist);
	talloc_free(RowSet);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(SPropTagArray);
		return false;
	}

	/* NspiResolveNamesW (0x14) */
	retval = ResolveNames(mt->session, (const char **)username_err, SPropTagArray, &RowSet, &flaglist, MAPI_UNICODE);
	mapitest_print_retval_clean(mt, "NspiResolveNamesW - non existant user name", retval);
	if (flaglist->aulPropTag[0] != MAPI_UNRESOLVED) {
		mapitest_print(mt, "Expected 0 (MAPI_UNRESOLVED), but NspiResolveNamesW returned: %i\n", flaglist->aulPropTag[0]);
	} else {
		mapitest_print(mt, "\tGot expected resolution flag\n");
	}
	talloc_free(flaglist);
	talloc_free(RowSet);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(SPropTagArray);
		return false;
	}
	MAPIFreeBuffer(SPropTagArray);
	return true;
}
Exemplo n.º 18
0
/**
   \details Test the QueryRows (0x15) operation

   This function:
   -# Opens the Inbox folder and gets the hierarchy table
   -# Set the required columns
   -# Calls QueryRows until the end of the table
   -# Open the test folder, and get its contents
   -# Calls QueryRows until the end of the test folder
   -# Checks the results are as expected.
   -# Cleans up

   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_oxctable_QueryRows(struct mapitest *mt)
{
	enum MAPISTATUS		retval;
	mapi_object_t		obj_htable;
	mapi_object_t		obj_test_folder;
	struct SRowSet		SRowSet;
	struct SPropTagArray	*SPropTagArray;
	struct SPropValue	lpProp;
	struct mt_common_tf_ctx	*context;
	uint32_t		idx = 0;
	uint32_t		count = 0;
	const char*		data;

	/* Step 1. Logon */
	if (! mapitest_common_setup(mt, &obj_htable, &count)) {
		return false;
	}

	/* Step 2. Set Table Columns */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x3,
					  PR_DISPLAY_NAME,
					  PR_FID,
					  PR_FOLDER_CHILD_COUNT);
	retval = SetColumns(&obj_htable, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	if (GetLastError() != MAPI_E_SUCCESS) {
		mapitest_print_retval(mt, "SetColumns");
		return false;
	}

	/* Step 3. QueryRows */
	do {
		retval = QueryRows(&obj_htable, 0x2, TBL_ADVANCE, &SRowSet);
		if (SRowSet.cRows > 0) {
			idx += SRowSet.cRows;
			if (retval == MAPI_E_SUCCESS) {
				mapitest_print(mt, "* %-35s: %.2d/%.2d [PASSED]\n", 
					       "QueryRows", idx, count);
			} else {
				mapitest_print(mt, "* %-35s: %.2d/%.2d [FAILED]\n", 
					       "QueryRows", idx, count);
			}
		}
	} while (retval == MAPI_E_SUCCESS && SRowSet.cRows > 0);


	/* Step 4. Get the test folder */
	context = mt->priv;
	mapi_object_init(&(obj_test_folder));
	GetContentsTable(&(context->obj_test_folder), &(obj_test_folder), 0, &count);
	if (GetLastError() != MAPI_E_SUCCESS) {
		mapitest_print_retval(mt, "GetContentsTable");
		return false;
	}
	if (count != 10) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "GetContentsTable", count);
		/* This isn't a hard error for this test though, because it might be from a 
		   previous test failure. Clean up and try again */
	}

	/* Step 5. Set Table Columns on the test folder */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x2, PR_BODY, PR_MESSAGE_CLASS);
	retval = SetColumns(&obj_test_folder, SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	if (GetLastError() != MAPI_E_SUCCESS) {
		mapitest_print_retval(mt, "SetColumns");
		return false;
	}

	/* Step 6. QueryRows on test folder contents */
	idx = 0;
	do {
		retval = QueryRows(&(obj_test_folder), 0x2, TBL_ADVANCE, &SRowSet);
		if (SRowSet.cRows > 0) {
			idx += SRowSet.cRows;
			if (retval == MAPI_E_SUCCESS) {
			  	uint32_t	i;
				mapitest_print(mt, "* %-35s: %.2d/%.2d [PASSED]\n", 
					       "QueryRows", idx, count);
				for (i = 0; i < SRowSet.cRows; ++i) {
					lpProp = SRowSet.aRow[i].lpProps[0];
					if (lpProp.ulPropTag != PR_BODY) {
						mapitest_print(mt, "* %-35s: Bad proptag0 (0x%x)\n", 
							       "QueryRows", lpProp.ulPropTag);
						return false;
					}
					data = get_SPropValue_data(&lpProp);
					if (0 != strncmp(data, "Body of message", 15)) {
						mapitest_print(mt, "* %-35s: Bad propval0 (%s)\n", 
							       "QueryRows", data);
						return false;
					}
					lpProp = SRowSet.aRow[i].lpProps[1];
					if (lpProp.ulPropTag != PR_MESSAGE_CLASS) {
						mapitest_print(mt, "* %-35s: Bad proptag1 (0x%x)\n", 
							       "QueryRows", lpProp.ulPropTag);
						return false;
					}
					data = get_SPropValue_data(&lpProp);
					if (0 != strncmp(data, "IPM.Note", 8)) {
						mapitest_print(mt, "* %-35s: Bad propval1 (%s)\n", 
							       "QueryRows", data);
						return false;
					}
				}
			} else {
				mapitest_print(mt, "* %-35s: %.2d/%.2d [FAILED]\n", 
					       "QueryRows", idx, count);
			}
		}
	} while (retval == MAPI_E_SUCCESS && SRowSet.cRows > 0);

	/* Release */
	mapi_object_release(&obj_htable);
	mapi_object_release(&(obj_test_folder));
	mapitest_common_cleanup(mt);

	return true;
}
Exemplo n.º 19
0
/**
   \details Retrieve Address Book information for a given recipient

   \param session pointer to the MAPI session context
   \param username pointer to the username to retrieve information from
   \param pPropTags pointer to the property tags array to lookup
   \param ppRowSet pointer on pointer to the results

   Note that if pPropTags is NULL, then GetABNameInfo will fetch
   the following default property tags:
   -# PR_ADDRTYPE_UNICODE
   -# PR_EMAIL_ADDRESS_UNICODE
   -# PR_DISPLAY_NAME_UNICODE
   -# PR_OBJECT_TYPE

   \return MAPI_E_SUCCESS on success, otherwise MAPI error. 

   \note Developers may also call GetLastError() to retrieve the last
   MAPI error code. Possible MAPI error codes are:
   -# MAPI_E_NOT_INITIALIZED if MAPI subsystem is not initialized
   -# MAPI_E_SESSION_LIMIT if the NSPI session is unavailable
   -# MAPI_E_INVALID_PARAMETER if a function parameter is invalid
   -# MAPI_E_NOT_FOUND if the username to lookup doesn't match any
      records

   \sa nspi_DNToMId, nspi_GetProps
 */
_PUBLIC_ enum MAPISTATUS GetABRecipientInfo(struct mapi_session *session,
				       const char *username,
				       struct SPropTagArray *pPropTags,
				       struct PropertyRowSet_r **ppRowSet)
{
	enum MAPISTATUS			retval;
	TALLOC_CTX			*mem_ctx;
	struct nspi_context		*nspi_ctx;
	struct PropertyRowSet_r		*RowSet;
	struct SPropTagArray		*SPropTagArray = NULL;
	struct PropertyTagArray_r	*pMId = NULL;
	struct PropertyTagArray_r	*flaglist = NULL;
	struct StringsArray_r		pNames;
	const char			*usernames[2];
	char				*email = NULL;
	bool				allocated = false;

	/* Sanity checks */
	OPENCHANGE_RETVAL_IF(!session, MAPI_E_SESSION_LIMIT, NULL);
	OPENCHANGE_RETVAL_IF(!session->profile, MAPI_E_SESSION_LIMIT, NULL);
	OPENCHANGE_RETVAL_IF(!session->nspi, MAPI_E_SESSION_LIMIT, NULL);
	OPENCHANGE_RETVAL_IF(!session->nspi->ctx, MAPI_E_SESSION_LIMIT, NULL);
	OPENCHANGE_RETVAL_IF(!ppRowSet, MAPI_E_INVALID_PARAMETER, NULL);
	OPENCHANGE_RETVAL_IF(!username, MAPI_E_INVALID_PARAMETER, NULL);

	mem_ctx = talloc_named(session, 0, "GetABRecipientInfo");
	nspi_ctx = (struct nspi_context *)session->nspi->ctx;

	/* Step 1. Resolve the username */
	usernames[0] = username;
	usernames[1] = NULL;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	SPropTagArray = set_SPropTagArray(mem_ctx, 0xc,
					  PR_ENTRYID,
					  PR_DISPLAY_NAME_UNICODE,
					  PR_ADDRTYPE_UNICODE,
					  PR_OBJECT_TYPE,
					  PR_DISPLAY_TYPE,
					  PR_EMAIL_ADDRESS_UNICODE,
					  PR_SEND_INTERNET_ENCODING,
					  PR_SEND_RICH_INFO,
					  PR_SEARCH_KEY,
					  PR_TRANSMITTABLE_DISPLAY_NAME_UNICODE,
					  PR_7BIT_DISPLAY_NAME_UNICODE,
					  PR_SMTP_ADDRESS_UNICODE);
	retval = ResolveNames(session, usernames, SPropTagArray, &RowSet, &flaglist, MAPI_UNICODE);
	MAPIFreeBuffer(SPropTagArray);
	OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);

	OPENCHANGE_RETVAL_IF((flaglist->aulPropTag[0] != MAPI_RESOLVED), MAPI_E_NOT_FOUND, mem_ctx);

	email = talloc_strdup(mem_ctx, (const char *) get_PropertyValue_PropertyRowSet_data(RowSet, PR_EMAIL_ADDRESS_UNICODE));
	MAPIFreeBuffer(RowSet);

	/* Step 2. Map recipient DN to MId */
	pNames.Count = 0x1;
	pNames.Strings = (const char **) talloc_array(mem_ctx, char *, 1);
	pNames.Strings[0] = email;
	pMId = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_DNToMId(nspi_ctx, mem_ctx, &pNames, &pMId);
	MAPIFreeBuffer((char *)pNames.Strings[0]);
	MAPIFreeBuffer((char **)pNames.Strings);
	OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);

	/* Step 3. Get recipient's properties */
	if (!pPropTags) {
		allocated = true;
		SPropTagArray = set_SPropTagArray(mem_ctx, 0x4,
						  PR_ADDRTYPE_UNICODE,
						  PR_EMAIL_ADDRESS_UNICODE,
						  PR_DISPLAY_NAME_UNICODE,
						  PR_OBJECT_TYPE);
	} else {
		SPropTagArray = pPropTags;
	}

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	retval = nspi_GetProps(nspi_ctx, RowSet, SPropTagArray, pMId, &RowSet);
	if (allocated == true) {
		MAPIFreeBuffer(SPropTagArray);
	}
	MAPIFreeBuffer(pMId);
	OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);

	RowSet = talloc_steal((TALLOC_CTX *)session, RowSet);
	*ppRowSet = RowSet;

	talloc_free(mem_ctx);

	return MAPI_E_SUCCESS;
}
Exemplo n.º 20
0
/**
   \details Test the NspiCompareMIds RPC operation (0x0a)

   \param mt pointer to the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_CompareMIds(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	uint32_t			plResult;
	struct PropertyTagArray_r	*MIds;
	struct PropertyRowSet_r		*RowSet;
	struct SPropTagArray		*SPropTagArray;
	struct PropertyValue_r		*lpProp;
	struct Restriction_r		Filter;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_CompareMIds");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	/* Build the array of columns we want to retrieve */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME);

	/* Build the restriction we want for NspiGetMatches */
	lpProp = talloc_zero(mem_ctx, struct PropertyValue_r);
	lpProp->ulPropTag = PR_OBJECT_TYPE;
	lpProp->dwAlignPad = 0;
	lpProp->value.l = 6;

	Filter.rt = RES_PROPERTY;
	Filter.res.resProperty.relop = RES_PROPERTY;
	Filter.res.resProperty.ulPropTag = PR_OBJECT_TYPE;
	Filter.res.resProperty.lpProp = lpProp;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds);
	MAPIFreeBuffer(lpProp);
	MAPIFreeBuffer(SPropTagArray);
	MAPIFreeBuffer(RowSet);
	mapitest_print_retval_clean(mt, "NspiGetMatches", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return false;
	}

	/* Ensure we have at least two result to compare */
	if (MIds->cValues < 2) {
		mapitest_print(mt, "* Only one result found, can't compare\n");
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return false;
	}

	retval = nspi_CompareMIds(nspi_ctx, mem_ctx, MIds->aulPropTag[0], MIds->aulPropTag[1], &plResult);
	mapitest_print_retval_clean(mt, "NspiCompareMIds", retval);
	MAPIFreeBuffer(MIds);
	if (retval != MAPI_E_SUCCESS) {
		talloc_free(mem_ctx);
		return false;
	}

	mapitest_print(mt, "* %-35s: %d\n", "value of the comparison", plResult);
	talloc_free(mem_ctx);

	return true;
}
Exemplo n.º 21
0
/**
    \details Test #1804 ModifyRecipients and try to build RecipientRow
    with multi-value properties (e.g. PidTagUserX509Certificate)

    \param mt pointer to the top level mapitest structure

    \return true on success, otherwise false
*/
_PUBLIC_ bool mapitest_zentyal_1804(struct mapitest *mt)
{
	enum MAPISTATUS			retval;
	mapi_object_t			obj_store;
	mapi_object_t			obj_folder;
	mapi_object_t			obj_message;
	mapi_id_t			id_folder;
	char				**username = NULL;
	struct SPropTagArray		*SPropTagArray = NULL;
	struct PropertyValue_r		value;
	struct PropertyRowSet_r		*RowSet = NULL;
	struct SRowSet			*SRowSet = NULL;
	struct PropertyTagArray_r	*flaglist = NULL;
	mapi_id_t			id_msgs[1];

	/* Step 1. Logon */
	mapi_object_init(&obj_store);
	retval = OpenMsgStore(mt->session, &obj_store);
	mapitest_print_retval(mt, "OpenMsgStore");
	if (GetLastError() != MAPI_E_SUCCESS) {
		return false;
	}

	/* Step 2. Open Outbox folder */
	retval = GetDefaultFolder(&obj_store, &id_folder, olFolderOutbox);
	mapitest_print_retval(mt, "GetDefaultFolder");
	if (GetLastError() != MAPI_E_SUCCESS) {
		return false;
	}

	mapi_object_init(&obj_folder);
	retval = OpenFolder(&obj_store, id_folder, &obj_folder);
	mapitest_print_retval(mt, "OpenFolder");
	if (GetLastError() != MAPI_E_SUCCESS) {
		return false;
	}

	/* Step 3. Create the message */
	mapi_object_init(&obj_message);
	retval = CreateMessage(&obj_folder, &obj_message);
	mapitest_print_retval(mt, "CreateMessage");
	if (GetLastError() != MAPI_E_SUCCESS) {
		return false;
	}


	/* Step 4. Resolve the recipients and call ModifyRecipients */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0xA,
					  PR_ENTRYID,
					  PR_DISPLAY_NAME_UNICODE,
					  PR_OBJECT_TYPE,
					  PR_DISPLAY_TYPE,
					  PR_TRANSMITTABLE_DISPLAY_NAME_UNICODE,
					  PR_EMAIL_ADDRESS_UNICODE,
					  PR_ADDRTYPE_UNICODE,
					  PR_SEND_RICH_INFO,
					  PR_7BIT_DISPLAY_NAME_UNICODE,
					  PR_SMTP_ADDRESS_UNICODE);

	username = talloc_array(mt->mem_ctx, char *, 2);
	username[0] = (char *)mt->profile->username;
	username[1] = NULL;

	retval = ResolveNames(mapi_object_get_session(&obj_message),
			      (const char **)username, SPropTagArray,
			      &RowSet, &flaglist, MAPI_UNICODE);
	mapitest_print_retval_clean(mt, "ResolveNames", retval);
	if (retval != MAPI_E_SUCCESS) {
		return false;
	}

	if (!RowSet) {
		mapitest_print(mt, "Null RowSet\n");
		return false;
	}
	if (!RowSet->cRows) {
		mapitest_print(mt, "No values in RowSet\n");
		MAPIFreeBuffer(RowSet);
		return false;
	}

	value.ulPropTag = PR_SEND_INTERNET_ENCODING;
	value.value.l = 0;
	PropertyRowSet_propcpy(mt->mem_ctx, RowSet, value);

	/* Fake multi-value property on RecipientRow */
	/* PT_MV_STRING8 */
	value.ulPropTag = PR_EMS_AB_PROXY_ADDRESSES;
	value.value.MVszA.cValues = 2;
	value.value.MVszA.lppszA = talloc_array(mt->mem_ctx, const char *, value.value.MVszA.cValues);
	value.value.MVszA.lppszA[0] = "smtp:[email protected]";
	value.value.MVszA.lppszA[1] = "X400:c=US;a= ;p=First Organizati;o=Exchange;s=test";
	PropertyRowSet_propcpy(mt->mem_ctx, RowSet, value);
	/* PT_MV_UNICODE - same layout as PT_MV_STRING8 */
	value.ulPropTag = PR_EMS_AB_PROXY_ADDRESSES_UNICODE;
	PropertyRowSet_propcpy(mt->mem_ctx, RowSet, value);
	/* PT_MV_BINARY */
	value.ulPropTag = PidTagUserX509Certificate;
	value.value.MVbin.cValues = 2;
	value.value.MVbin.lpbin = talloc_array(mt->mem_ctx, struct Binary_r, value.value.MVbin.cValues);
	value.value.MVbin.lpbin[0].cb = 9;
	value.value.MVbin.lpbin[0].lpb = (uint8_t *)"string 1";
	value.value.MVbin.lpbin[1].cb = 9;
	value.value.MVbin.lpbin[1].lpb = (uint8_t *)"string 2";
	PropertyRowSet_propcpy(mt->mem_ctx, RowSet, value);

	SRowSet = talloc_zero(RowSet, struct SRowSet);
	cast_PropertyRowSet_to_SRowSet(SRowSet, RowSet, SRowSet);

	SetRecipientType(&(SRowSet->aRow[0]), MAPI_TO);
	mapitest_print_retval(mt, "SetRecipientType");
	retval = ModifyRecipients(&obj_message, SRowSet);
	mapitest_print_retval_fmt(mt, "ModifyRecipients", "(%s)", "MAPI_TO");
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(RowSet);
		MAPIFreeBuffer(flaglist);
		return false;
	}

	/* Step 5. Delete the message */
	id_msgs[0] = mapi_object_get_id(&obj_message);
	retval = DeleteMessage(&obj_folder, id_msgs, 1);
	mapitest_print_retval(mt, "DeleteMessage");
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(RowSet);
		MAPIFreeBuffer(flaglist);
		return false;
	}
	/* Release */
	MAPIFreeBuffer(RowSet);
	MAPIFreeBuffer(flaglist);
	mapi_object_release(&obj_message);
	mapi_object_release(&obj_folder);
	mapi_object_release(&obj_store);

	return true;
}
Exemplo n.º 22
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);
}
Exemplo n.º 23
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);
		}
Exemplo n.º 24
0
/**
   \details Test the NspiResortRestriction RPC operation (0x6)

   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_nspi_ResortRestriction(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	struct Restriction_r		Filter;
	struct PropertyRowSet_r		*RowSet = NULL;
	struct SPropTagArray		*SPropTagArray = NULL;
	struct PropertyValue_r		*lpProp = NULL;
	struct PropertyTagArray_r	*MIds = NULL;
	struct PropertyTagArray_r	*ppMIds = NULL;
	bool				ret = true;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_ResortRestriction");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	/* Build the array of columns we want to retrieve */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0xb,
					  PR_DISPLAY_NAME,
					  PR_OFFICE_TELEPHONE_NUMBER,
					  PR_OFFICE_LOCATION,
					  PR_TITLE,
					  PR_COMPANY_NAME,
					  PR_ACCOUNT,
					  PR_ADDRTYPE,
					  PR_ENTRYID,
					  PR_DISPLAY_TYPE,
					  PR_INSTANCE_KEY,
					  PR_EMAIL_ADDRESS
					  );

	/* Build the restriction we want for NspiGetMatches */
	lpProp = talloc_zero(mem_ctx, struct PropertyValue_r);
	lpProp->ulPropTag = PR_OBJECT_TYPE;
	lpProp->dwAlignPad = 0;
	lpProp->value.l = 6;

	Filter.rt = RES_PROPERTY;
	Filter.res.resProperty.relop = RES_PROPERTY;
	Filter.res.resProperty.ulPropTag = PR_OBJECT_TYPE;
	Filter.res.resProperty.lpProp = lpProp;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds);
	MAPIFreeBuffer(lpProp);
	MAPIFreeBuffer(SPropTagArray);
	MAPIFreeBuffer(RowSet);
	mapitest_print_retval_clean(mt, "NspiGetMatches", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return false;
	}

	ppMIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_ResortRestriction(nspi_ctx, mem_ctx, SortTypeDisplayName, MIds, &ppMIds);
	mapitest_print_retval_clean(mt, "NspiResortRestriction", retval);
	if (retval != MAPI_E_SUCCESS) {
		ret = false;
	}

	MAPIFreeBuffer(MIds);
	MAPIFreeBuffer(ppMIds);
	talloc_free(mem_ctx);

	return ret;
}
Exemplo n.º 25
0
/**
   \details exchange_nsp NspiQueryRows (0x3) function

   \param dce_call pointer to the session context
   \param mem_ctx pointer to the memory context
   \param r pointer to the NspiQueryRows request data

   \return MAPI_E_SUCCESS on success
 */
static void dcesrv_NspiQueryRows(struct dcesrv_call_state *dce_call,
				 TALLOC_CTX *mem_ctx,
				 struct NspiQueryRows *r)
{
	enum MAPISTATUS			retval = MAPI_E_SUCCESS;
	struct emsabp_context		*emsabp_ctx = NULL;
	struct SPropTagArray		*pPropTags;
	struct PropertyRowSet_r		*pRows;
	uint32_t			count = 0;
	uint32_t			i, j;

	DEBUG(3, ("exchange_nsp: NspiQueryRows (0x3)\n"));

	/* Step 0. Ensure incoming user is authenticated */
	if (!dcesrv_call_authenticated(dce_call)) {
		DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
		DCESRV_NSP_RETURN(r, MAPI_E_LOGON_FAILED, NULL);
	}

	emsabp_ctx = dcesrv_find_emsabp_context(&r->in.handle->uuid);
	if (!emsabp_ctx) {
		DCESRV_NSP_RETURN(r, MAPI_E_CALL_FAILED, NULL);
	}

	/* Step 1. Sanity Checks (MS-NSPI Server Processing Rules) */
	if (r->in.pStat->ContainerID && r->in.lpETable == NULL && (emsabp_tdb_lookup_MId(emsabp_ctx->tdb_ctx, r->in.pStat->ContainerID) == false)) {
		retval = MAPI_E_INVALID_BOOKMARK;
		goto failure;
	}

	if (r->in.pPropTags == NULL) {
		pPropTags = set_SPropTagArray(mem_ctx, 0x7,
					      PR_EMS_AB_CONTAINERID,
					      PR_OBJECT_TYPE,
					      PR_DISPLAY_TYPE,
					      PR_DISPLAY_NAME,
					      PR_OFFICE_TELEPHONE_NUMBER,
					      PR_COMPANY_NAME,
					      PR_OFFICE_LOCATION);
	} else {
		pPropTags = r->in.pPropTags;
	}

	/* Allocate RowSet to be filled in */
	pRows = talloc_zero(mem_ctx, struct PropertyRowSet_r);

	/* Step 2. Fill ppRows  */
	if (r->in.lpETable == NULL) {
		/* Step 2.1 Fill ppRows for supplied Container ID */
		struct ldb_result	*ldb_res;

		retval = emsabp_ab_container_enum(mem_ctx, emsabp_ctx,
						  r->in.pStat->ContainerID, &ldb_res);
		if (retval != MAPI_E_SUCCESS)  {
			goto failure;
		}

		if (ldb_res->count < r->in.pStat->NumPos) {
			/* Bad position */
			retval = MAPI_E_INVALID_PARAMETER;
			goto failure;
		}

		count = ldb_res->count - r->in.pStat->NumPos;

		if (r->in.Count < count) {
			count = r->in.Count;
		}
		if (count) {
			pRows->cRows = count;
			pRows->aRow = talloc_array(mem_ctx, struct PropertyRow_r, count);
		}

		/* fetch required attributes for every entry found */
		for (i = 0; i < count; i++) {
			retval = emsabp_fetch_attrs_from_msg(mem_ctx, emsabp_ctx, pRows->aRow + i,
							     ldb_res->msgs[i+r->in.pStat->NumPos], 0, r->in.dwFlags, pPropTags);
			if (retval != MAPI_E_SUCCESS) {
				goto failure;
			}
		}
		r->in.pStat->NumPos = r->in.pStat->Delta + pRows->cRows;
		r->in.pStat->CurrentRec = MID_END_OF_TABLE;
		r->in.pStat->TotalRecs = pRows->cRows;
		r->in.pStat->Delta = 0;
	} else {
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
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);
}
Exemplo n.º 28
0
/**
   \details Test the NspiModProps RPC operation (0xb)
 
   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
*/
_PUBLIC_ bool mapitest_nspi_ModProps(struct mapitest *mt)
{
	TALLOC_CTX			*mem_ctx;
	enum MAPISTATUS			retval;
	struct nspi_context		*nspi_ctx;
	struct PropertyRow_r		*pRow;
	struct SPropTagArray		*pPropTags;
	struct PropertyValue_r		modProp;
	struct PropertyTagArray_r	*MIds;
	struct PropertyRowSet_r		*RowSet;
	struct SPropTagArray		*SPropTagArray;
	struct PropertyValue_r		*lpProp;
	struct Restriction_r		Filter;
	const char			*original_office_location;
	bool				ret = true;

	mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_ModProps");
	nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx;

	/* Build the array of columns we want to retrieve */
	SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_DISPLAY_NAME,
					  PR_DISPLAY_TYPE);

	/* Build the restriction we want for NspiGetMatches */
	lpProp = talloc_zero(mem_ctx, struct PropertyValue_r);
	lpProp->ulPropTag = PR_ACCOUNT;
	lpProp->dwAlignPad = 0;
	lpProp->value.lpszA = mt->mapi_ctx->session->profile->username;

	Filter.rt = RES_PROPERTY;
	Filter.res.resProperty.relop = RES_PROPERTY;
	Filter.res.resProperty.ulPropTag = PR_ACCOUNT;
	Filter.res.resProperty.lpProp = lpProp;

	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r);
	retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds);
	MAPIFreeBuffer(lpProp);
	MAPIFreeBuffer(RowSet);
	MAPIFreeBuffer(SPropTagArray);
	mapitest_print_retval_clean(mt, "nspi_GetMatches", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		talloc_free(mem_ctx);
		return false;
	}

	/* Query the rows */
	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	retval = nspi_QueryRows(nspi_ctx, mem_ctx, NULL, MIds, 1, &RowSet);
	mapitest_print_retval_clean(mt, "nspi_QueryRows", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		MAPIFreeBuffer(RowSet);
		talloc_free(mem_ctx);
		return false;
	}
	if (RowSet->cRows != 1) {
		mapitest_print(mem_ctx, "unexpected number of rows: %i\n", RowSet->cRows);
		MAPIFreeBuffer(MIds);
		MAPIFreeBuffer(RowSet);
		talloc_free(mem_ctx);
		return false;
	}
	original_office_location = (const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION);
	mapitest_print(mt, "original PR_OFFICE_LOCATION value: %s\n", original_office_location);

	/* Build the SRow and SPropTagArray for NspiModProps */
	pRow = talloc_zero(mem_ctx, struct PropertyRow_r);
	modProp.ulPropTag = PR_OFFICE_LOCATION;
	modProp.value.lpszA = "MT office location";
	PropertyRow_addprop(pRow, modProp);

	pPropTags = set_SPropTagArray(mem_ctx, 0x1, PR_OFFICE_LOCATION);
	retval = nspi_ModProps(nspi_ctx, mem_ctx, MIds->aulPropTag[0], pPropTags, pRow);
	mapitest_print_retval_clean(mt, "nspi_ModProps", retval);
	MAPIFreeBuffer(pRow);

	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		MAPIFreeBuffer(pPropTags);
		talloc_free(mem_ctx);
		return false;
	}

	/* Check that the property was set correctly */
	RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r);
	retval = nspi_QueryRows(nspi_ctx, mem_ctx, NULL, MIds, 1, &RowSet);
	mapitest_print_retval_clean(mt, "nspi_QueryRows", retval);
	if (retval != MAPI_E_SUCCESS) {
		MAPIFreeBuffer(MIds);
		MAPIFreeBuffer(RowSet);
		talloc_free(mem_ctx);
		return false;
	}
	if (RowSet->cRows != 1) {
		mapitest_print(mem_ctx, "unexpected number of rows: %i\n", RowSet->cRows);
		MAPIFreeBuffer(MIds);
		MAPIFreeBuffer(RowSet);
		talloc_free(mem_ctx);
		return false;
	}
	if (strcmp((const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION), "MT office location") != 0) {
		mapitest_print(mt, "PR_OFFICE_LOCATION string value mismatch: %s", (const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION));
		ret = false;
	} else {
		mapitest_print(mt, "correctly set PR_OFFICE_LOCATION\n");
	}

	/* try to reset the office location back to the original value */
	pRow = talloc_zero(mem_ctx, struct PropertyRow_r);
	modProp.ulPropTag = PR_OFFICE_LOCATION;
	modProp.value.lpszA = original_office_location;
	PropertyRow_addprop(pRow, modProp);

	retval = nspi_ModProps(nspi_ctx, mem_ctx, MIds->aulPropTag[0], pPropTags, pRow);
	mapitest_print_retval_clean(mt, "nspi_ModProps (reset original value)", retval);
	if (retval != MAPI_E_SUCCESS) {
		ret = false;
	}

	MAPIFreeBuffer(MIds);
	MAPIFreeBuffer(pPropTags);
	MAPIFreeBuffer(pRow);

	talloc_free(mem_ctx);
	
	return ret;
}
Exemplo n.º 29
0
/**
   \details Test the SortTable (0x13), ExpandRow (0x59), CollapseRow(0x5a),
   GetCollapseState(0x6b) and SetCollapseState (0x6c) operations

   This function:
   -# Opens the Inbox folder and creates some test content
   -# Checks that the content is OK
   -# Applies a sort and categorisation
   -# Checks the results are as expected.
   -# Save away the Row ID and Insatnce Number for the first header
   -# Collapse the first category
   -# Checks the results are as expected.
   -# Save the "collapse state"
   -# Expand the first category again
   -# Checks the results are as expected
   -# Restore the saved "collapse state"
   -# Checks the results are as expected
   -# Cleans up

   \param mt pointer on the top-level mapitest structure

   \return true on success, otherwise false
 */
_PUBLIC_ bool mapitest_oxctable_Category(struct mapitest *mt)
{
	mapi_object_t		obj_htable;
	mapi_object_t		obj_test_folder;
	struct mt_common_tf_ctx	*context;
	uint32_t		count = 0;
	uint32_t		origcount = 0;
	bool			ret = true;
	struct SSortOrderSet	criteria;
	uint64_t		inst_id = 0;
	uint64_t		inst_num = 0;
	struct SPropTagArray	*SPropTagArray;
	struct SRowSet		SRowSet;
	uint32_t                rowcount = 0;
	uint32_t		Numerator = 0;
	uint32_t		Denominator = 0;
	struct SBinary_short	collapseState;

	/* Step 1. Logon */
	if (! mapitest_common_setup(mt, &obj_htable, &count)) {
		return false;
	}

	/* Step 2. Get the test folder */
	context = mt->priv;
	mapi_object_init(&(obj_test_folder));
	GetContentsTable(&(context->obj_test_folder), &(obj_test_folder), 0, &origcount);
	if (GetLastError() != MAPI_E_SUCCESS) {
		mapitest_print_retval(mt, "GetContentsTable");
		ret = false;
		goto cleanup;
	}
	if (origcount != 10) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "GetContentsTable", count);
		/* This isn't a hard error for this test though, because it might be from a 
		   previous test failure. Clean up and try again */
	}

	/* We need the header row InstanceId to fold/unfold the headers */
	SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x6,
					  PR_SENDER_NAME,
					  PR_BODY,
					  PR_LAST_MODIFICATION_TIME,
					  PR_SUBJECT,
					  PR_INST_ID,
					  PR_INSTANCE_NUM);
	SetColumns(&(obj_test_folder), SPropTagArray);
	MAPIFreeBuffer(SPropTagArray);
	mapitest_print_retval(mt, "SetColumns");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	/* Apply a categorised sort */
	memset(&criteria, 0x0, sizeof (struct SSortOrderSet));
	criteria.cSorts = 1;
	criteria.cCategories = 1;
	criteria.cExpanded = 1;
	criteria.aSort = talloc_array(mt->mem_ctx, struct SSortOrder, criteria.cSorts);
	criteria.aSort[0].ulPropTag = PR_SENDER_NAME;
	criteria.aSort[0].ulOrder = TABLE_SORT_ASCEND;
	SortTable(&(obj_test_folder), &criteria);
	mapitest_print_retval(mt, "SortTable");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	rowcount =  2 * origcount;
	QueryRows(&(obj_test_folder), rowcount, TBL_ADVANCE, &SRowSet);
	mapitest_print_retval(mt, "QueryRows");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	/* Checks the results are as expected */
	QueryPosition(&(obj_test_folder), &Numerator, &Denominator);
	mapitest_print_retval(mt, "QueryPosition");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}
	/* the categories are expanded, and there are six unique senders, so there are six
	   extra rows - one for each header row */
	if (Denominator != origcount + 6) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Numerator);
		ret = false;
		goto cleanup;
	}

	/* save away ID/instance values for first row header */
	inst_id = (*(const uint64_t *)get_SPropValue_data(&(SRowSet.aRow[0].lpProps[4])));
	inst_num = (*(const uint32_t *)get_SPropValue_data(&(SRowSet.aRow[0].lpProps[5])));

	/* Collapse a row header */
	CollapseRow(&(obj_test_folder), inst_id, &rowcount);
	mapitest_print_retval(mt, "CollapseRow");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	/* Checks the results are as expected */
	QueryPosition(&(obj_test_folder), &Numerator, &Denominator);
	mapitest_print_retval(mt, "QueryPosition");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}
	/* there are still six unique headers, but half of the real entries are under the first
	   header (usually 10, unless we have some other rubbish hanging around), and when we
	   collapse the first header row, that half disappear */
	if (Denominator != origcount/2 + 6) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator);
		ret = false;
		goto cleanup;
	}

	/* Save the table collapse state */
	GetCollapseState(&(obj_test_folder), inst_id, inst_num, &collapseState);
	mapitest_print_retval(mt, "GetCollapseState");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}


	/* Expand a category */
	ExpandRow(&(obj_test_folder), inst_id, 20, &SRowSet, &rowcount);
	mapitest_print_retval(mt, "ExpandRow");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	/* Checks the results are as expected */
	QueryPosition(&(obj_test_folder), &Numerator, &Denominator);
	mapitest_print_retval(mt, "QueryPosition");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}
	/* we've expanded the first header row, so we now get all the entries plus the 6 headers */
	if (Denominator != origcount + 6) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator);
		ret = false;
		goto cleanup;
	}

	/* Restore the collapse state  */
	SetCollapseState(&(obj_test_folder), &collapseState);
	mapitest_print_retval(mt, "SetCollapseState");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}

	/* Checks the results are as expected */
	QueryPosition(&(obj_test_folder), &Numerator, &Denominator);
	mapitest_print_retval(mt, "QueryPosition");
	if (GetLastError() != MAPI_E_SUCCESS) {
		ret = false;
		goto cleanup;
	}
	/* back to the situation with the first heading collapsed */
	if (Denominator != origcount/2 + 6) {
		mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator);
		ret = false;
		goto cleanup;
	}

 cleanup:
	/* Release */
	mapi_object_release(&obj_htable);
	mapi_object_release(&(obj_test_folder));
	mapitest_common_cleanup(mt);

	return ret;
}
Exemplo n.º 30
0
static bool mapitest_noserver_srowset_tagged(struct mapitest *mt)
{
	enum MAPISTATUS		retval;
	struct loadparm_context	*lp_ctx = NULL;
	DATA_BLOB		rawData;
	uint8_t			rawDataHex[1024];
	struct SRowSet		rowSet;
	struct SRowSet		referenceRowSet;
	struct SPropTagArray	*proptags;
	uint32_t		rowNum;

	retval = GetLoadparmContext(mt->mapi_ctx, &lp_ctx);
	if (retval != MAPI_E_SUCCESS) return false;

	rawData.data = talloc_array(mt->mem_ctx, uint8_t, 1024);
	memcpy(rawDataHex, SROWSET_TAGGED, 2*SROWSET_TAGGED_LEN);
	rawData.length = strhex_to_str((char*)rawData.data, 1024, (char*)rawDataHex, 2*SROWSET_TAGGED_LEN);
	if (rawData.length != SROWSET_TAGGED_LEN) {
		mapitest_print(mt, "* %-40s: tagged - Bad length\n", "SRowSet");
		return false;
	}

	proptags = set_SPropTagArray(mt->mem_ctx, 2, PR_SENDER_NAME,  PR_BODY);
	rowSet.cRows = 16;
	rowSet.aRow = talloc_array(mt->mem_ctx, struct SRow, 16);
	emsmdb_get_SRowSet(mt->mem_ctx, &rowSet, proptags, &rawData);

	/* Check the resulting SRowSet */
	if (rowSet.cRows != 16) {
		mapitest_print(mt, "* %-40s: unexpected row count: %i\n", "SRowSet", rowSet.cRows);
		return false;
	}

	/* Build reference RowSet */
	referenceRowSet.cRows = rowSet.cRows;
	referenceRowSet.aRow = talloc_array(mt->mem_ctx, struct SRow, rowSet.cRows);
	for (rowNum = 0; rowNum < rowSet.cRows; ++rowNum) {
		referenceRowSet.aRow[rowNum].ulAdrEntryPad = 0;
		referenceRowSet.aRow[rowNum].cValues = 2;
		referenceRowSet.aRow[rowNum].lpProps = talloc_array(mt->mem_ctx, struct SPropValue, 2);
		referenceRowSet.aRow[rowNum].lpProps[0].ulPropTag = PR_SENDER_NAME;
		referenceRowSet.aRow[rowNum].lpProps[0].dwAlignPad = 0;
		referenceRowSet.aRow[rowNum].lpProps[1].ulPropTag = PR_BODY;
		referenceRowSet.aRow[rowNum].lpProps[1].dwAlignPad = 0;
	}
	referenceRowSet.aRow[0].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[0].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[0].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[1].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[1].lpProps[1].value.lpszA = "Body of message 5";
	referenceRowSet.aRow[2].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[2].lpProps[1].value.lpszA = "Body of message 6";
	referenceRowSet.aRow[3].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[3].lpProps[1].value.lpszA = "Body of message 7";
	referenceRowSet.aRow[4].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[4].lpProps[1].value.lpszA = "Body of message 8";
	referenceRowSet.aRow[5].lpProps[0].value.lpszA = "MT Dummy From";
	referenceRowSet.aRow[5].lpProps[1].value.lpszA = "Body of message 9";
	referenceRowSet.aRow[6].lpProps[0].value.lpszA = "MT Dummy0";
	referenceRowSet.aRow[6].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[6].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[7].lpProps[0].value.lpszA = "MT Dummy0";
	referenceRowSet.aRow[7].lpProps[1].value.lpszA = "Body of message 0";
	referenceRowSet.aRow[8].lpProps[0].value.lpszA = "MT Dummy1";
	referenceRowSet.aRow[8].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[8].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[9].lpProps[0].value.lpszA = "MT Dummy1";
	referenceRowSet.aRow[9].lpProps[1].value.lpszA = "Body of message 1";
	referenceRowSet.aRow[10].lpProps[0].value.lpszA = "MT Dummy2";
	referenceRowSet.aRow[10].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[10].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[11].lpProps[0].value.lpszA = "MT Dummy2";
	referenceRowSet.aRow[11].lpProps[1].value.lpszA = "Body of message 2";
	referenceRowSet.aRow[12].lpProps[0].value.lpszA = "MT Dummy3";
	referenceRowSet.aRow[12].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[12].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[13].lpProps[0].value.lpszA = "MT Dummy3";
	referenceRowSet.aRow[13].lpProps[1].value.lpszA = "Body of message 3";
	referenceRowSet.aRow[14].lpProps[0].value.lpszA = "MT Dummy4";
	referenceRowSet.aRow[14].lpProps[1].ulPropTag = PR_BODY_ERROR;
	referenceRowSet.aRow[14].lpProps[1].value.err = MAPI_E_NOT_FOUND;
	referenceRowSet.aRow[15].lpProps[0].value.lpszA = "MT Dummy4";
	referenceRowSet.aRow[15].lpProps[1].value.lpszA = "Body of message 4";

	/* compare result with reference rowset */
	for (rowNum = 0; rowNum < rowSet.cRows; ++rowNum) {
		uint32_t	i;
		/* check each row has expected number of properties */
		if (rowSet.aRow[rowNum].cValues != referenceRowSet.aRow[rowNum].cValues) {
			mapitest_print(mt, "* %-40s: unexpected props count, row %i: %i\n", "SRowSet", rowSet.aRow[rowNum].cValues, rowNum);
			return false;
		}
		for (i=0; i < rowSet.aRow[rowNum].cValues; ++i) {
			/* check property tags are as expected */
			if (rowSet.aRow[rowNum].lpProps[i].ulPropTag != referenceRowSet.aRow[rowNum].lpProps[i].ulPropTag) {
				mapitest_print(mt, "* %-40s: unexpected proptag (%i/%i): 0x%08x\n", "SRowSet", rowNum, i, rowSet.aRow[rowNum].lpProps[i].ulPropTag);
				return false;
			}
			/* check property values are as expected */
			if ((rowSet.aRow[rowNum].lpProps[i].ulPropTag & 0xFFFF) == PT_ERROR) {
				if (rowSet.aRow[rowNum].lpProps[i].value.err != referenceRowSet.aRow[rowNum].lpProps[i].value.err) {
					mapitest_print(mt, "* %-40s: unexpected property error value (%i/%i): 0x%04x\n", "SRowSet", rowNum, i, rowSet.aRow[rowNum].lpProps[i].value.err);
					return false;
				}
			} else {
				if (strcmp(rowSet.aRow[rowNum].lpProps[i].value.lpszA, referenceRowSet.aRow[rowNum].lpProps[i].value.lpszA) != 0) {
					mapitest_print(mt, "* %-40s: unexpected property value (%i/%i): %s\n", "SRowSet", rowNum, i, rowSet.aRow[rowNum].lpProps[i].value.lpszA);
					return false;
				}
			}
		}
	}
	return true;
}