none
How to enumerate messages in IMailTransportCategorize::EndMessageCategorization? RRS feed

  • Question

  • Hi have a solution for Exchange Server 2007 and 2010 that implements a custom Transport Agent.  This works well.  However, I need to support Exchange Server 2003 too.

    I already have most of an Exchange Server  2003 solution working, via pre and post categorization sinks.  However, one last piece of the puzzle requires me to enumerate the messages passed to the IMailTransportCategorize::EndMessageCategorization handler... but documentation on this interface is scarce, to say the least.

    I actually have the enumeration working, but don't trust it (you'll see why in a second).

    Note, the following code is C# using the PIA wrappers, but this is *not* a C# question... if anyone can tell me how the enumeration is meant to work in *any* language, I'll port it to C# easily enough :)

    So, here's how I've got the enumeration working so far:

    void IMailTransportCategorize.EndMessageCategorization(ICategorizerMailMsgs pICatMsgs, int hrCatStatus) {
      IntPtr pEnum = new IntPtr();
      pICatMsgs.BeginMailMsgEnumeration(ref pEnum);
      uint pdwFlags=0;
      do {
        MailMsg ppIMailMsgProperties;
        IMailMsgRecipientsAdd ppIMailMsgRecipientsAdd;
        pICatMsgs.GetNextMailMsg(ref pEnum, out pdwFlags, out ppIMailMsgProperties, out ppIMailMsgRecipientsAdd);
        Message message = new Message(ppIMailMsgProperties);
        Debug.WriteLine(String.Format("EndMessageCategorization: {0}", message.Rfc822MsgId));
      } while (pdwFlags != 3969908737);
      pICatMsgs.EndMailMsgEnumeration(ref pEnum);
    }
    

    So I'm sure you can see right away why I don't trust it... the do-while loop is being terminated by a "magic" value - 3969908737.  While this always works on my test VM, I simply cannot, in good conscience, deploy it like that.

    So, does anyone know, first of all, if I'm using the BeginMailMsgEnumeration, GetNextMailMsg and EndMailMsgEnumeration functions correctly here?  And can anyone shed any light on the pdwFlags value?

    The pdwFlags value contains 8 "on" bits, so is presumably its a combination of 8 different flags... any ideas what they might be or where they might be documented?

    Thanks! :)

    Paul.

    Tuesday, November 16, 2010 8:43 PM

Answers

  • Ok, so I've answered my own question :)

    Forget the "magic" value (which I've verified does not work safely anyway).

    Instead, simply wrap the ICategorizerMailMsgs::GetNextMailMsg call in a try-catch block, and check for a "No more data is available" (0x80070103) COMException :)

    Nice! :)

    Paul.

    • Marked as answer by pcolby Thursday, November 18, 2010 12:37 AM
    Thursday, November 18, 2010 12:37 AM