Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

One-off mime splitter

by Allan (Initiate)
on Aug 18, 2001 at 20:18 UTC ( #105924=perlquestion: print w/replies, xml ) Need Help??

Allan has asked for the wisdom of the Perl Monks concerning the following question:

I recently had the misfortune of accidently directing MS Outlook Express to download *delete* my Imap mail. Well I sought an answer to getting it back on Google, and I managed to select all of it and "forward" it to myself, saving it as one giant mime (or quasi-Mime) file.But it is not am mbox file anymore, but a huge multipart-mixed file, with hints like:
"X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200"

I am looking for some perl to split these things up back into normal mbox format.

Yes, it would be a fun exercise in Perl using Mime::Tools, but I really don't have the time to write this for one file. (Nor do I hope to do this ever again)

Anyone already write something like this? PS: Tried to coax Pine to read it.. NG

Replies are listed 'Best First'.
Re: One-off mime splitter
by guillaume (Pilgrim) on Aug 18, 2001 at 21:07 UTC
    You don't give much details, but I think this (from the Mime::tools documentation) could be of some help:
    Here's some pretty basic code for parsing a MIME message, and outputting its decoded components to a given directory: use MIME::Parser; ### Create parser, and set some parsing options: my $parser = new MIME::Parser; $parser->output_under("$ENV{HOME}/mimemail"); ### Parse input: $entity = $parser->parse(\*STDIN) or die "parse failed\n"; ### Take a look at the top-level entity (and any parts it has): $entity->dump_skeleton;
    You should use MIME::Tools. If it's because you didn't want to install it, a quick
    perl -MCPAN -e "install MIME::Tools"

    will do the job for you.

    And remember, even for a one-time task you are better off reusing existing code. Some may say that doing otherwise is a form of "False Impatience" :-)

    Guillaume
      $entity would be the single email with lots of attachments - each one is an individual email (possibly with attachments)- phew!

      So... I think you want to add something like this:
      foreach my $email ($entity->parts()) { # $email is now a MIME::Entity # I.e. one of the original emails that # was mistakenly combined into one. # either print the email, or capture it with # one of the "as_string" methods and use OLE # to stuff it back into Outlook. $email->print(\*STDOUT) }
      This is all from memory - I wrote a mail filter last week to do some virus scanning. But might help.

      Error: Keyboard not attached. Press F1 to continue.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-07-01 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (102 votes). Check out past polls.

    Notices?