diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-02-18 00:03:10 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-02-18 00:03:10 -0800 |
commit | e33e94307ba0bd2f3fff543c407eee812c4ea5c9 (patch) | |
tree | bb654da5987358ca6bc69d0fc4e4786b17c991fe | |
parent | ad4b1c9df3eb00382b03fbc9c24f2a3a8eab58f4 (diff) | |
download | portage-e33e94307ba0bd2f3fff543c407eee812c4ea5c9.tar.gz portage-e33e94307ba0bd2f3fff543c407eee812c4ea5c9.tar.bz2 portage-e33e94307ba0bd2f3fff543c407eee812c4ea5c9.zip |
mail: handle unicode in subject for python3
-rw-r--r-- | pym/portage/mail.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/pym/portage/mail.py b/pym/portage/mail.py index f87efe262..598c1f9b7 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -67,9 +67,19 @@ def create_message(sender, recipient, subject, body, attachments=None): mymessage.set_unixfrom(sender) mymessage["To"] = recipient mymessage["From"] = sender - # Use Header as a workaround so that long subject lines are wrapped - # correctly by <=python-2.6 (gentoo bug #263370, python issue #1974). - mymessage["Subject"] = Header(subject) + + if sys.hexversion >= 0x3000000: + # Avoid UnicodeEncodeError in python3 with non-ascii characters. + # File "/usr/lib/python3.1/email/header.py", line 189, in __init__ + # self.append(s, charset, errors) + # File "/usr/lib/python3.1/email/header.py", line 262, in append + # input_bytes = s.encode(input_charset, errors) + #UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128) + mymessage["Subject"] = subject + else: + # Use Header as a workaround so that long subject lines are wrapped + # correctly by <=python-2.6 (gentoo bug #263370, python issue #1974). + mymessage["Subject"] = Header(subject) mymessage["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S %z") return mymessage |