Revision: 8175
          http://svn.sourceforge.net/mailman/?rev=8175&view=rev
Author:   tkikuchi
Date:     2007-03-22 23:37:02 -0700 (Thu, 22 Mar 2007)

Log Message:
-----------
Fix of Decorate.py for the case (input_charset != output_charset) and fail
to encode by output_charset (language == 'ja' and cset == 'euc-jp').
Add a test code for list language is 'ja' and message is 'iso-2022-jp';
('Japanese' in header/footer, 'French' in message).

Modified Paths:
--------------
    trunk/mailman/Mailman/Handlers/Decorate.py
    trunk/mailman/Mailman/testing/test_handlers.py

Modified: trunk/mailman/Mailman/Handlers/Decorate.py
===================================================================
--- trunk/mailman/Mailman/Handlers/Decorate.py  2007-03-22 04:29:31 UTC (rev 
8174)
+++ trunk/mailman/Mailman/Handlers/Decorate.py  2007-03-23 06:37:02 UTC (rev 
8175)
@@ -99,15 +99,16 @@
             # charset, then utf-8.  It's okay if some of these are duplicates.
             for cset in (lcset, mcset, 'utf-8'):
                 try:
-                    payload = payload.encode(cset)
-                except UnicodeError:
-                    pass
-                else:
+                    pld = payload.encode(cset)
                     del msg['content-transfer-encoding']
                     del msg['content-type']
-                    msg.set_payload(payload, cset)
+                    msg.set_payload(pld, cset)
                     wrap = False
                     break
+                # 'except' should be here because set_payload() may fail for
+                # 'euc-jp' which re-encode to 'iso-2022-jp'. :(
+                except UnicodeError:
+                    pass
         except (LookupError, UnicodeError):
             pass
     elif msg.get_content_type() == 'multipart/mixed':

Modified: trunk/mailman/Mailman/testing/test_handlers.py
===================================================================
--- trunk/mailman/Mailman/testing/test_handlers.py      2007-03-22 04:29:31 UTC 
(rev 8174)
+++ trunk/mailman/Mailman/testing/test_handlers.py      2007-03-23 06:37:02 UTC 
(rev 8175)
@@ -883,7 +883,24 @@
                self._mlist, None, {'personalize': 1,
                                    'recips': [1, 2, 3]})
 
+    def test_no_multipart_mixed_charset(self):
+        mlist = self._mlist
+        mlist.preferred_language = 'ja'
+        mlist.msg_header = '%(description)s header'
+        mlist.msg_footer = '%(description)s footer'
+        mlist.description = u'\u65e5\u672c\u8a9e'
+        msg = Message.Message()
+        msg.set_payload('Fran\xe7aise', 'iso-8859-1')
+        Decorate.process(self._mlist, msg, {})
+        self.assertEqual(msg.as_string(unixfrom=0), """\
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: base64
 
+5pel5pys6KqeIGhlYWRlcgpGcmFuw6dhaXNlCuaXpeacrOiqniBmb290ZXI=
+""")
+
+
 
 class TestFileRecips(TestBase):
     def test_short_circuit(self):


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to