DST609 has asked for the wisdom of the Perl Monks concerning the following question:
use MIME::Parser; use MIME::Lite; use Email::Simple; use POSIX; $server = new Net::IMAP::Simple::SSL($AuthSrvr); $server->login($AuthUser,$AuthPass); my $parser = new MIME::Parser; my $outputdir="tmpMail/"; my $rsx = POSIX::strftime("%Y%m%d%H%M%S", localtime); $parser->output_dir($outputdir); $parser->output_prefix($rsx); my ($unseen, $recent, $num_messages) = $server->status($folder); $num_offset=$num_messages; $num_offset=2; # test a few if ($num_offset>$num_messages) { $num_offset=$num_messages; } for (my $i = 1; $i <= $num_offset; $i++) { my $entity = $parser->parse($server->getfh($i)); my $from = $entity->head->get('From'); my $subject = $entity->head->get('Subject'); my $timestamp = $entity->head->get('Date'); my $parts=0; for my $part ($entity->parts()) { if ($part->mime_type eq 'application/octet-stream' || $part->mime_ty +pe eq 'application/pdf' ) { $parts++; my $filename = $part->bodyhandle->path; if ($filename=~/^(.*)document_/) { move ($filename, $outputdir.$rsx.".pdf"); } } } $server->copy($i, 'dump'); $server->delete($i); } $server->quit();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mime::Parser - File Naming Convention
by Anonymous Monk on Apr 24, 2013 at 11:01 UTC | |
by DST609 (Novice) on Apr 24, 2013 at 12:37 UTC | |
by Anonymous Monk on Apr 24, 2013 at 13:37 UTC |