Update of /cvsroot/mailman/mailman/Mailman/Handlers
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7488

Modified Files:
      Tag: Release_2_1-maint
        Decorate.py 
Log Message:
[ 872068 ] Decorate.py patch (by tkikuchi)
  Use unicode concatnation in header+message+footer



Index: Decorate.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Handlers/Decorate.py,v
retrieving revision 2.21.2.3
retrieving revision 2.21.2.4
diff -u -d -r2.21.2.3 -r2.21.2.4
--- Decorate.py 1 Dec 2003 14:21:08 -0000       2.21.2.3
+++ Decorate.py 18 Sep 2004 08:40:29 -0000      2.21.2.4
@@ -53,7 +53,12 @@
             # BAW: Hmm, should we allow this?
             d['user_password'] = mlist.getMemberPassword(member)
             d['user_language'] = mlist.getMemberLanguage(member)
-            d['user_name'] = mlist.getMemberName(member) or _('not available')
+            username = mlist.getMemberName(member)
+            if username:
+                username = username.encode(Utils.GetCharSet(d['user_language']))
+            else:
+                username = member
+            d['user_name'] = username
             d['user_optionsurl'] = mlist.GetOptionsURL(member)
         except Errors.NotAMemberError:
             pass
@@ -83,18 +88,36 @@
     # BAW: If the charsets don't match, should we add the header and footer by
     # MIME multipart chroming the message?
     wrap = True
-    if not msg.is_multipart() and msgtype == 'text/plain' and \
-           msg.get('content-transfer-encoding', '').lower() <> 'base64' and \
-           (lcset == 'us-ascii' or mcset == lcset):
-        oldpayload = msg.get_payload()
-        frontsep = endsep = ''
-        if header and not header.endswith('\n'):
-            frontsep = '\n'
-        if footer and not oldpayload.endswith('\n'):
-            endsep = '\n'
-        payload = header + frontsep + oldpayload + endsep + footer
-        msg.set_payload(payload)
-        wrap = False
+    if not msg.is_multipart() and msgtype == 'text/plain':
+        # TK: Try to keep the message plain by converting the header/
+        # footer/oldpayload into unicode and encode with mcset/lcset.
+        # Try to decode qp/base64 also.
+        uheader = unicode(header, lcset)
+        ufooter = unicode(footer, lcset)
+        try:
+            oldpayload = unicode(msg.get_payload(decode=1), mcset)
+            frontsep = endsep = u''
+            if header and not header.endswith('\n'):
+                frontsep = u'\n'
+            if footer and not oldpayload.endswith('\n'):
+                endsep = u'\n'
+            payload = uheader + frontsep + oldpayload + endsep + ufooter
+            try:
+                # first, try encode with list charset
+                payload = payload.encode(lcset)
+                newcset = lcset
+            except UnicodeError:
+                if lcset != mcset:
+                    # if fail, encode with message charset (if different)
+                    payload = payload.encode(mcset)
+                    newcset = mcset
+                    # if this fails, fallback to outer try and wrap=true
+            del msg['content-transfer-encoding']
+            del msg['content-type']
+            msg.set_payload(payload, newcset)
+            wrap = False
+        except (LookupError, UnicodeError):
+            pass
     elif msg.get_type() == 'multipart/mixed':
         # The next easiest thing to do is just prepend the header and append
         # the footer as additional subparts

_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to