我对使用imaplib从我的邮箱中获取主题的脚本有困难。python email subject r n
这里,是我的脚本:
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”,如果我得到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必须与此写作 – holdenweb
我非常确定它必须像这样发送。这可能是一场意外,甚至在发送时都没有注意到。你的Python是正确的。 – JosiahDaniels
这看起来像标题折叠。我会认为电子邮件解析库会为你处理这个问题。我没有为你解决头痛的问题。 – Max