Raw Headers when using IAMP with out loading EML/MSG

What would be the most efficent way to parse the raw headers of an email a specific field (list-unsubscribe or ThreadTopic/Index for expample) without first saving an EML/MSG to a file or db?

Thanks in advance

Hi,


Thank you for your inquiry.

Please check the ImapClient class for it’s member ListMessages(). This method will return you the ImapMessageInfoCollection object having all the message headers from a particular folder. To get only those messages which match some condition(s), you can easily use the overloaded ListMessages() method which takes MailQuery as an argument.

Hope this helps. In case you have further queries or comments, please feel free to write back.

Thanks for the reply Babar but unless I am missing something the ImapMessageInfoCollection doesnt contain the Raw headers. It appears to me that it only contains the unfolded message headers with the standard "To/From/CC/Subject/Date", etc. Here is a code snippet from what I believe you are talking about doing. And header information such as ThreadTopic/ThreadIndex and List-Unsubscribe are not contained in that collection (i dont believe).

            int msgCount = this.imapClient.ListMessages().Count;
            if (msgCount > 0)
            {
                ImapMessageInfoCollection list = this.imapClient.ListMessages();
            }
            else
            {
                this.imapClient.Disconnect();
                return;
            }

Hi,


Thank you for your feedback.

I am afraid, your required header information (ThreadTopic/ThreadIndex/List-Unsubscribe) is unavailable at the moment by using ImapClient. I have verified this by connecting to my Gmail account.

When you say “is unavailable at the moment by using ImapClient” does that mean that the funcionality is intended to be there but isnt or that it’s working as intended and look elsewhere? Do you have a work around?

Also tried to:

        private void MessageHeader()
        {
            _client.SelectFolder(ImapFolderInfo.InBox);
            ImapMessageInfoCollection messages = _client.ListMessages();
            foreach (ImapMessageInfo message in messages)
            {
                MailMessage msg = _client.FetchMessage(message.UniqueId);
                foreach (MimeHeader header in msg.Headers)
                {
                    if (header.Name.Equals("ThreadTopic"))
                    {
                        string threadTopic = header.RawContent;
                    }
                }
            }
        }

and received an exception of:

Unable to cast object of type 'System.String' to type 'Aspose.Email.Mime.MimeHeader'.

Hi,


Thank you for reporting this to us.

We are able to reproduce your said exception so we have logged a ticket (Id:32865) in our tracking system for correction purposes. Once this issue is resolved, you will be notified automatically.

Regards,

Hi,


Please use the following code snippet to iterate over the MailMessage Headers,

foreach (string key in message.Headers.AllKeys)
{
Console.WriteLine(key + ": " + message.Headers.Get(key));
}