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

fletch at phydeaux.org fletch at phydeaux.org
Thu Jan 5 13:00:34 EST 2006


> 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.
[... snip ...]
> 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.

You're reading the message contents from STDIN so just pass that to the
new method.

my $msg = Mail::Internet->new( \*STDIN );


If you'd already read the whole thing into an array:

my @lines = <>;

You could pass a reference to that:

my $msg = Mail::Internet->new( \@lines );


Or if you'd read it into a scalar you could split on \n and pass that:

my $msg = Mail::Internet->new( [ split( "\n", $contents ) ] );

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U





More information about the Ale mailing list