Alex Corcoles <a...@pdp7.net> added the comment:

To clarify (and maybe help someone which might come across), you mean:

In [1]: message_text = """To: a...@corcoles.net
   ...: Subject: ** ACKNOWLEDGEMENT Host Alert: archerc7.bcn.int.pdp7.net 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: archerc7.bcn.int.pdp7.net 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: archerc7.bcn.int.pdp7.net 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.

----------
status: closed -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34954>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to