Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This script should do what you want. I looked at several modules trying to find one that does everything, but lately I find that most mail related modules do one or two very specific things well, but for anything but the simplest tasks end up using more than one to get the job done. In this case, Mail::POP3Client is a good POP3 access tool but MIME::Parser is hard to beat for saving attachments to disk:
#!/usr/local/bin/perl use strict; use warnings; use Mail::POP3Client; use MIME::Parser; my $pop = new Mail::POP3Client( USER => "user", PASSWORD => "password", HOST => "pop3.server" ); ## for HeadAndBodyToFile() to use my $fh = new IO::Handle(); ## Initialize stuff for MIME::Parser; my $outputdir = "./mimemail"; my $parser = new MIME::Parser; $parser->output_dir($outputdir); my $i; ## process all messages in pop3 inbox for ($i = 1; $i <= $pop->Count(); $i++) { open (MAILOUT, ">pop3.msg$i"); $fh->fdopen( fileno( MAILOUT ), "w" ); ## write current msg to file $pop->HeadAndBodyToFile( $fh, $i ); close MAILOUT; ## MIME::Parser handles only one msg at-a-time open (MAILIN, "<pop3.msg$i"); ## flush all attachments this msg to ./mimemail dir using internal +filename my $entity = $parser->read(\*MAILIN); close MAILIN; }
BTW, this was done hastily and could use more error testing, could probably be done more simply/elegantly, but I leave that for the poster.

Does anyone know how to read the messages directly to MIME::Parser without having to write the intermediate files first? I've encountered this dilemma recently trying to combine other unrelated mail modules.

--Jim


In reply to Re: Retrieving email and decoding attachments by jlongino
in thread Retrieving email and decoding attachments by jtapper

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found