Re: Header folding

David A Golden <[email protected]> Wed, 18 Aug 2004 16:26:19 -0400
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <5.2.0.9.2.20040818160814.03e43a10@localhost>
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.

-- David

At 8/18/2004 02:34 PM, Scott Grim wrote:
>In your example, you're taking mail from procmail.  Every header line should
>already be folded.  Try piping a message with unfolded lines directly
>through your script.
>
>Here's a simple script I wrote to test it:
>
>-- BEGIN --
>#!/usr/bin/perl
>
>use Mail::Message;
>
>my $msg = Mail::Message->read(\*STDIN);
>my $head = $msg->head;
>
>## Some header manipulation here.
>
>print $msg->string;  # could use $msg->print as well.
>-- END --
>
>cat any message with an unfolded header line such as a  Received line
>through that script and it'll come out unfolded.  I need the output of
>$msg->string to be folded.
>
>
>----- Original Message -----
>From: "David A Golden" <[email protected]>
>To: <[email protected]>
>Sent: Wednesday, August 18, 2004 1:52 PM
>Subject: Re: Header folding
>
>
> > At 8/18/2004 01:15 PM, Scott Grim wrote:
> > >It appears that the read method in Mail::Message::Construct::Read assumes
> > >that all header lines are already folded and makes no effort to fold
>them.
> > >Is there any (easy) way around this in the case that the header has lines
> > >that are, in fact, not folded?
> > >
> > >I have the entire message in a scalar variable and would like to use read
>to
> > >put it into a Mail::Message object.  From there, I need to evaluate and
> > >sometimes modify header information (to do spam marking, etc) before
> > >inserting the message into a database for a database-driven mail system.
> >
> > Reading from a scalar (or filehandle) should handle folded and unfolded
> > headers just fine in the input.  Are you having problems with the input or
> > the folding of headers when outputting the message after you've modified
> > it?  (Mail::Box defaults to folding headers if they exceed 78 characters.)
> > Can you post some example code and output that shows the problem your
>having?
> >
> > For reference, here's how I use Mail::Box as a procmail filter for spam
> > tagging:
> >
> > <>; # ignore the "From_" line that procmail adds
> > my $msg = Mail::Message->read(\*STDIN);
> > $bb->tagmsg( { msg=>$msg, %options } ); # A Mail::Classifier object
> > print $msg->head->createFromLine;
> > $msg->print;
> >
> > Regards,
> > David
> >
> >