Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by ultranerds (Pilgrim)
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:

Hi,

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? :)

TIA!

Andy

Comment on MIME::Parser- get the filename + folder it was extracted to?
Download Code
Re: MIME::Parser- get the filename + folder it was extracted to?
by roboticus (Canon) on Dec 09, 2010 at 13:02 UTC

    ultranerds:

    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.

    ...roboticus

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

      Hi,

      Thanks for the reply.

      I ended up using

      $parser->output_dir($path);

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

      Cheers

      Andy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://876233]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-12-27 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls