How to split mailbox into single file per message?

2020-03-03 06:02发布

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.

3条回答
等我变得足够好
2楼-- · 2020-03-03 06:41

Git (git mailsplit) can do this as well. For example,

wget ftp://lists.gnu.org/bug-tar/2014-09
git mailsplit -o. 2014-09
查看更多
我想做一个坏孩纸
3楼-- · 2020-03-03 06:43

If you don't have formail, you can also use this Perl oneliner (copied from here, and just tested on a Thunderbird Inbox I needed to split)

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

or, to have 0-padded numbers:

perl -pe 'open STDOUT, sprintf(">m%05d.mbx", ++$n) if /^From /' < $IN > before-first
查看更多
Fickle 薄情
4楼-- · 2020-03-03 06:51

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.
查看更多
登录 后发表回答