On Thursday, October 29, 2015 at 1:28:21 PM UTC-4, Giulio Iotti wrote:
On Thursday, October 29, 2015 at 6:52:44 PM UTC+2, Mark Fletcher wrote:
I'm using the net/mail package to parse/manipulate email messages. I would like to be able to regenerate the emails with the headers in the original order, but because mail uses a map to store the header lines, this isn't possible. Short of writing my own email parsing package, does anyone have any ideas for how I could augment net/mail so that I can get the headers back in order? I've racked my brain (didn't take long), and couldn't think of any way to do so.
If you really need to do this (because the order doesn't really matter, why do you want to keep the order?) I can suggest two options:
IIRC the RFC specifies that general headers SHOULD NOT be reordered, and some headers specifically MUST NOT be reordered.
(well, I'm this far, might as well look it up ;) ...)
RFC5322 3.6
> It is important to note that the header fields are not guaranteed to
be in a particular order. They may appear in any order, and they
have been known to be reordered occasionally when transported over
the Internet. However, for the purposes of this specification,
header fields SHOULD NOT be reordered when a message is transported
or transformed. More importantly, the trace header fields and resent
header fields MUST NOT be reordered, and SHOULD be kept in blocks
prepended to the message.