This project is read-only.

Message Properties from Headers

Feb 19, 2009 at 7:26 PM
Is there a reason you chose not to populate certain message properties while parsing the headers?  It seems that, for example, when you parse the "To" header, it should be added to the "To" property of the MailMessage.  In my testing, while the "To" header is listed among the headers, the "To" property remain at a zero count.

.Net appears to be getting involved at some level because even though you specify tolower() for all of the headers, it re-caps some of the headers.  ("To", "From", etc...)  But it's not automatically adding these values to the appropriate MailMessage properties.  Not sure what that's about.

Any insight?

Also, could you give a quick comment on what each of the RegEx expression are supposed to do.  I think I've got it figured out, but I'd kinda like to check my work.  Thanks.

Feb 21, 2009 at 9:17 AM
I've fixed the missing To header now. Will check in new version shortly.

And yes, .net is magically recasing some of the headers. I have no idea why Microsoft has chosen to do this, and which headers they do it to, but it was another argument why it didn't matter that I lower-cased the headers :-) I guess it happens somewhere in the inner workings of the MailMessage object.

I've added some comments to the regex'es, but are there any in particular you wonder about? They are mostly just simple regex extracting the values of the headers, but some of them takes a few strange situations into account, which makes them a bit more unreadable.

Feb 21, 2009 at 6:22 PM
Edited Feb 21, 2009 at 6:24 PM
Yes... That's a simple fix. I hadn't reviewed the bits where you were making those adjustments before I posted. And there are a few more standard fields that can be translated in the process.

As far as the caps.. I just leaned towards keeping them as in the message and adjusting when comparing. I can't really say I have a good reason. But in some cases I output certain headers and just wanted them to match the way they were originally formatted.

I want to understand all of the regex's... There are a couple with some syntax that I was not familiar with, such as: "=\?.*?\?B\?(.*?)\?="
I can tell it involved breaking the lines up but I can't quite decode it completely, so I was taking the lazy route and asking the author what the intent was. :0)

Thanks for your time and effort on this code. I will be sure to keep a credit for you in my project. There are a few parsers out there, but yours seemed the best foundation for tweaking it into what I needed.