Guest User

Untitled

a guest
Jun 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.99 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Mail::POP3Client;
  5. use MIME::Parser;
  6.  
  7. my $pop = new Mail::POP3Client(
  8.                  USER     => "*****",
  9.                  PASSWORD => "*****",
  10.                  HOST     => "*****",
  11.                  USESSL   => "true",
  12.                  PORT     => "995",
  13. );
  14.  
  15. ## for HeadAndBodyToFile() to use
  16. my $fh = new IO::Handle();
  17.  
  18. ## Initialize stuff for MIME::Parser;
  19. my $outputdir = "./mimemail";
  20. my $parser = new MIME::Parser;
  21. $parser->output_dir($outputdir);
  22.  
  23.  
  24. my $i;
  25. ## process all messages in pop3 inbox
  26. for ($i = 1; $i <= $pop->Count(); $i++) {
  27.    open (MAILOUT, ">pop3.msg$i");
  28.    $fh->fdopen( fileno( MAILOUT ), "w" );
  29.    ## write current msg to file
  30.    $pop->HeadAndBodyToFile( $fh, $i );
  31.    close MAILOUT;
  32.    ## MIME::Parser handles only one msg at-a-time
  33.    open (MAILIN, "<pop3.msg$i");
  34.    ## flush all attachments this msg to ./mimemail dir using internal filename
  35.    my $entity = $parser->read(\*MAILIN);
  36.    close MAILIN;
  37. }
Add Comment
Please, Sign In to add comment