Index: Decorate.py =================================================================== RCS file: /cvsroot/mailman/mailman/Mailman/Handlers/Decorate.py,v retrieving revision 2.21.2.2 diff -u -r2.21.2.2 Decorate.py --- Decorate.py 7 Jan 2003 14:18:39 -0000 2.21.2.2 +++ Decorate.py 20 Feb 2003 11:30:49 -0000 @@ -77,18 +77,35 @@ # BAW: If the charsets don't match, should we add the header and footer by # MIME multipart chroming the message? wrap = 1 - 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 = 0 + 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 by list charset + payload = payload.encode(lcset) + newcset = lcset + except UnicodeError: + # Then messeage charset. If this fails, goto outer except. + payload = payload.encode(mcset) + newcset = mcset + del msg['content-transfer-encoding'] + del msg['content-type'] + msg.set_payload(payload, newcset) + wrap = 0 + except (UnicodeError, LookupError): + # What else errors are expected? They should be added. + 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