diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-09 23:16:50 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-09 23:16:50 +0000 |
commit | 7608f97f12887f079a210a9abd02079e85bbe180 (patch) | |
tree | 6d665b806f1a7b3e920772221778261fb5bca4e2 | |
parent | 26e20aad7f60e344a3826138af8934c2174c6b4c (diff) | |
download | portage-7608f97f12887f079a210a9abd02079e85bbe180.tar.gz portage-7608f97f12887f079a210a9abd02079e85bbe180.tar.bz2 portage-7608f97f12887f079a210a9abd02079e85bbe180.zip |
Make everything safe for unicode (this should fix the elog modules that
send mail).
svn path=/main/trunk/; revision=13965
-rw-r--r-- | pym/portage/mail.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/pym/portage/mail.py b/pym/portage/mail.py index 5f1cc11a6..9779fac86 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -10,6 +10,17 @@ from email.MIMEBase import MIMEBase as BaseMessage from email.header import Header def create_message(sender, recipient, subject, body, attachments=None): + + if sys.hexversion < 0x3000000: + if isinstance(sender, unicode): + sender = sender.encode('utf_8', 'replace') + if isinstance(recipient, unicode): + recipient = recipient.encode('utf_8', 'replace') + if isinstance(subject, unicode): + subject = subject.encode('utf_8', 'replace') + if isinstance(body, unicode): + body = body.encode('utf_8', 'replace') + if attachments == None: mymessage = TextMessage(body) else: @@ -19,6 +30,8 @@ def create_message(sender, recipient, subject, body, attachments=None): if isinstance(x, BaseMessage): mymessage.attach(x) elif isinstance(x, basestring): + if sys.hexversion < 0x3000000 and isinstance(x, unicode): + x = x.encode('utf_8', 'replace') mymessage.attach(TextMessage(x)) else: raise portage.exception.PortageException("Can't handle type of attachment: %s" % type(x)) @@ -66,7 +79,21 @@ def send_mail(mysettings, message): myrecipient = mysettings["PORTAGE_ELOG_MAILURI"] myfrom = message.get("From") - + + if sys.hexversion < 0x3000000: + if isinstance(myrecipient, unicode): + myrecipient = myrecipient.encode('utf_8', 'replace') + if isinstance(mymailhost, unicode): + mymailhost = mymailhost.encode('utf_8', 'replace') + if isinstance(mymailport, unicode): + mymailport = mymailport.encode('utf_8', 'replace') + if isinstance(myfrom, unicode): + myfrom = myfrom.encode('utf_8', 'replace') + if isinstance(mymailuser, unicode): + mymailuser = mymailuser.encode('utf_8', 'replace') + if isinstance(mymailpasswd, unicode): + mymailpasswd = mymailpasswd.encode('utf_8', 'replace') + # user wants to use a sendmail binary instead of smtp if mymailhost[0] == os.sep and os.path.exists(mymailhost): fd = os.popen(mymailhost+" -f "+myfrom+" "+myrecipient, "w") |