C.F. Scheidecker Antunes wrote:
Hello all,
Hello,
Although I have done this same thing in PHP and Java before I have an urgent need to accomplish it in Perl due to specific requirements.
What I need is to write an application that: - Access a pop3 remote account - Iterate through the list of messages on the server - Download the attachments and save them localy on the machine - delete all downloaded messages
requirements:
- only attachments ending with .txt and .zip should be saved, the rest must be ignored.
OK, so I need help and directions on this.
What are the Perl CPAN modules to achieve it? Browsing CPAN I found: Net-POP3_auth-0.03.tar.gz and Mail-POP3Client-2.16.tar.gz.
However I do not know how can I handle the mime attachment requirement. Read the MIME body, save the attachment with its original name and only .txt and .zip files.
Sorry for the delay I've had this message waiting for a reply and finally am getting to it :)
Ok, use Mail::POP3Client to connect and iterate through each message then delete them
Mail::Internet is excellent for parsing email, althgough it doesn't do MIME. I;ve used MIME::Parser for parsing the mime stuff.
Its a bit complicated, as all MIME can get due to evil MIME makers.
I'd start there, I also am aware of a module coming out that has a single fucntion that breaks the email up into a hash, incuding a key that is a hash of the attachements.
If you like I can send you more info about it, but its not due out for a few more weeks give or take. It uses Mail::Internet and Mime::Parser and does all the crazy stuff for you :)
So that you could do something like:
#connect # get messages into an array of array refs for(@messages) { my $email = emailhash($_); my %att = %{ $email->{ATTACHED}; # for easier reading :) for(keys %att) { my %part = %{ $att{$_} }; # again for easier reading :) if($part{ctype} eq 'text/plain' && $part{filename} =~ m/\.txt$) { # save file } } } #delete messages
After that, I will need to unzip all the .zip files saved to check inside and do some processing.
Archive::Zip is what I've used to do this :)
I appreacite any help, any links to articles that teach how to do it in perl.
Thanks in advance,
HTH :)
Lee.M - JupiterHost.Net
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>