How to parse the Email into sections like, header, body, attachment, and sender and receiver? I would like to use Perl or Perl Moose?
Asked
Active
Viewed 7,326 times
1 Answers
9
see Mail::Message - general message object something like,
my $msg =Mail::Message->new($mail);
my $body = $msg->body;
my @to = $msg->to;
my @from = $msg->from;
or see Email::Simple - simple parsing of RFC2822 message format and headers.
Updated:
see also Email::MIME - Easy MIME message parsing.

Nikhil Jain
- 8,232
- 2
- 25
- 47
-
2The interface of Mail::Message for multipart messages (what jubf calls "attachment") is really complicated to use. I recommend [Email::MIME](http://p3rl.org/Email::MIME) instead which is derived from Email::Simple. – daxim Apr 07 '11 at 12:08
-
@daxim: yes, good point, I should add `Email::MIME` in my answer too. – Nikhil Jain Apr 07 '11 at 15:29
-
What is "$mail" in this context? The constructor seems to take a lot of different options, but it's not clear how to just dump an entirely constructed email (a simple string) in to it. – Jun 09 '11 at 17:17
-
$mail is a raw mail message, as you can take from maildir, a really long string, no problem. – sekrett Apr 21 '15 at 11:02