R
ryotyankou via OfficeKB.com
I need to process the MailItem when OnItemSend were triggered, So i make a
copy(MailItem->Copy) of MailItem, say it is CopyMailItem, then i saved
CopyMailitem(It may be encrypted or signatured, or may be both of them),
after use it, i need to delete this copy. But i couldn't get this
CopyMailItem while it is encrypted or signatured. What should i do to delete
the copy? The code is my attemption:
----------------------------
HRESULT CMyTest::HardDeleteMailItem(Outlook::_MailItemPtr & ItemPtr, BYTE
*pByte, int nByteLen)
{
HRESULT hResult = E_FAIL;
LPENTRYLIST lpTempList = NULL;
//Fill the ENTRYLIST
MAPIAllocateBuffer(sizeof(ENTRYLIST), (LPVOID*)&lpTempList);
if (lpTempList)
{
lpTempList->cValues = 1;
lpTempList->lpbin = NULL;
MAPIAllocateMore((ULONG)sizeof(SBinary), lpTempList, (LPVOID*)&lpTempList-
{
lpTempList->lpbin->cb = nByteLen;
MAPIAllocateMore(nByteLen, lpTempList, (LPVOID *)&lpTempList->lpbin->lpb);
if (lpTempList->lpbin->lpb)
{
CopyMemory(lpTempList->lpbin->lpb, pByte, nByteLen);
}
}
}
Outlook::_NameSpacePtr NameSpacePtr = ItemPtr->GetSession();
Outlook::MAPIFolderPtr pDraftFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook:lFolderDrafts);
if(pDraftFolderPtr == NULL)
{
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return E_FAIL;
}
IMAPIFolder * pFolder = NULL;
if(FAILED(pDraftFolderPtr->GetMAPIOBJECT()->QueryInterface(IID_IMAPIFolder,
reinterpret_cast<void**>(&pFolder))))
{
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return E_FAIL;
}
//Hard Delete message
ULONG ulFlag = DEL_MESSAGES;
hResult = pFolder->DeleteMessages(lpTempList, NULL, NULL, ulFlag);
//Free memory
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return hResult;
----------------------------
But it will fail at pFolder->DeleteMessages, return value is 0x80040106
MAPI_E_UNKNOWN_FLAGS, I tried
#define DELETE_HARD_DELETE ((ULONG) 0x00000010)
ULONG ulFlag = DEL_MESSAGES | DELETE_HARD_DELETE;
too, returned the same error.
what's the wrong with my code? please help me.
copy(MailItem->Copy) of MailItem, say it is CopyMailItem, then i saved
CopyMailitem(It may be encrypted or signatured, or may be both of them),
after use it, i need to delete this copy. But i couldn't get this
CopyMailItem while it is encrypted or signatured. What should i do to delete
the copy? The code is my attemption:
----------------------------
HRESULT CMyTest::HardDeleteMailItem(Outlook::_MailItemPtr & ItemPtr, BYTE
*pByte, int nByteLen)
{
HRESULT hResult = E_FAIL;
LPENTRYLIST lpTempList = NULL;
//Fill the ENTRYLIST
MAPIAllocateBuffer(sizeof(ENTRYLIST), (LPVOID*)&lpTempList);
if (lpTempList)
{
lpTempList->cValues = 1;
lpTempList->lpbin = NULL;
MAPIAllocateMore((ULONG)sizeof(SBinary), lpTempList, (LPVOID*)&lpTempList-
if (lpTempList->lpbin && pByte)lpbin);
{
lpTempList->lpbin->cb = nByteLen;
MAPIAllocateMore(nByteLen, lpTempList, (LPVOID *)&lpTempList->lpbin->lpb);
if (lpTempList->lpbin->lpb)
{
CopyMemory(lpTempList->lpbin->lpb, pByte, nByteLen);
}
}
}
Outlook::_NameSpacePtr NameSpacePtr = ItemPtr->GetSession();
Outlook::MAPIFolderPtr pDraftFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook:lFolderDrafts);
if(pDraftFolderPtr == NULL)
{
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return E_FAIL;
}
IMAPIFolder * pFolder = NULL;
if(FAILED(pDraftFolderPtr->GetMAPIOBJECT()->QueryInterface(IID_IMAPIFolder,
reinterpret_cast<void**>(&pFolder))))
{
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return E_FAIL;
}
//Hard Delete message
ULONG ulFlag = DEL_MESSAGES;
hResult = pFolder->DeleteMessages(lpTempList, NULL, NULL, ulFlag);
//Free memory
MAPIFreeBuffer(lpTempList->lpbin->lpb);
MAPIFreeBuffer(lpTempList->lpbin);
MAPIFreeBuffer(lpTempList);
return hResult;
----------------------------
But it will fail at pFolder->DeleteMessages, return value is 0x80040106
MAPI_E_UNKNOWN_FLAGS, I tried
#define DELETE_HARD_DELETE ((ULONG) 0x00000010)
ULONG ulFlag = DEL_MESSAGES | DELETE_HARD_DELETE;
too, returned the same error.
what's the wrong with my code? please help me.