Gentlemen, please consider the following ipython session:
In [98]: m = email.message_from_file(f) In [99]: print m["subject"] =?utf-8?b?W291aS5jb20uYnJdIENhcnTDo28gZGUgY3LDqWRpdG8gdGVyw6EgbGVn?= =?utf-8?b?aXNsYcOnw6NvIGVzcGVjw61maWNh?= It gives me the raw subject header value. Now of course I just wanted the header in unicode. So I have to do: In [100]: from email.header import decode_header In [101]: decode_header(m["subject"]) Out[101]: [('[oui.com.br] Cart\xc3\xa3o de cr\xc3\xa9dito ter\xc3\xa1 legisla\xc3\xa7\xc3\xa3o espec\xc3\xadfica', 'utf-8')] In [102]: print decode_header(m["subject"])[0][0] [oui.com.br] Cartão de crédito terá legislação específica My questions are: 1) Why does not it currently return the *decoded* header? 2) Would it break too many apps if we changed it? 2.1) If it would, can we add a function such as message.getheader("subject") for this? 2.1.1) Would you like me to propose a patch with the obvious implementation? Sometimes, for things more or less like this, I just feel like *subclassing* Message. But I can't. The MIME parser is wired to create Messages. I don't think I can tell it to create a MyMessageSubclass. This also happens with the convenience function email.message_from_file(f). It creates a Message. I *think* I could make it into a class method of Message, then I would be able to call MyMessage.from_file(). Is this idea -- making things more object-oriented -- interesting for you? For starters, isn't it high time Message became a new-style class by inheriting from object? -- Nando Florestan =============== [skype] nandoflorestan [phone] + 55 (11) 3675-3038 [mobile] + 55 (11) 9820-5451 [internet] http://oui.com.br/ [À Capela] http://acapela.com.br/ [location] São Paulo - SP - Brasil _______________________________________________ Email-SIG mailing list Email-SIG@python.org Your options: http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com