[ale] Easy way to cut body of email in perl

Christopher Fowler cfowler at outpostsentinel.com
Thu Jan 5 08:46:13 EST 2006


On Thu, 2006-01-05 at 08:37 -0500, fletch at phydeaux.org wrote:
> >> In this case, sure.  In general, no since there's no guaranteed ordering
> >> of headers.
> >> Safest bet would be to use Mail::Internet or the like and let that parse
> >> things.
> >
> > It's been a while since i was manually deconstructing mail, but IIRC
> > there's a blank line between headers and body ... and between messages.
> 
> Sure.  Not that it's not trivial to separate the two.
> 
> my( $headers, $body );
> while( <> ) {
> 
> 
> But then you've got to do grunt work such as parsing the headers yourself.
>  Much simpler just to use a well tested module and be done with it.
> 

I looked at Mail::Internet and unless I read the perldoc wrong I did not
see a way I could pass the whole email to a new object and then have it
parsed.

http://search.cpan.org/~markov/MailTools-1.71/Mail/Internet.pm
-------------------------------------------------------------------------------
CONSTRUCTOR

new ( [ ARG ], [ OPTIONS ] )
        
        ARG is optional and may be either a file descriptor (reference
        to a GLOB) or a reference to an array. If given the new object
        will be initialized with headers and body either from the array
        of read from the file descriptor.
        
        OPTIONS is a list of options given in the form of key-value
        pairs, just like a hash table. Valid options are
        
        
Header
        
        The value of this option should be a Mail::Header object. If
        given then Mail::Internet will not attempt to read a mail header
        from ARG, if it was specified.
        
Body
        
        The value of this option should be a reference to an array which
        contains the lines for the body of the message. Each line should
        be terminated with \n (LF). If Body is given then Mail::Internet
        will not attempt to read the body from ARG (even if it is
        specified).
        

The Mail::Header options Modify, MailFrom and FoldLength may also be
given.
-------------------------------------------------------------------------------
Maybe I'm reading it wrong?









More information about the Ale mailing list