Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: filename of an attachment

by webfiend (Vicar)
on Dec 08, 2008 at 17:56 UTC ( #729007=note: print w/replies, xml ) Need Help??

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: To: 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
    this is much better than it was, so thank you webfiend. it almost works already. I must only look at this:
    $parser->output_under('/tmp'); my $entity = $parser->parse(\*DATA);
    I want to do it with a standard in. this because the program will be set on a server where the mail will sent to in the form of a Bcc. and another thing: your testmail is fine;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://729007]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2019-07-17 12:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found