Index: email/Charset.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/Charset.py,v retrieving revision 1.13 diff -u -r1.13 Charset.py --- email/Charset.py 6 Mar 2003 05:16:29 -0000 1.13 +++ email/Charset.py 7 Feb 2004 00:32:17 -0000 @@ -1,6 +1,7 @@ # Copyright (C) 2001,2002 Python Software Foundation # Author: che@debian.org (Ben Gertzfield), barry@zope.com (Barry Warsaw) +import re from types import UnicodeType from email.Encoders import encode_7or8bit import email.base64MIME @@ -266,7 +267,11 @@ def convert(self, s): """Convert a string from the input_codec to the output_codec.""" if self.input_codec <> self.output_codec: - return unicode(s, self.input_codec).encode(self.output_codec) + # By replacing we may get unreadable characters. + # Should we make it chosable ? fail/replace (TK) + if not _isunicode(s): + s = unicode(s, self.input_codec, 'replace') + return s.encode(self.output_codec, 'replace') else: return s @@ -386,6 +391,8 @@ s = self.convert(s) # 7bit/8bit encodings return the string unchanged (module conversions) if self.body_encoding is BASE64: + # should be CRLF line separated (sendmail autoconversion) + s = re.sub('([^\r])\n', '\g<1>\r\n', s) return email.base64MIME.body_encode(s) elif self.body_encoding is QP: return email.quopriMIME.body_encode(s) Index: email/Encoders.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/Encoders.py,v retrieving revision 1.7 diff -u -r1.7 Encoders.py --- email/Encoders.py 1 Oct 2002 00:05:24 -0000 1.7 +++ email/Encoders.py 7 Feb 2004 00:32:17 -0000 @@ -84,7 +84,12 @@ try: orig.encode('ascii') except UnicodeError: - msg['Content-Transfer-Encoding'] = '8bit' + # 'iso-2022-??' is non-ascii but '7bit' + charset = msg.get_charset().get_output_charset().lower() + if charset.startswith('iso-2022-'): + msg['Content-Transfer-Encoding'] = '7bit' + else: + msg['Content-Transfer-Encoding'] = '8bit' else: msg['Content-Transfer-Encoding'] = '7bit'