inblosam has asked for the wisdom of the Perl Monks concerning the following question:
Here is my POP3Client script that right now returns the subject and from, and saves the whole email as a file.--Apple-Mail-16--694122637 Content-Transfer-Encoding: base64 Content-Type: application/pdf; x-unix-mode=0644; name="bus-schedule.pdf" Content-Disposition: inline; filename=some-file.pdf (then base64 code here) --Apple-Mail-18--693549197 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-mac-type=2A2A2A2A; x-unix-mode=0644; x-mac-creator=48647261; name="somefilename" Content-Disposition: attachment; filename=somefilename (then the file is here)
Can anyone advise? I need to be able to handle multiple files too, and pretty much any type of attachment.#!/usr/bin/perl -w use strict; use Mail::POP3Client; use MIME::Parser; my $pop = new Mail::POP3Client( USER => "email\@mydomain.com", PASSWORD => "mypassword", HOST => "mail.mydomain.com" ); my $i; for( $i = 111; $i <= $pop->Count(); $i++ ) { foreach( $pop->Head( $i ) ) { /^(From|Subject):\s+/i && print $_, "\n"; my $dir = '/some/folder/somewhere/attachments'; my $parser = new MIME::Parser; my $io = new IO::File; if ($io->open( "> $dir/raw-message.$i")) { $pop->HeadAndBodyToFile( $io, $i ); $io->close; print "Parsing $dir/raw-message.$i...\n"; $parser->parse( IO::File->new( "$dir/raw-message.$i") ); } } } $pop->Close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Saving attachments from email files
by dave0 (Friar) on May 02, 2005 at 17:26 UTC |