diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-03-08 08:39:01 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-03-08 08:39:01 +0000 |
commit | b4544cf47c7266e0029c2cd5aac02bc38db1c22d (patch) | |
tree | 9b32b6c71bd2383d6bee38ba4ef3f17ca6d90cae | |
parent | 583f5aa50d68f89093744f345ddea7d8147111d7 (diff) | |
download | portage-b4544cf47c7266e0029c2cd5aac02bc38db1c22d.tar.gz portage-b4544cf47c7266e0029c2cd5aac02bc38db1c22d.tar.bz2 portage-b4544cf47c7266e0029c2cd5aac02bc38db1c22d.zip |
Bug #291331 - Force ascii encoding in send_mail() in order to avoid
UnicodeEncodeError from smtplib.sendmail with python3.
svn path=/main/trunk/; revision=15759
-rw-r--r-- | pym/portage/mail.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/pym/portage/mail.py b/pym/portage/mail.py index 0cc250085..3836c187a 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -14,7 +14,7 @@ import time from portage import os from portage import _encodings -from portage import _unicode_encode +from portage import _unicode_decode, _unicode_encode from portage.localization import _ import portage @@ -135,7 +135,17 @@ def send_mail(mysettings, message): myconn = smtplib.SMTP(mymailhost, mymailport) if mymailuser != "" and mymailpasswd != "": myconn.login(mymailuser, mymailpasswd) - myconn.sendmail(myfrom, myrecipient, message.as_string()) + + message_str = message.as_string() + if sys.hexversion >= 0x3000000: + # Force ascii encoding in order to avoid UnicodeEncodeError + # from smtplib.sendmail with python3 (bug #291331). + message_str = _unicode_encode(message_str, + encoding='ascii', errors='backslashreplace') + message_str = _unicode_decode(message_str, + encoding='ascii', errors='replace') + + myconn.sendmail(myfrom, myrecipient, message_str) myconn.quit() except smtplib.SMTPException as e: raise portage.exception.PortageException(_("!!! An error occured while trying to send logmail:\n")+str(e)) |