如何将邮箱拆分为单个文件?

Ste*_*nko 6 java unix linux email bash

我想通过bash命令将我的收件箱拆分为单独的文件(每个消息一个文件),或者可以是Java中的简单程序.我该怎么做?

WBR,Thanx.

Igo*_*bin 9

只是用formail.formail是一个程序,可以处理邮箱,为邮箱中的每个邮件运行一些操作,单独的邮件等.

更多信息:http://www.manpagez.com/man/1/formail/

如果您只想将邮箱拆分为单独的文件,我会建议这样的解决方案:

$ cat $MAIL | formail -ds sh -c 'cat > msg.$FILENO'
Run Code Online (Sandbox Code Playgroud)

来自男人:

   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.
Run Code Online (Sandbox Code Playgroud)

  • `formail` 是我机器上 procmail 的一部分(`apt-get install procmail`)。 (3认同)
  • 对我来说,这不起作用;它只是构建了一个与 mbox 相同的“msg.000”文件。 (2认同)

小智 6

Git也可以做到这一点,例如

wget ftp://lists.gnu.org/bug-tar/2014-09
git mailsplit -o. 2014-09
Run Code Online (Sandbox Code Playgroud)


miv*_*ivk 5

如果你没有 formail,你也可以使用这个 Perl oneliner(从这里复制,刚刚在我需要拆分的 Thunderbird 收件箱上测试)

perl -pe 'open STDOUT, ">out".++$n if /^From /' < $IN > before_first
Run Code Online (Sandbox Code Playgroud)

或者,有 0 填充的数字:

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