The only thing I'm trying to do is take files that have been zipped and emailed to me, and save them in a folder on my server.
I've got the following hodgepodge of copy/pasted/glued code, but haven't been able to figure out how to finish the part where the attachment is saved.
Is there an easier way to do this? A search of the CPAN modules didn't pan out.
use Net::IMAP::Simple; use Email::Simple; use Email::MIME::Attachment::Stripper; my $username = "user"; my $password= "pass"; my $server = Net::IMAP::Simple->new( 'server' ); $server->login( $username,$password) || warn "Bad login!\n"; my $nmessages = $server->select( 'inbox' ); $number_of_messages = $nmessages; foreach my $msg ( 1 .. $number_of_messages ) { if ($server->seen( $msg )){ # print "This message has been read before...\n"; } else { print "New!"; my $email = Email::Simple->new( join '', @{$server->get( $ +msg )} ); my $stripper = Email::MIME::Attachment::Stripper->new($msg +); my Email::MIME $msg = $stripper->message; #my attachments = ..; This returns a list of all the attachments we f +ound in the message, as a hash of { filename, content_type, payload } +. my @attachments = $stripper->attachments; # print $email->header('Subject'), "\n"; # $data = $email->body, "\n"; # print $data; # print "\n"; } } wend; $server->quit(); exit;

In reply to Save Email Attachment to File by ecuguru

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.