diff roundup/mailer.py @ 4313:7a6c5c117879

Fix handling of non-ascii in realname in the nosy mailer... ...this used to mangle the email address making it unusable when replying. Thanks to intevation for funding the fix.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Sun, 27 Dec 2009 20:05:32 +0000
parents 630a20c51345
children 94ee533613ac
line wrap: on
line diff
--- a/roundup/mailer.py	Wed Dec 23 00:34:39 2009 +0000
+++ b/roundup/mailer.py	Sun Dec 27 20:05:32 2009 +0000
@@ -61,10 +61,15 @@
         charset = getattr(self.config, 'EMAIL_CHARSET', 'utf-8')
         tracker_name = unicode(self.config.TRACKER_NAME, 'utf-8')
         if not author:
-            author = formataddr((tracker_name, self.config.ADMIN_EMAIL))
+            author = (tracker_name, self.config.ADMIN_EMAIL)
+            name = author[0]
         else:
             name = unicode(author[0], 'utf-8')
-            author = formataddr((name, author[1]))
+        try:
+            name = name.encode('ascii')
+        except UnicodeError:
+            name = Header(name, charset).encode()
+        author = formataddr((name, author[1]))
 
         if multipart:
             message = MIMEMultipart()
@@ -77,10 +82,7 @@
         except UnicodeError:
             message['Subject'] = Header(subject, charset)
         message['To'] = ', '.join(to)
-        try:
-            message['From'] = author.encode('ascii')
-        except UnicodeError:
-            message['From'] = Header(author, charset)
+        message['From'] = author
         message['Date'] = formatdate(localtime=True)
 
         # add a Precedence header so autoresponders ignore us

Roundup Issue Tracker: http://roundup-tracker.org/