【发布时间】:2016-11-08 23:08:51
【问题描述】:
我在使用 imaplib 从邮箱中获取主题的脚本时遇到问题。
这是我的脚本:
for mail in response[0].split():
typ, response = imap.fetch(mail, '(RFC822)')
for response_part in response:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
for header in [ 'subject']:
print msg["subject"]
但我得到了这个输出:
[astreinte] [2015.06.09 07:36:04] blurp : TIMESTAMP ALERT
Disaster is PROBLEM
我的问题是“TIMESTAMP ALERT”之后的 EndOfLine,如果我得到 msg.items() 我可以查看:
('Subject', '[astreinte] [2015.06.09 07:36:04] ankdo2ga22 : DOFUS TIMESTAMP ALERT\r\n Disaster is PROBLEM')
所以,我不明白为什么存在 \r\n ?它是否存在于元数据中。但是zabbix发送消息时没有添加。 我用的是office365。
非常感谢您的帮助。
【问题讨论】:
-
您的意思是“虽然我有一条以主题结尾的消息,但发送消息时不会出现行结尾”?不知道 zabbix 和 Office 365 与书面有什么关系
-
我很确定它一定是这样发送的。这可能是一个意外,甚至在发送时都没有注意到。你的蟒蛇是正确的。
-
这看起来像页眉折叠。我原以为电子邮件解析库会为您处理这个问题。我没有想到的解决方案。