I need help to have a script that allows to recover the attachment (.pdf or .xls) of the unread mail from INBOX, the attachments will be deposited in a folder 'X' of the local disk with UID of the mail like name. for example: in the mail box to browse, there are two new unread mails (mail1 and mail2) in mail1 i have attachment "pj1.pdf" and in mail2 i have attachment "pj2.pdf" (or .xls), the question is how to recover pj1.pdf and pj2.pdf(or .xls) from mail1 and mail2 in a local disk folder : / documents / X and renaming it to /documents/X/attachment1.pdf and /documents/X/attachmen2.pdf I use the following modules : Mail::IMAPClient and MIME::Parser;
use strict; use warnings; use Mail::IMAPClient; use Date::Format; use Date::Parse; use MIME::Parser; use IO::Socket::SSL; use File::Path; use Carp; use warnings; #Recuperer le nombre des messages dans INBOX my $nm=$imap->unseen_count("INBOX") ; # Select INBOX dossier $imap->select("INBOX"); #Recuperer la liste des messages non lu dans un objet liste @message my @messages = $imap->unseen; die "$0: search: $@" if defined $@; # parcourir les message INBOX non lu for(my $id = 1; $id <= $nm; $id++){ my $id = pop @messages; my $msg = $imap->message_string($id) or die "Could not message_string: $@\n"; # my $fh = $imap->getfh( $msg ); #my ($ parser) = new MIME::Parser; my $parser = MIME::Parser->new( ); #$parser->output_under($dossier_output); # Création des dossiers UID MAIL $parser->output_under($dossier_output, DirName=>"$id");; # toutes les PJ dans un même d`enter code here`ossier # $parser->output_dir("mailsPJ"); my $message = $parser->parse_data($msg) }; $imap->logout or die "Logout error: ", $imap->LastError, "\n";
In reply to Get only attachment Mail without .html and .txt by Red_Developper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |