pankaj_it09 has asked for the wisdom of the Perl Monks concerning the following question:
use Net::IMAP::Client; use Email::MIME; use Email::MIME::Attachment::Stripper ; use Data::Dumper; my $imap = Net::IMAP::Client->new( server => 'imap.gmail.com', user => 'casetest@gmail.com', pass => 'go123', ssl => 1, # (use SSL? default no) # ssl_verify_peer => 1, # (use ca to verify se +rver, default yes) # ssl_ca_file => '/etc/ssl/certs/certa.pm', # (CA file used for ve +rify server) or # ssl_ca_path => '/etc/ssl/certs/', # (CA path used for SS +L) port => 993 # (but defaults are sane +) ) or die "Could not connect to IMAP server"; # everything's useless if you can't login $imap->login or die('Login failed: ' . $imap->last_error); # select folder $imap->select('INBOX'); # fetch all message ids (as array reference) my $messages = $imap->search('ALL'); foreach $msg (@$messages) { my $data = $imap->get_rfc822_body($msg); my $parsed = Email::MIME->new($data); #print "Parsed content :\n". Dumper( $parsed) . "\n"; my $parts = $parsed->parts; print "Number of email parts : $parts\n"; my @parts = $parsed->parts; # Give the Email MIME content to Attachment::Stripper for extracti +on my $stripper; if ($parts > 1) { $stripper = Email::MIME::Attachment::Stripper->new($parts[1]); } else { next; } # The extraction method itself my @attachments = $stripper->attachments; # Save the attachments on the local disk foreach my $att ( @attachments ) { my $file = $att->{filename}; open my $fh, '>', $file or die $!; print $fh $att->{payload}; close $fh; chmod 0644, $file; } } # Close the IMAP connection $imap->logout();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to use Email::MIME::Attachment::Stripper to download email attachments?
by marto (Cardinal) on May 06, 2014 at 13:03 UTC | |
by pankaj_it09 (Scribe) on May 06, 2014 at 13:10 UTC | |
by marto (Cardinal) on May 06, 2014 at 13:18 UTC | |
|
Re: How to use Email::MIME::Attachment::Stripper to download email attachments?
by moritz (Cardinal) on May 06, 2014 at 12:58 UTC | |
by pankaj_it09 (Scribe) on May 06, 2014 at 13:35 UTC | |
by pankaj_it09 (Scribe) on May 06, 2014 at 13:08 UTC | |
|
Re: How to use Email::MIME::Attachment::Stripper to download email attachments?
by pankaj_it09 (Scribe) on May 06, 2014 at 13:53 UTC |