Re: Header folding
Mark Overmeer <[email protected]> Thu, 19 Aug 2004 10:13:40 +0200
| Newsgroups | gmane.comp.lang.perl.modules.mail-box |
|---|---|
| Organization | MARKOV Solutions |
| Message-ID | <[email protected]> |
* David A Golden ([email protected]) [040818 22:26]: > Wow. Given the documentation, that's definitely unexpected behavior. It > looks like the default wrapping never gets set properly. Here's some code > that's a workaround: > > __BEGIN__ > #!/usr/bin/perl > use Mail::Message; > > my $msg = Mail::Message->read(\*STDIN); > $_->setWrapLength(78) for $msg->head->orderedFields; > $msg->print; > __END__ > > Mark -- this looks like a bug, but I'm stumped trying to track it down > through the class hierarchy and overloadings. I do not know where this is documented that way, but it will surely be a left-over from old behavior. Old behavior was copied from Mail::Internet, but has been modified to comply with the RFCs. According to RFC2822: The more conservative 78 character recommendation is to accommodate the many implementations of user interfaces that display these messages which may truncate, or disastrously wrap, the display of more than 78 characters per line, in spite of the fact that such implementations are non-conformant to the intent of this specification (and that of [RFC2821] if they actually cause information to be lost). Again, even though this limitation is put on messages, it is encumbant upon implementations which display messages to handle an arbitrarily large number of characters in a line (certainly at least up to the 998 character limit) for the sake of robustness. As you see, folding is a recommendation, not a MUST. The disadvantage on automatic folding fields are plenty: - applications, like SpamAssassin, may wish the exact folding regardless how long the lines are. - messages will change in size (added/removed \n) - some messages have a reason to fold in certain short lines, for instance if they want to show a postal address. You don't want to break that. - after folding, the message in memory is different from the message in the folder file. - refolding will require quite a lot of processing power. Especially the last point made me decide that folding should be kept in-tact, unless explicitly (knowingly) re-folded. But when you wish it to happen it should be simple, and that was a missing library feature. So, in the next release Mail::Message::Head::Complete will contain: =method wrap INTEGER Re-fold all fields from the header to contain at most INTEGER number of characters per line. =example re-folding a header $msg->head->wrap(78); =cut sub wrap($) { my ($self, $length) = @_; $_->setWrapLength($length) foreach $self->orderedFields; } -- Thanks, MarkOv ------------------------------------------------------------------------ drs Mark A.C.J. Overmeer MARKOV Solutions [email protected] [email protected] http://Mark.Overmeer.net http://solutions.overmeer.net