When I run the below code the attachments are not downloaded .
The OS is Windows 7 and Perl version is 5.16.3
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();