How to split a mailbox into one file per message?

I would like to split my mailbox into separate files (one file per message) with the bash command or it can be a simple Java program. How can i do this?

WBR, Thanx.

+5
source share
3 answers

Just use it formail. formailis a program that can process a mailbox, run some actions for each message in the mailbox, individual messages, etc.

Additional information: http://www.manpagez.com/man/1/formail/

If you want to split the mailbox into separate files, I would suggest this solution:

$ cat $MAIL | formail -ds sh -c 'cat > msg.$FILENO'

From a person:

   FILENO
        While splitting, formail  assigns  the  message  number  currently
        being  output  to  this  variable.   By presetting FILENO, you can
        change the initial message number being used and the width of  the
        zero-padded  output.   If  FILENO is unset it will default to 000.
        If FILENO is non-empty and does not contain a number, FILENO  gen-
        eration is disabled.
+7
source

Git ,

wget ftp://lists.gnu.org/bug-tar/2014-09
git mailsplit -o. 2014-09
+4

If you don't have formail, you can also use this Perl oneliner (copied from here and just tested in Inbox, I need Thunderbird to break)

perl -pe 'open STDOUT, ">out".++$n if /^From /' < $IN > before_first

or to have 0-filled numbers:

perl -pe 'open STDOUT, sprintf(">m%05d.mbx", ++$n) if /^From /' < $IN > before-first
+3
source

All Articles