如何按时间顺序对 mbox 文件重新排序?
我有一个使用进化创建的单个线轴 mbox 文件,其中包含我希望打印的一系列电子邮件。 我的问题是电子邮件没有按时间顺序放入 mbox 文件中。 我想知道使用 bash、perl 或 python 从头到尾对文件进行排序的最佳方法。 对于发给我的文件,我想按已收到的方式订购;对于我发送的文件,我想按已发送的方式订购。 使用 maildir 文件或类似文件可能会更容易吗?
电子邮件目前的格式如下:
From [email protected] Fri Aug 12 09:34:09 2005
Message-ID: <[email protected]>
Date: Fri, 12 Aug 2005 09:34:09 +0900
From: me <[email protected]>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: someone <[email protected]>
Subject: Re: (no subject)
References: <[email protected]>
In-Reply-To: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Status: RO
X-Status:
X-Keywords:
X-UID: 371
X-Evolution-Source: imap://[email protected]/
X-Evolution: 00000002-0010
Hey
the actual content of the email
someone wrote:
> lines of quotedtext
我想知道是否有一种方法可以使用此信息轻松地重新组织文件,也许可以使用 perl 等。
I have a single spool mbox file that was created with evolution, containing a selection of emails that I wish to print. My problem is that the emails are not placed into the mbox file chronologically. I would like to know the best way to place order the files from first to last using bash, perl or python. I would like to oder by received for files addressed to me, and sent for files sent by me. Would it perhaps be easier to use maildir files or such?
The emails currently exist in the format:
From [email protected] Fri Aug 12 09:34:09 2005
Message-ID: <[email protected]>
Date: Fri, 12 Aug 2005 09:34:09 +0900
From: me <[email protected]>
User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: someone <[email protected]>
Subject: Re: (no subject)
References: <[email protected]>
In-Reply-To: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Status: RO
X-Status:
X-Keywords:
X-UID: 371
X-Evolution-Source: imap://[email protected]/
X-Evolution: 00000002-0010
Hey
the actual content of the email
someone wrote:
> lines of quotedtext
I am wondering if there is a way to use this information to easily reorganize the file, perhaps with perl or such.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 python 中你可以这样做:
This is how you could do it in python:
如果使用 Thunderbird 的 ImportExportTools 插件将邮件消息导入 mbox,Python 解决方案将无法工作。
有一个错误:消息应在格式中以“from”行为前缀:
但 ImportExportTools 以这样的“from”行为前缀:
因此存在两个错误:
GMT 的“年时间”
信息以及时区名称
由于Python的mailbox.py/UnixMailbox已经硬编码了正则表达式来匹配'from'行,所以一些消息无法解析。
我把错误信息写给了作者,但是有很多错误导入的信息:(。
Python solution wont work if mail messages was imported into mbox using Thunderbird's ImportExportTools addon.
There are a bug: messages shall prefix with 'from' line in format:
but ImportExportTools prefix with such 'from' line:
So there are two errors:
'year time'
info along with time zone name
Since Python's mailbox.py/UnixMailbox has hardcoded regexp for 'from' line matching, some of messages can't parsed.
I wrote the error message to the author, but there are many mistakenly imported messages :(.
当加载邮箱时可以对内存中的邮件重新排序,重写 mbox 有什么意义? 您想在哪一个时间订购? 收到日期? 发送日期? 无论如何,所有用于使用 mbox 的 Ruby/Python/Perl 模块都可以做到这一点。
What's the point in rewriting the mbox whereas you can reorder the mails in memory when loading up the mailbox? Which time is the one you want to order on? Receive date? Sent date? Anyway, all the Ruby/Python/Perl modules for playing with mboxes can do that.