头脑风暴:将txt电子邮件解析为结构化对象(JSON等)

2024-04-26 13:56:48 发布

您现在位置:Python中文网/ 问答频道 /正文

对于我的论文项目,我将处理大量的电子邮件。 我需要提取所有的头字段,并通过管道将它们导入一个排序的数据结构,最好是像JSON这样的通用数据结构

现在,我一直在研究这个问题,并找到了很多半屁股工作的解决办法。 我不想你告诉我怎么做,只是把一些想法摆在桌面上

现在我的计划是使用python来解析头字段。 我选择python是因为它很好用,而且我也有过使用它的经验。此外,还有很多图书馆。 问题是python官方电子邮件处理不能很好地处理重复字段,这对我来说非常关键。特别是对于标题“Received:”,因为它允许跟踪跨多个邮件服务器的电子邮件传输

官方图书馆忽略了多个字段,只存储了第一个字段——”

有什么想法吗?你将如何处理这个问题


Tags: 项目json数据结构管道官方图书馆排序电子邮件
1条回答
网友
1楼 · 发布于 2024-04-26 13:56:48

这个答案可能对你有帮助:problem with email parsing with python and multiple Received records

The python doc for email.getitem() says:

Note that if the named field appears more than once in the message’s headers, exactly which of those field values will be returned is undefined. Use the get_all() method to get the values of all the extant named headers.

so, use e.get_all(i) instead of e[i] to get all values of the Received: header.

相关问题 更多 >