Hey folks,

I've patched up my local mailer.py[1] to correctly encode
"From: " Headers.

The attached patch *works* but it's not pretty.

Someone who actually knows Python might want to encapsulate
my changes in a function.

n.b.: I am not subscribed to this ML, if you want notify me
of updates, please CC me.

So long,

i

[1] 
http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/mailer/mailer.py

--
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.ga...@brainsware.org
URL: http://brainsware.org/
GPG: 6880 4155 74BD FD7C B515  2EA5 4B1D 9E08 A097 C9AE

Index: mailer.py
===================================================================
--- mailer.py   (revision 1516)
+++ mailer.py   (working copy)
@@ -236,7 +236,15 @@
     except UnicodeError:
       from email.Header import Header
       subject = Header(subject, 'utf-8').encode()
-    hdrs = 'From: %s\n'    \
+    from_hdr = ''
+    words = self.from_addr.split()
+    for word in words:
+      try:
+        from_hdr += ' ' + word.encode('ascii')
+      except UnicodeError:
+        from email.Header import Header
+       from_hdr += ' ' + Header(word, 'utf-8').encode()
+    hdrs = 'From:%s\n'    \
            'To: %s\n'      \
            'Subject: %s\n' \
            'MIME-Version: 1.0\n' \
@@ -246,7 +254,7 @@
            'X-Svn-Commit-Author: %s\n' \
            'X-Svn-Commit-Revision: %d\n' \
            'X-Svn-Commit-Repository: %s\n' \
-           % (self.from_addr, ', '.join(self.to_addrs), subject,
+           % (from_hdr, ', '.join(self.to_addrs), subject,
               group, self.repos.author or 'no_author', self.repos.rev,
               os.path.basename(self.repos.repos_dir))
     if self.reply_to:

Reply via email to