This code saves email messages and attachments using MIME::Parse. The text body of the message is saved as a string +number like **msg-6108-1.txt**

How do I find out what this file is going to be named? I'd like to prefix the file attachment name with this name so I can match the message to the attachments when I process the folder contents on the server using cron at a later time.

this is currently saving files like this:

msg-6108-1.txt
fileattachment.pdf

I'd like to save something like this:

msg-6108-1.txt
msg-6108-1-fileattachment.pdf

#!/usr/bin/perl use Net::IMAP::Simple::SSL; use MIME::Parser; print "Content-type: text/html\n\n"; $server = new Net::IMAP::Simple::SSL('xxx'); $server->login('xxx','xxx'); my $newm=0; $newm = $server->select('INBOX'); if ($newm==0) { $server->quit(); print "No New Messages."; exit; } my $outputdir = "./temp"; my $parser = new MIME::Parser; $parser->output_dir($outputdir); for (my $i = 1; $i <= $newm; $i++) { my $entity = $parser->parse($server->getfh($i)); my $from = $entity->head->get('From'); my $subject = $entity->head->get('Subject'); my $timestamp = $entity->head->get('Date'); print "#$i $from / $subject / $timestamp<br />"; for my $part ($entity->parts()) { print " / ".$part->mime_type; if ( $part->mime_type eq 'application/octet-stream' || $part-> +mime_type eq 'application/pdf' ) { my $filename = $part->bodyhandle->path; print " / $filename"; } print "<br />"; } $server->copy($i,'dump'); $server->delete($i); } $server->quit();

In reply to MIME::Parser Customize Attachment Naming Convention by DST609

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.