As your title implies,
MIME-tools will help with getting the information out of the email once you have received it. You will need to get your hands on the email first, of course. If your mail lives on a POP3 server, use
Net::POP3 to get it.
I will now assume that your mail is sitting in a text file named incoming.
#!/usr/bin/perl -w
use strict;
use MIME::Parser;
my $parser=new MIME::Parser;
$parser->output_dir("mime");
open FILE, "incoming" ||die "could not open\n";
my $email=$parser->read(\*FILE)||die "could not parse\n";
close FILE;
## Now $email is a MIME::Entity.
if (!$email->parts) {
my $bodyh=$email->bodyhandle;
my $IO = $body->open("r") || die "open body: $!";
open OUTFILE, ">body";
while(defined($_ = $IO->getline)) {
print OUTFILE;
}
$IO->close;
close OUTFILE;
} else {
print "This is a multipart MIME message, and I need to do more work
+to be able to read it.\n";
}
$email->purge;
Hopefully that gets you started... No guarantees against typos in the code...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.