Hello,

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("imap.gmail.com", 993, null, ImapSecurity.Implicit);
            imap.Login(username, password);
            imap.SelectFolder("Inbox");
            ImapMessageCollection collection = imap.GetMessageList(ImapListFields.FullHeaders);
            foreach (ImapMessageInfo msg in collection)
            {
                Console.WriteLine(msg.MessageId.Id);
            }
            Console.Read();
}

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

asked 07 Mar '10, 14:11

Wakatake's gravatar image

Wakatake
384
accept rate: 0%

edited 11 Mar '10, 19:53

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310


Hello,

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(msg.MessageId.Id);
   else
      Console.WriteLine("Message has no Message-ID header set.");
}
link

answered 08 Mar '10, 11:39

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×76
×53
×6

Asked: 07 Mar '10, 14:11

Seen: 861 times

Last updated: 25 Mar '11, 12:23