This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Alex Corcoles
Recipients Alex Corcoles, barry, r.david.murray, xtreak
Date 2018-10-10.18:21:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
To clarify (and maybe help someone which might come across), you mean:

In [1]: message_text = """To:
   ...: Subject: ** ACKNOWLEDGEMENT Host Alert: is DOWN
   ...:  **
   ...: User-Agent: Heirloom mailx 12.5 7/5/10
   ...: MIME-Version: 1.0
   ...: Content-Type: text/plain; charset=us-ascii
   ...: Content-Transfer-Encoding: 7bit
   ...: ***** Nagios *****
   ...: """
In [2]: import email
In [4]: message = email.message_from_string(message_text)
In [5]: message.get('Subject')
Out[5]: '** ACKNOWLEDGEMENT Host Alert: is DOWN\n **'

In [7]: from email import policy
In [8]: message = email.message_from_string(message_text, policy=policy.HTTP)
In [9]: message.get('Subject')
Out[9]: '** ACKNOWLEDGEMENT Host Alert: is DOWN **'

Yeah, there's a bundled policy that does what I need, but I think it's not very intuitive.

I get that the stdlib is deliberately low level in these parts, and it's more of building block to create higher level libraries on top of that, but still I feel that getting an email's subject in a friendly fashion should be easy and intuitive in the stdlib, or the stdlib's docs should point out clearly to go and look for a higher level library because email is hard.

OTOH, working with mail sucks and should be discouraged, so if you want to close this definitely I won't complain.
Date User Action Args
2018-10-10 18:21:25Alex Corcolessetrecipients: + Alex Corcoles, barry, r.david.murray, xtreak
2018-10-10 18:21:25Alex Corcolessetmessageid: <>
2018-10-10 18:21:25Alex Corcoleslinkissue34954 messages
2018-10-10 18:21:25Alex Corcolescreate