0 votes
by (270 points)
edited

It seems that the parser does not process the Received header correctly. It only returns the last one, but it is possible for a message to contain more than one Received header (as each server that the mail passes through adds one. I've tried with the MailMessage and MimeMessage objects and both have the same results. How can access the complete list of Received headers?

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (147k points)
edited
 
Best answer

The parser processes the Received header correctly, but the name-based indexer of MimeHeaderCollection class only returns the first header value (this is documented behavior).

To access the complete list of Received headers, simply iterate through the MimeHeaderCollection. Like this, for example:

MailMessage message = new MailMessage();
...
foreach (MimeHeader header in message.Headers)
{
    if (string.Equals(header.Name, "Received", StringComparison.OrdinalIgnoreCase))
    {
        Display(header.Value);
    }
}
by (270 points)
Worked perfectly thanks! I guess in my mind I was expecting them to all be returned maybe separated with crlf.
by (147k points)
Yes, I suppose we could return the Received headers separated with CRLF, but we would have to come up with another solution for other headers, and it has never really been needed. I guess adding a method called GetAllHeaderValues(string headerName) would be useful.
by (13.0k points)
edited

UPDATE: MimeHeaderCollection.GetAllHeaders and GetAllHeaderValuesRaw methods are included in Release 2012 R1 http://blog.rebex.net/news/archive/2012/03/08/version-2012-r1.aspx

...