i have a trouble with a script to get the subject from my mailbox using imaplib.
Here, is my script:
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"]
But i get this Output:
[astreinte] [2015.06.09 07:36:04] blurp : TIMESTAMP ALERT
Disaster is PROBLEM
My problem is the EndOfLine after "TIMESTAMP ALERT", if i get msg.items() i can view that:
('Subject', '[astreinte] [2015.06.09 07:36:04] ankdo2ga22 : DOFUS TIMESTAMP ALERT\r\n Disaster is PROBLEM')
So, i don't understand why the \r\n is present ? Is it present in the metadata. But not added when zabbix send the message. I use office365.
Thanks a lot for help.
Shameless plug: Try using my library: https://pypi.python.org/pypi/O365
If you are using Office 365 it should make your life much more simple.
In answering you question of why is the \r\n present, it is because Office365 is based on windows. Windows uses \r\n for it's line breaks for legacy reasons.