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();

In reply to How to use Email::MIME::Attachment::Stripper to download email attachments? by pankaj_it09

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.