diff options
-rw-r--r-- | Mailman/Handlers/Decorate.py | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/Mailman/Handlers/Decorate.py b/Mailman/Handlers/Decorate.py index 4aa5500a..b9932a27 100644 --- a/Mailman/Handlers/Decorate.py +++ b/Mailman/Handlers/Decorate.py @@ -53,7 +53,12 @@ def process(mlist, msg, msgdata): # 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 @@ def process(mlist, msg, msgdata): # 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 |