Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

MIME::Parser- get the filename + folder it was extracted to?

by ultranerds (Friar)
on Dec 09, 2010 at 11:01 UTC ( #876233=perlquestion: print w/replies, xml ) Need Help??
ultranerds has asked for the wisdom of the Perl Monks concerning the following question:


I've managed to write a little function which will parse emails grabbed via Mail::POP3Client, and it works fine (it extracts the files to a folder, within a sub-folder - i.e msg-1291891283-19924-4.

The problems I have, is:

1) I need to get a list of these files, so I can rename them with a "prefix" them with yyyymmddHHMMSS_ 2) I need to rename stuff like “B%DClen%FCt %7E .Cey.pdf” into its "real" filename, i.e “BÜlenüt ~ .Ceylan. – Test.pdf”

The code is as follows:
sub process_mail { my $mesage_body = $_[0]; # Create a new MIME::Parser object my $parser = new MIME::Parser; # Tolerant mode $parser->ignore_errors(1); # Output to a file $parser->output_to_core(0); # Output to a per message folder $parser->output_under("/kunden/217787_60385/onexma/archiv/Clients/ +000000"); # Parsing the message my $entity = $parser->parse_data($_[0]); my $error = ($@ || $parser->last_error); if ($error) { print $error."<br>\n"; } else { print "Attachment extracted !<br>\n"; } # Delete the files containing the message content (we want only th +e attachment) chdir ("."); unlink $entity->{'ME_Parts'}[0]->{'ME_Bodyhandle'}->{'MB_Path'} || + warn ("Can't delete the message body file !"); }

I've had a look through the `man` for MIME::Parser, and can't see anything that would do this.

Any of you guys got any ideas/pointers? :)



Replies are listed 'Best First'.
Re: MIME::Parser- get the filename + folder it was extracted to?
by roboticus (Chancellor) on Dec 09, 2010 at 13:02 UTC


    I just did a quick scan of the MIME::Parser docs, and found (in the section "Specifying output destination") a reference to the filer method which you can use to set a new MIME::Parser::Filer object. Looking at that document leads me to believe that you can subclass it and make it put files where you want, rather than having to rename them. I've never done it, so I don't know how easy/complex that would be.


    When your only tool is a hammer, all problems look like your thumb.


      Thanks for the reply.

      I ended up using


      ..and then doing a readdir() on that folder. Working fine now :)



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://876233]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-05-29 10:21 GMT
Find Nodes?
    Voting Booth?