Link to home
Start Free TrialLog in
Avatar of jonawebb
jonawebb

asked on

Access all headers programmatically?

Can anyone tell me if there is a way to get all the headers of an outlook message from a COM plugin? I have gotten access to the _MailItem, and can get headers like To:, Subject:, etc. using get_To, get_Subject, etc. But the _MailItem interface doesn't seem to allow me to get, for example, Return-Path. Is there a way I can get access to the "raw" headers, or to any headers that Outlook didn't know what to do with?

Jon Webb
ASKER CERTIFIED SOLUTION
Avatar of Neo_mvps
Neo_mvps

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonawebb
jonawebb

ASKER

Your answer, while not quite right, was invaluable in pointing me in the right direction. I'd be happy to give you full credit for the answer if you'll post it as such.

The solution I came up with was this:

#include <mapix.h>
#include <initguid.h>
#include <mapiguid.h>

     IDispatch *pItem;
        // ... initialize pItem by lookup in an Outlook folder

     CComQIPtr<Outlook::_MailItem> pMail(pItem);
     ATLASSERT(pMail);
     IUnknown* pUnk = NULL;
     pMail->get_MAPIOBJECT(&pUnk);
     ATLASSERT(pUnk);
     CComQIPtr<IMAPIProp, &IID_IMAPIProp> pMAPIProp(pUnk);
     ATLASSERT(pMAPIProp);
     SPropTagArray ar = {0};
     ULONG nProps = 0;
     SPropValue *arProps = NULL;
     char *szResult = NULL;

     ar.cValues = 1;
     ar.aulPropTag[0] = PR_TRANSPORT_MESSAGE_HEADERS;
     pMAPIProp->GetProps(&ar, PT_UNSPECIFIED, &nProps, &arProps);
I forgot to add:
1) The IDispatch returned by get_MAPIOBJECT supports two interfaces that I could find documentation on: IMAPIProp and IMAPISession. The fact that these interfaces are supported is undocumented anywhere; I found them by stepping through the assembly.
2) IMAPIProp is what you use to get the headers. In my code, GetProps returns the header as a string in the arProps parameter.
3) There are two different kinds of IMessage interfaces. The Microsoft documentation is even more elliptical and unorganized than usual.
Very cool and thanks for the grade of A.
oops... should have said B.