aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortkikuchi <>2004-09-18 08:40:29 +0000
committertkikuchi <>2004-09-18 08:40:29 +0000
commite47f4472576cc7b84dcd07e50f8b080e376f24cf (patch)
tree7e6522a96230be43cd0629dff0ff294b55f0b0be
parentaca1c26fafc64c786185c1c05cf7653c3f59e1bd (diff)
downloadmailman2-e47f4472576cc7b84dcd07e50f8b080e376f24cf.tar.gz
mailman2-e47f4472576cc7b84dcd07e50f8b080e376f24cf.tar.xz
mailman2-e47f4472576cc7b84dcd07e50f8b080e376f24cf.zip
[ 872068 ] Decorate.py patch (by tkikuchi)
Use unicode concatnation in header+message+footer
-rw-r--r--Mailman/Handlers/Decorate.py49
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