First challenge: It is suggested in the documentation for Mail::Internet that you use MIME::Entity for multipart support. Mail::Internet and Mail::Field are explicitly not going to help you in this context. You already use MIME::Head, so I'm going to assume you have MIME::Tools installed.

Second challenge: Test data would be really nice. But hey, I had to look up how to do it myself, so no points against you. I'm not even sure I'm doing it right myself. I generated a test email and attached it to the code in the __DATA__ chunk.

use warnings; use strict; use MIME::Parser; my $parser = MIME::Parser->new(); # The message and attachment are extracted to disk, so there will be a # couple of files in this directory. $parser->output_under('/tmp'); my $entity = $parser->parse(\*DATA); if ( $entity->is_multipart ) { # This message is multipart, so look at each part for my $part ( $entity->parts ) { my $head = $part->head; # We only care about attached content in this example. if ( my $filename = $head->recommended_filename ) { print "Attachment name: $filename\n"; } } } __DATA__ Content-Type: multipart/mixed; boundary="----------=_1228756284-7253-0 +" Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) From: me@myhost.com To: you@yourhost.com Subject: Hello, Nurse! This is a multi-part message in MIME format... ------------=_1228756284-7253-0 Content-Type: text/plain; name="short.txt" Content-Disposition: inline; filename="short.txt" Content-Transfer-Encoding: binary This is a short text file ------------=_1228756284-7253-0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: binary some literal text ------------=_1228756284-7253-0--

Hopefully you can fill in the remaining blanks for your app, or somebody else can show an even more streamlined way to do it. Have fun!


In reply to Re: filename of an attachment by webfiend
in thread filename of an attachment by Bass-Fighter

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.