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

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.