How to get the encrypted MailItem on OutLook2003?

  • Thread starter ryotyankou via OfficeKB.com
  • Start date
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-
if (lpTempList->lpbin && pByte)
{
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::eek: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.
 
D

Dmitry Streblechenko

DELETE_HARD_DELETE only works in the Exchange online store.
Have you tried to just pass 0?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
R

ryotyankou via OfficeKB.com

yes, i tried to just pass 0 to DeleteMessages, return error is
MAPI_W_PARTIAL_COMPLETION. Maybe it is because my type is POP3/SMTP.
What should i do then, just to delete this item completely? Please help me.

Dmitry said:
DELETE_HARD_DELETE only works in the Exchange online store.
Have you tried to just pass 0?
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
[quoted text clipped - 63 lines]
too, returned the same error.
what's the wrong with my code? please help me.
 
D

Dmitry Streblechenko

Why do you assume that Drafts folder is the parent for the new item?
If anything it would be the Inbox. Or, even better, retrieve the parent
folder from the MailItem.Parent property.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
yes, i tried to just pass 0 to DeleteMessages, return error is
MAPI_W_PARTIAL_COMPLETION. Maybe it is because my type is POP3/SMTP.
What should i do then, just to delete this item completely? Please help
me.

Dmitry said:
DELETE_HARD_DELETE only works in the Exchange online store.
Have you tried to just pass 0?
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
[quoted text clipped - 63 lines]
too, returned the same error.
what's the wrong with my code? please help me.
 
R

ryotyankou via OfficeKB.com

I'm sorry for reply so lately because of the Chinese New Year. Ok, let's
continue our discuss.
Thank you for your response.
Do you mean that if the Item's in inbox, then i can get this item even it
were encrypted?
I couldn't get your idea clearly, would you please explain it more detailed,
thank you.
One more question, what could i do with the item's parent folder? TIA.

Dmitry said:
Why do you assume that Drafts folder is the parent for the new item?
If anything it would be the Inbox. Or, even better, retrieve the parent
folder from the MailItem.Parent property.
yes, i tried to just pass 0 to DeleteMessages, return error is
MAPI_W_PARTIAL_COMPLETION. Maybe it is because my type is POP3/SMTP.
[quoted text clipped - 10 lines]
 
D

Dmitry Streblechenko

What I meant is that the folder that you use to call
IMAPIFolder::DeleteMessages() is always the Drats folder
(NameSpacePtr->GetDefaultFolder(Outlook::eek:lFolderDrafts); and it is highly
unlikely that the actual parent fodler is Drafts.
..I was simply suggesting to try to use the actual parent folder,.which can
be retrieved from MailItem.Parent.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
I'm sorry for reply so lately because of the Chinese New Year. Ok, let's
continue our discuss.
Thank you for your response.
Do you mean that if the Item's in inbox, then i can get this item even it
were encrypted?
I couldn't get your idea clearly, would you please explain it more
detailed,
thank you.
One more question, what could i do with the item's parent folder? TIA.

Dmitry said:
Why do you assume that Drafts folder is the parent for the new item?
If anything it would be the Inbox. Or, even better, retrieve the parent
folder from the MailItem.Parent property.
yes, i tried to just pass 0 to DeleteMessages, return error is
MAPI_W_PARTIAL_COMPLETION. Maybe it is because my type is POP3/SMTP.
[quoted text clipped - 10 lines]
too, returned the same error.
what's the wrong with my code? please help me.
 
R

ryotyankou via OfficeKB.com

Hi, Dmitry, I tried your suggestion, but it not work, the code is almost the
same as i posted before, just make a little change.
Change this:
Outlook::MAPIFolderPtr pDraftFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook::eek:lFolderDrafts);
To:
Outlook::MAPIFolderPtr pDraftFolderPtr = ItemPtr->GetParent();
While i Call DeleteMessages(...), it failed with return value: 0x80040106
(Pass in DEL_MESSAGES or HARD_DELETE_MESSAGE flag) and 0x00040680(Pass in 0.).


Dmitry said:
What I meant is that the folder that you use to call
IMAPIFolder::DeleteMessages() is always the Drats folder
(NameSpacePtr->GetDefaultFolder(Outlook::eek:lFolderDrafts); and it is highly
unlikely that the actual parent fodler is Drafts.
.I was simply suggesting to try to use the actual parent folder,.which can
be retrieved from MailItem.Parent.
I'm sorry for reply so lately because of the Chinese New Year. Ok, let's
continue our discuss.
[quoted text clipped - 15 lines]
 
D

Dmitry Streblechenko

0x80040106 is MAPI_E_UNKNOWN_FLAGS
0x00040680 is MAPI_W_PARTIAL_COMPLETION

So essentially you are back to where you are started...


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
Hi, Dmitry, I tried your suggestion, but it not work, the code is almost
the
same as i posted before, just make a little change.
Change this:
Outlook::MAPIFolderPtr pDraftFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook::eek:lFolderDrafts);
To:
Outlook::MAPIFolderPtr pDraftFolderPtr = ItemPtr->GetParent();
While i Call DeleteMessages(...), it failed with return value: 0x80040106
(Pass in DEL_MESSAGES or HARD_DELETE_MESSAGE flag) and 0x00040680(Pass in
0.).


Dmitry said:
What I meant is that the folder that you use to call
IMAPIFolder::DeleteMessages() is always the Drats folder
(NameSpacePtr->GetDefaultFolder(Outlook::eek:lFolderDrafts); and it is highly
unlikely that the actual parent fodler is Drafts.
.I was simply suggesting to try to use the actual parent folder,.which can
be retrieved from MailItem.Parent.
I'm sorry for reply so lately because of the Chinese New Year. Ok, let's
continue our discuss.
[quoted text clipped - 15 lines]
too, returned the same error.
what's the wrong with my code? please help me.
 
R

ryotyankou via OfficeKB.com

I use MFCMAPI to delete the encrypted message(with HARD_DELETE flag), it also
failed with MAPI_E_UNKNOWN_FLAGS.
But i choose the "Permanent deletion (deletes to deleted item retention if
supported)", it's ok, the message's gone. I trace the code, then trace my
code, finally i found that the error is caused by the message's entryid, my
entryid is not correct, now it is ok, thank you for your help!

Dmitry said:
0x80040106 is MAPI_E_UNKNOWN_FLAGS
0x00040680 is MAPI_W_PARTIAL_COMPLETION

So essentially you are back to where you are started...
Hi, Dmitry, I tried your suggestion, but it not work, the code is almost
the
[quoted text clipped - 20 lines]
 
Top