Perl Mail Messages Handling
Recently we were working on Mail Messages handling and we choose to do it using Perl. Perl has lot of modules that can be of great help .... the granddaddy of these modules is Mail::Internet, originally created by Graham Barr and now maintained by Mark Overmeer. This module offers a constructor that takes either an array of lines or a filehandle, reads a message, and returns a Mail::Internet object representing the message.
You can get From, Reply-To, To, Subject using get() method. Reading and editing the body is done through the body method.
I've not said anything about MIME yet. Mail::Internet is reasonably handy for simple tasks, but it doesn't handle MIME at all. So we used another module as Email::MIME.
Here is the full code:
require Mail::Internet;
require Mail::Address;
require Email::MIME;
$mail = Mail::Internet->new( \*STDIN );
my $sender = $mail->get('Reply-To') || $mail->get('From');
my $to = $mail->get('To');
my $subject = $mail->get('Subject');
my $body = $mail->as_string();
my $email = Email::MIME->new($body);
my $part_body = ($email->subparts())[0]->body;
You can get From, Reply-To, To, Subject using get() method. Reading and editing the body is done through the body method.
I've not said anything about MIME yet. Mail::Internet is reasonably handy for simple tasks, but it doesn't handle MIME at all. So we used another module as Email::MIME.
Here is the full code:
require Mail::Internet;
require Mail::Address;
require Email::MIME;
$mail = Mail::Internet->new( \*STDIN );
my $sender = $mail->get('Reply-To') || $mail->get('From');
my $to = $mail->get('To');
my $subject = $mail->get('Subject');
my $body = $mail->as_string();
my $email = Email::MIME->new($body);
my $part_body = ($email->subparts())[0]->body;

0 Comments:
Post a Comment
<< Home