Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split mailbox into single file per message?

I'd like to split my inbox into separate files (one file per one message) by bash command, or may be simple program in Java. How can I do it?

WBR, Thanx.

like image 733
Stepan Yakovenko Avatar asked Jul 01 '12 12:07

Stepan Yakovenko


People also ask

What is splitting a Unix MBOX mail file into individual messages?

When one wants to split MBOX into individual messages, it is supposed to mean having to save each email message in EML file format. EML format stores each message in a single file. So, you require the help of MBOX to EML conversion utility for this task. Download, install and run the application on your Windows system.


1 Answers

Just use formail. formail is a program that can process mailbox, run some actions for each message in the mailbox, separate messages and so on.

More info: http://www.manpagez.com/man/1/formail/

If you want just split a mailbox to separate files, I would suggest such solution:

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

From man:

   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.
like image 111
Igor Chubin Avatar answered Sep 23 '22 16:09

Igor Chubin