Пример #1
0
LPWSTR getFolderName(IMsgStore* pStore, ULONG cbEntryID, LPENTRYID lpEntryID) 
{
	
	HRESULT hRes = E_FAIL;
	ULONG ulObjType = MAPI_FOLDER;
	LPMAPIFOLDER lpFolder = NULL;
	
	// Get parent folder
	hRes = pStore->OpenEntry(cbEntryID, lpEntryID, 0, 0, &ulObjType, (LPUNKNOWN*)&lpFolder);
	if (hRes != S_OK) {
		return NULL;
	}
	
	SizedSPropTagArray(2, ptaFolder) = {2, {PR_DISPLAY_NAME, PR_ENTRYID}};
	LPSPropValue rgFolderProps = NULL;
	ULONG cValues = 0;
	
	// Get parent folder properties
	hRes = lpFolder->GetProps((LPSPropTagArray)&ptaFolder, MAPI_UNICODE, &cValues, &rgFolderProps);
	if (hRes != S_OK) {
		lpFolder->Release();
		return NULL;
	}
	
	// folder name
	return rgFolderProps[0].Value.lpszW;
}
Пример #2
0
HRESULT DetectFolderDetails(LPMAPIFOLDER lpFolder, string *lpName, string *lpClass, ULONG *lpFolderType)
{
	HRESULT hr = hrSuccess;
	LPSPropValue lpPropertyArray = NULL;
	ULONG ulPropertyCount = 0;

	SizedSPropTagArray(3, PropertyTagArray) = {
		3,
		{
			PR_DISPLAY_NAME_A,
			PR_CONTAINER_CLASS_A,
			PR_FOLDER_TYPE,
		}
	};

	hr = lpFolder->GetProps((LPSPropTagArray)&PropertyTagArray,
			      0,
			      &ulPropertyCount,
			      &lpPropertyArray);
	if (FAILED(hr)) {
		cout << "Failed to obtain all properties." << endl;
		goto exit;
	}

	*lpFolderType = 0;

	for (ULONG i = 0; i < ulPropertyCount; i++) {
		if (PROP_TYPE(lpPropertyArray[i].ulPropTag) == PT_ERROR)
			hr = MAPI_E_INVALID_OBJECT;
		else if (lpPropertyArray[i].ulPropTag == PR_DISPLAY_NAME_A)
			*lpName = lpPropertyArray[i].Value.lpszA;
		else if (lpPropertyArray[i].ulPropTag == PR_CONTAINER_CLASS_A)
			*lpClass = lpPropertyArray[i].Value.lpszA;
		else if (lpPropertyArray[i].ulPropTag == PR_FOLDER_TYPE)
			*lpFolderType = lpPropertyArray[i].Value.ul;
	}

	/*
	 * As long as we found what we were looking for, we should be satisfied.
	 */
	if (!lpName->empty() && !lpClass->empty())
		hr = hrSuccess;

exit:
	if (lpPropertyArray)
		MAPIFreeBuffer(lpPropertyArray);

	return hr;
}
CString CExMapi::GetFolderName(LPMAPIFOLDER lpFolder)
{
	CString folderName = L"";
	if(!lpFolder) return folderName;

	LPSPropValue props=NULL;
	ULONG cValues=0;
	ULONG rgTags[]={ 1, PR_DISPLAY_NAME };

	if(SUCCEEDED(lpFolder->GetProps((LPSPropTagArray) rgTags, CExMapi::cm_nMAPICode, &cValues, &props)))
	{
		folderName = CExMapi::GetValidString(*props);		
	}
	return folderName;
}
BOOL CExMapi::IsContactFolder(LPMAPIFOLDER lpFolder)
{
	if(!lpFolder) return FALSE;

	LPSPropValue props=NULL;
	ULONG cValues=0;
	ULONG rgTags[]={ 1, PR_CONTAINER_CLASS };

	if(SUCCEEDED(lpFolder->GetProps((LPSPropTagArray) rgTags, CExMapi::cm_nMAPICode, &cValues, &props)))
	{
		CString containerClass = CExMapi::GetValidString(*props);
		if(containerClass == L"IPF.Contact")
			return TRUE;
	}
	return FALSE;
}
Пример #5
0
// Deletes a sub folder and ALL sub folders/messages
BOOL CMAPIEx::DeleteSubFolder(LPMAPIFOLDER pSubFolder, LPMAPIFOLDER pFolder) {
    if (!pSubFolder) return FALSE;

    if (!pFolder) {
        pFolder = m_pFolder;
        if (!pFolder) return FALSE;
    }

    LPSPropValue props    = NULL;
    ULONG        cValues  = 0;
    ULONG        rgTags[] = { 1, PR_ENTRYID };

    if (pSubFolder->GetProps((LPSPropTagArray)rgTags, CMAPIEx::cm_nMAPICode, &cValues, &props) == S_OK) {
        HRESULT hr = pFolder->DeleteFolder(props[0].Value.bin.cb, (LPENTRYID)props[0].Value.bin.lpb, NULL, NULL, DEL_FOLDERS | DEL_MESSAGES);
        MAPIFreeBuffer(props);
        return hr == S_OK;
    }
    return FALSE;
}
Пример #6
0
LPMAPIFOLDER CMAPIEx::OpenSpecialFolder(unsigned long ulFolderID, BOOL bInternal) {
    LPMAPIFOLDER pInbox = OpenInbox(FALSE);

    if (!pInbox || !m_pMsgStore) return FALSE;

    LPSPropValue props   = NULL;
    ULONG        cValues = 0;
    DWORD        dwObjType;
    ULONG        rgTags[] = { 1, ulFolderID };
    LPMAPIFOLDER pFolder;

    if (pInbox->GetProps((LPSPropTagArray)rgTags, cm_nMAPICode, &cValues, &props) != S_OK) return NULL;
    m_pMsgStore->OpenEntry(props[0].Value.bin.cb, (LPENTRYID)props[0].Value.bin.lpb, NULL, m_ulMDBFlags, &dwObjType, (LPUNKNOWN *)&pFolder);
    MAPIFreeBuffer(props);
    RELEASE(pInbox);

    if (pFolder && bInternal) {
        RELEASE(m_pFolder);
        m_pFolder = pFolder;
    }
    return pFolder;
}
Пример #7
0
/**
 * Add new folders to the favorites folder
 *
 * @param lpSession Pointer to the current mapi session
 * @param lpFolder Pointer to a folder in the public store, except a folder from the favorites folder
 * @param lpAliasName Pointer to a string containing another name for the folder
 * @param ulFlags Bitmask of flags that controls how the folder is added. The following flags can be set:
 * FAVO_FOLDER_LEVEL_BASE
 *		Add only the folder itself
 * FAVO_FOLDER_LEVEL_ONE
 *		Add the folder and the immediate subfolders only
 * FAVO_FOLDER_LEVEL_SUB
 *		Add the folder and all subfolders
 * MAPI_UNICODE
 *		lpAliasName parameter is in wide or multibyte format
 */
HRESULT AddFavoriteFolder(LPMAPIFOLDER lpShortcutFolder, LPMAPIFOLDER lpFolder, LPCTSTR lpAliasName, ULONG ulFlags)
{
	HRESULT hr = hrSuccess;
	
	LPMAPITABLE lpTable = NULL;
	LPSPropValue lpsPropArray = NULL;
	LPSPropValue lpPropDepth = NULL; // No free needed

	SRowSet *lpRows = NULL;

	ULONG ulFolderFlags = 0;
	ULONG cValues = 0;

	SizedSPropTagArray(5, sPropsFolderInfo) = {5, { PR_DEPTH, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS}};

// FIXME: check vaiables

	// Add folders to the shorcut folder
	hr = lpFolder->GetProps((LPSPropTagArray)&sPropsFolderInfo, 0, &cValues, &lpsPropArray);
	if (FAILED(hr) != hrSuccess) //Gives always a warning
		goto exit;

	hr = AddToFavorite(lpShortcutFolder, 1, lpAliasName, ulFlags, cValues, lpsPropArray);
	if (hr != hrSuccess)
		goto exit;

	if (lpsPropArray) { MAPIFreeBuffer(lpsPropArray); lpsPropArray = NULL; }


	if (ulFlags == FAVO_FOLDER_LEVEL_SUB) {
		ulFolderFlags = CONVENIENT_DEPTH;
	} else if(ulFlags == FAVO_FOLDER_LEVEL_ONE) {
		ulFolderFlags = 0;
	}else {
		hr = hrSuccess; // Done
		goto exit;
	}

	// Get subfolders
	hr = lpFolder->GetHierarchyTable(ulFolderFlags, &lpTable);
	if (hr != hrSuccess)
		goto exit;

	hr = lpTable->SetColumns((LPSPropTagArray)&sPropsFolderInfo, 0);
	if (hr != hrSuccess)
		goto exit;

	// Add the favorite recusive depended what the flags are
	while(true)
	{
		hr = lpTable->QueryRows (1, 0, &lpRows);
		if (hr != hrSuccess)
			goto exit;

		if (lpRows->cRows == 0)
			break;

		lpPropDepth = PpropFindProp(lpRows->aRow[0].lpProps,lpRows->aRow[0].cValues, PR_DEPTH);
		if (lpPropDepth == NULL) {
			hr = MAPI_E_CORRUPT_DATA;// Break the action
			goto exit;
		}

		hr = AddToFavorite(lpShortcutFolder, lpPropDepth->Value.ul + 1, NULL, 0, lpRows->aRow[0].cValues, lpRows->aRow[0].lpProps);
		if (hr != hrSuccess) {
			// Break the action
			goto exit;
		}

		FreeProws(lpRows);
		lpRows = NULL;

	} //while(true)

exit:
	if (lpTable)
		lpTable->Release();

	if (lpRows)
		FreeProws(lpRows);

	if (lpsPropArray)
		MAPIFreeBuffer(lpsPropArray);


	return hr;
}