[Zope-Checkins] SVN: Zope/trunk/src/Products/MailHost/MailHost.py Be a little more tolerant of encoded headers when no charset is passed or inferrable.

Alec Mitchell alecpm at gmail.com
Fri Aug 14 00:54:53 EDT 2009


Log message for revision 102758:
  Be a little more tolerant of encoded headers when no charset is passed or inferrable.
  

Changed:
  U   Zope/trunk/src/Products/MailHost/MailHost.py

-=-
Modified: Zope/trunk/src/Products/MailHost/MailHost.py
===================================================================
--- Zope/trunk/src/Products/MailHost/MailHost.py	2009-08-14 03:55:27 UTC (rev 102757)
+++ Zope/trunk/src/Products/MailHost/MailHost.py	2009-08-14 04:54:53 UTC (rev 102758)
@@ -434,7 +434,9 @@
     if subject:
         # remove any existing header otherwise we get two
         del mo['Subject']
-        mo['Subject'] = Header(subject, charset)
+        # Perhaps we should ignore errors here and pass 8bit strings
+        # on encoding errors
+        mo['Subject'] = Header(subject, charset, errors='replace')
     elif not mo.get('Subject'):
         mo['Subject'] = '[No Subject]'
 
@@ -491,9 +493,9 @@
     try:
         name.decode('us-ascii')
     except UnicodeDecodeError:
-        # Encoded strings need an extra space
-        # XXX: should we be this tolerant of encoding errors here?
-        charset = Charset(charset)
-        name = charset.header_encode(name)
-    header.append(formataddr((name, addr)))
+        if charset:
+            charset = Charset(charset)
+            name = charset.header_encode(name)
+    # We again replace rather than raise an error or pass an 8bit string
+    header.append(formataddr((name, addr)), errors='replace')
     return header



More information about the Zope-Checkins mailing list