Menu

#4 Extract each email messages to individual file

open
nobody
None
5
2003-10-20
2003-10-20
Anonymous
No

Basically what I am after is a tool that will iterate
through a PST file and save all the email messages into
separate files as rfc822 / mime format preserving all the
body parts headers and attachments. We need to
export the messages to be able to import them into a
document management system.

Discussion

  • Tim Heaney

    Tim Heaney - 2004-01-09

    Logged In: YES
    user_id=827666

    Forgive me for speaking out of turn, I just stumbled in here
    looking for something to convert a .dbx file to mbox format,
    but...

    It seems to me you don't really need this. Once you have
    files in mbox format, you can use any number of methods to
    split them into individual messages. You can use formail
    (part of procmail), along with a little shell script

    #!/bin/sh

    #
    # createfile - Use this with formail to split a Unix mbox into
    # individual files named message.1, message.2, ...
    #
    # FILENO=1 formail -ds createfile < mboxfile
    #
    # Basically, formail is looking for the name of a program,
    so this is
    # a program which simply redirects its input to a file.
    #

    cat > message.$FILENO

    or Perl's Email::Folder module

    perl -MEmail::Folder -e
    '$f=Email::Folder->new(shift);while($m=$f->next_message){$n++;open
    F,"> message.$n" or die; print F $m->as_string}' mboxfile

    or Python's email and mailbox modules

    #!/usr/bin/python

    import email
    import mailbox

    num = 1
    for msg in mailbox.PortableUnixMailbox(open('mboxfile'),
    email.message_from_file):
    file = open('message.' + str(num), 'w')
    print >>file, msg
    num += 1

    or something similar in whatever your favorite scripting
    language is. Once you've got the data out of its proprietary
    format, the battle's already won.

     
  • Nobody/Anonymous

    Logged In: NO

    Se the manpage for csplit

    Roughly:

    csplit mboxfilename "/^From /" {*}

     

Log in to post a comment.