Squiddy has asked for the wisdom of the Perl Monks concerning the following question:
Dear Perl Monks, I seek your wisdom (and patience)
I've included my current work below. It's a basic attempt to get mail and parse the MIME attachments. I can get the email without problems using the Mail::POP3Client. I am attempting to send the header and body of each message to the MIME Parser and save the resulting parsed text and files. When I run the script, a number of folders are created in the output directory, but with zero contents.
In other examples I've seen using MIME::Parser there seems to be an object (forgive me if it's called by another name) called $parser->parts, but I can't find it defined in the MIME::Tools (or MIME::Parser) documentation. My first probably is probably not knowing what "\*STDIN" represents. I know STDIN, but I don't want to be manually piping something to the script; I want to work with strings I already have in the script.
Your wisdom is much appriciated.
#!/usr/bin/perl -w ## import modules use lib '/Users/squiddy/sandbox/lib/'; use Mail::POP3Client; use MIME::Parser; ## create a new MIME parser object my $parser = new MIME::Parser; $parser->output_under("/Users/squiddy/sandbox/mailtemp/"); $parser->output_to_core(1); ###### code removed for simplicity ######### ## get mail $pop = new Mail::POP3Client( USER => "squiddy", PASSWORD => "notmypw", HOST => "pop3.squiddy.com", USESSL => true ); ###### code removed for simplicity ######### ## loop through each item on the POP3 server for ($i = 1; $i <= $pop->Count(); $i++) { ## get the unique email UIDL (out of a returned string "N XXXXXXX" +) $mailnum = $pop->Uidl($i); @maildat = split(" ",$mailnum); $mailnum = $maildat[1]; # print "$mailnum\n"; ## if it doesn't already exist in the database if (exists $hash{$mailnum}) { # print "nothing here\n"; } else { ###### code removed for simplicity ######### ## get email body $emailmessage = $pop->HeadAndBody($i); ###### code removed for simplicity ######### ## output the MIME parts $entity = $parser->parse($emailmessage) or die "parse failed\n +"; } } ## close the connection $pop->close(); ###### code removed for simplicity #########
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MIME::Parser tries but fails to save files
by ig (Vicar) on May 29, 2011 at 02:09 UTC | |
|
Re: MIME::Parser tries but fails to save files
by ig (Vicar) on May 29, 2011 at 02:23 UTC |