1 |
Author: zmedico |
2 |
Date: 2009-11-11 06:38:32 +0000 (Wed, 11 Nov 2009) |
3 |
New Revision: 14806 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/mail.py |
7 |
Log: |
8 |
Bug #292528 - Specify UTF-8 in the MIMEText constructor arguments, in order |
9 |
to avoid conversiont to ascii and subsequent UnicodeEncodeError when sending |
10 |
mail. The idea comes from here: http://bugs.python.org/issue4403#msg76425. |
11 |
|
12 |
|
13 |
Modified: main/trunk/pym/portage/mail.py |
14 |
=================================================================== |
15 |
--- main/trunk/pym/portage/mail.py 2009-11-09 20:51:20 UTC (rev 14805) |
16 |
+++ main/trunk/pym/portage/mail.py 2009-11-11 06:38:32 UTC (rev 14806) |
17 |
@@ -3,7 +3,7 @@ |
18 |
# Distributed under the terms of the GNU General Public License v2 |
19 |
# $Id$ |
20 |
|
21 |
-from email.mime.text import MIMEText as TextMessage |
22 |
+from email.mime.text import MIMEText |
23 |
from email.mime.multipart import MIMEMultipart as MultipartMessage |
24 |
from email.mime.base import MIMEBase as BaseMessage |
25 |
from email.header import Header |
26 |
@@ -21,6 +21,9 @@ |
27 |
if sys.hexversion >= 0x3000000: |
28 |
basestring = str |
29 |
|
30 |
+def TextMessage(_text): |
31 |
+ return MIMEText(_text, _charset="UTF-8") |
32 |
+ |
33 |
def create_message(sender, recipient, subject, body, attachments=None): |
34 |
|
35 |
if sys.hexversion < 0x3000000: |
36 |
@@ -127,9 +130,7 @@ |
37 |
myconn = smtplib.SMTP(mymailhost, mymailport) |
38 |
if mymailuser != "" and mymailpasswd != "": |
39 |
myconn.login(mymailuser, mymailpasswd) |
40 |
- msg = _unicode_encode(message.as_string(), |
41 |
- encoding=_encodings['content'], errors='backslashreplace') |
42 |
- myconn.sendmail(myfrom, myrecipient, msg) |
43 |
+ myconn.sendmail(myfrom, myrecipient, message) |
44 |
myconn.quit() |
45 |
except smtplib.SMTPException as e: |
46 |
raise portage.exception.PortageException(_("!!! An error occured while trying to send logmail:\n")+str(e)) |