如何使用 mailutils 迭代 eml 文件?

如何使用 mailutils 迭代 eml 文件?

如何.eml迭代文件目录?

nicholas@mordor:~$ 
nicholas@mordor:~$ mail -f foomail/foo.eml 
"/home/nicholas/foomail/foo.eml": 0 messages
nicholas@mordor:~$ 

然而,我希望看到一个可供选择的列表。

答案1

你不能,EML 格式是不是受支持的本地邮箱格式由 GNU Mailutils ...但是,显然 MBOX 格式是。

幸运的是从 EML 到 MBOX 的转换很容易,这正是您应该考虑的。

为了证明这一点,我用了这个样本 EML... 所以,

$ head *.eml
==> 1.eml <==
FCC: imap://[email protected]/Sent
X-Identity-Key: id1
X-Account-Key: account1
From: "[email protected]" <[email protected]>
Subject: test confirmation
To: [email protected], [email protected],
 [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected]
Message-ID: <[email protected]>
Date: Thu, 15 Aug 2019 14:54:37 +0900

==> 2.eml <==
FCC: imap://[email protected]/Sent
X-Identity-Key: id1
X-Account-Key: account1
From: "[email protected]" <[email protected]>
Subject: test confirmation
To: [email protected], [email protected],
 [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected]
Message-ID: <[email protected]>
Date: Thu, 15 Aug 2019 14:54:37 +0900

==> 3.eml <==
FCC: imap://[email protected]/Sent
X-Identity-Key: id1
X-Account-Key: account1
From: "[email protected]" <[email protected]>
Subject: test confirmation
To: [email protected], [email protected],
 [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected]
Message-ID: <[email protected]>
Date: Thu, 15 Aug 2019 14:54:37 +0900

...并尝试用mailutils不起作用):

$ mail -V
mail (GNU Mailutils) 3.16
Copyright (C) 2007-2023 Free Software Foundation, inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$
$ 
$ mail --file *.eml
mail: -f requires at most one command line argument
$ 
$ 
$ mail --file 1.eml
"/home/ubuntu/test/dir/1.eml": 0 messages

...现在让我们将这 3 条 EML 消息转换为一个 MBOX 文件:

$ for e in *.eml
  do
    date +"From - %a %b %d %H:%M:%S %Y" >> file.mbox
    cat "$e" >> file.mbox
    echo >> file.mbox
    done
$ 
$ 
$ ls -lh
total 20K
-rw-rw-r-- 1 ubuntu ubuntu 2.5K Nov 30 17:48 1.eml
-rw-rw-r-- 1 ubuntu ubuntu 2.5K Nov 30 17:48 2.eml
-rw-rw-r-- 1 ubuntu ubuntu 2.5K Nov 30 17:48 3.eml
-rw-rw-r-- 1 ubuntu ubuntu 7.6K Nov 30 17:49 file.mbox
$ 
$ 
$ head file.mbox 
From - Thu Nov 30 17:49:34 2023
FCC: imap://[email protected]/Sent
X-Identity-Key: id1
X-Account-Key: account1
From: "[email protected]" <[email protected]>
Subject: test confirmation
To: [email protected], [email protected],
 [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected]
Message-ID: <[email protected]>

...并尝试阅读:

$ mail --file file.mbox 
"/home/ubuntu/test/dir/file.mbox": 3 messages 3 new
>N   1 piro-test@clear-co Thu Nov 30 17:49  64/2549  test confirmation
 N   2 piro-test@clear-co Thu Nov 30 17:49  64/2549  test confirmation
 N   3 piro-test@clear-co Thu Nov 30 17:49  64/2549  test confirmation
? 
FCC: imap://[email protected]/Sent
X-Identity-Key: id1
X-Account-Key: account1
From: "[email protected]" <[email protected]>
Subject: test confirmation
To: [email protected], [email protected],
 [email protected], [email protected], [email protected],
 [email protected], [email protected], [email protected]
Message-ID: <[email protected]>
Date: Thu, 15 Aug 2019 14:54:37 +0900
X-Mozilla-Draft-Info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0;
 attachmentreminder=0; deliveryformat=4
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101
 Thunderbird/69.0
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------26A45336F6C6196BD8BBA2A2"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------26A45336F6C6196BD8BBA2A2
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
? q
Held 3 messages in /home/ubuntu/test/dir/file.mbox

...并且它有效。

相关内容