A quick not is that never rely on results from PR_DISPLAY_NAME because names like "Inbox","Drafts Folder" can be localized.
Here is the code snippet i use.
You have to use it like this.
if (isFolderTypeSame(pSession,pFolder,PR_CE_IPM_INBOX_ENTRYID))
You can use these values for third parameter.
PR_CE_IPM_DRAFTS_ENTRYID
CE_IPM_INBOX_ENTRYID
PR_IPM_OUTBOX_ENTRYID
PR_IPM_WASTEBASKET_ENTRYID
PR_IPM_SENTMAIL_ENTRYID
bool isFolderTypeSame(IMAPISession *m_pSession,LPMAPIFOLDER pFolder,ULONG _PR_FOLDERTYPE)
{
HRESULT hr = E_FAIL;
CComPtr<IMsgStore> pms ;
ULONG cItems;
SizedSPropTagArray(2, rgtagsFldr) = {2 , PR_OWN_STORE_ENTRYID,PR_ENTRYID};
ULONG entryid[] = { 1, _PR_FOLDERTYPE };
LPSPropValue fldrprops=NULL,msgstoreprops = NULL;
ULONG result=0;
// This method assumes that the CALLER already logged on to a MAPISession
if (!m_pSession)
CHR(E_FAIL);
// Now request the PR_OWN_STORE_ENTRYID on the folder. This is the
// ENTRYID of the message store that owns the folder object.
hr = pFolder->GetProps((SPropTagArray *) &rgtagsFldr, MAPI_UNICODE, &cItems, &fldrprops);
CHR(hr);
// Now open the message store object.
hr = m_pSession->OpenEntry(fldrprops[0].Value.bin.cb,(LPENTRYID)fldrprops[0].Value.bin.lpb,NULL,
0, NULL, (LPUNKNOWN*)&pms);
CHR(hr);
// Get the ENTRYID of the wastebasket for the message store
hr = pms->GetProps((LPSPropTagArray)entryid, MAPI_UNICODE, &cItems, &msgstoreprops);
CHR(hr);
m_pSession->CompareEntryIDs(fldrprops[1].Value.bin.cb,(LPENTRYID)fldrprops[1].Value.bin.lpb,msgstoreprops[0].Value.bin.cb,(LPENTRYID)msgstoreprops[0].Value.bin.lpb,0,&result);
Error:
MAPIFreeBuffer(msgstoreprops);
MAPIFreeBuffer(fldrprops);
return result;
}
No comments:
Post a Comment