New Outlook Documentation Part 3 - Detecting Header Items

[This is now documented here: https://msdn.microsoft.com/en-us/library/bb820923.aspx]

[This information was also published as https://support.microsoft.com/kb/912239]

This one jumped ahead in the line because Oliver Seaman was asking me about detecting which items are headers. Next post should be about dealing with IMAP header messages.

Topic
A property to identify items in header only state

dispidHeaderItem
Both Cached Exchange mode and IMAP support the concept of header items. Messages in the Cached Exchange OST and in the IMAP PST can be in one of two states: a message in its entirety with the header and body, or a message with only its header downloaded.

This property can be used to determine the current state of a message.

Note: this property does not apply to remote transport headers, which can be distinguished by the message class “IPM.Remote”.

Definitions

 #define dispidHeaderItem 0x8578
DEFINE_OLEGUID(PSETID_Common, MAKELONG(0x2000+(8),0x0006),0,0);

Usage

This is a named property of type PT_LONG which will be present and non-zero on a message if the message is a header.

 BOOL bIsHeader(LPMESSAGE lpMessage)
{
 HRESULT         hRes = S_OK;
    BOOL            bRet = false;
   ULONG           ulVal = 0;
  LPSPropValue    lpPropVal = NULL;
   LPSPropTagArray lpNamedPropTag = NULL;
  MAPINAMEID      NamedID = {0};
  LPMAPINAMEID    lpNamedID = NULL;

   NamedID.lpguid = (LPGUID) &PSETID_Common;
   NamedID.ulKind = MNID_ID;
   NamedID.Kind.lID = dispidHeaderItem;
    lpNamedID = &NamedID;

   hRes = lpMessage->GetIDsFromNames(1, &lpNamedID, NULL, &lpNamedPropTag);

 if (lpNamedPropTag && 1 == lpNamedPropTag->cValues)
  {
       lpNamedPropTag->aulPropTag[0] = CHANGE_PROP_TYPE(lpNamedPropTag->aulPropTag[0], PT_LONG);

     //Get the value of the property.
        hRes = lpMessage->GetProps(lpNamedPropTag, 0, &ulVal, &lpPropVal);
       if (lpPropVal && 1 == ulVal && PT_LONG == PROP_TYPE(lpPropVal->ulPropTag) && lpPropVal->Value.ul)
     {
           bRet = true;
        }
   }
   
    MAPIFreeBuffer(lpPropVal);
  MAPIFreeBuffer(lpNamedPropTag);
 return bRet;
}

[Update: Added KB link]