in reply to filename of an attachment
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: filename of an attachment
by Bass-Fighter (Beadle) on Dec 18, 2008 at 08:34 UTC |