Retrieving the Message-ID

+1 vote
asked Mar 7, 2010 by Wakatake (240 points)
edited Mar 25, 2011


How do I parse the Message-ID from the headers?

I have the following:

static void Main(string[] args)
            Imap imap = new Imap();
            imap.Connect("", 993, null, ImapSecurity.Implicit);
            imap.Login(username, password);
            ImapMessageCollection collection = imap.GetMessageList(ImapListFields.FullHeaders);
            foreach (ImapMessageInfo msg in collection)

but I am having a NullReferenceException. How do I go about it, the correct way? Thanks!

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Mar 8, 2010 by Martin Vobr (12,950 points)
edited Mar 8, 2010


the Message-ID header is optional and it looks like you have found a message with missing Message-ID header.

See following quote from the RFC 5322.

3.6.4. Identification Fields

Though listed as optional in the table in section 3.6, every message SHOULD have a "Message-ID:" field.

It means that when creating a new message you should include the Message-ID field, but also that every parser should be able to process messages with Message-ID not set.

Try using this code:

foreach (ImapMessageInfo msg in collection)
   if (msg.MessageId != null)
      Console.WriteLine("Message has no Message-ID header set.");