This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vajrasky
Recipients barry, r.david.murray, vajrasky
Date 2013-12-12.06:21:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386829279.51.0.373470600297.issue19957@psf.upfronthosting.co.za>
In-reply-to
Content
In Lib/email/encoders.py:

def encode_7or8bit(msg):
    """Set the Content-Transfer-Encoding header to 7bit or 8bit."""
    orig = msg.get_payload(decode=True)
    if orig is None:
        # There's no payload.  For backwards compatibility we use 7bit
        msg['Content-Transfer-Encoding'] = '7bit'
        return
    # We play a trick to make this go fast.  If encoding/decode to ASCII
    # succeeds, we know the data must be 7bit, otherwise treat it as 8bit.
    try:
        if isinstance(orig, str):
            orig.encode('ascii')
        else:
            orig.decode('ascii')
    except UnicodeError:
        charset = msg.get_charset()


msg.get_payload(decode=True) always return bytes so there is no point of these lines:

        if isinstance(orig, str):
            orig.encode('ascii')
        else:
            orig.decode('ascii')

Attached the patch to refactor this function.
History
Date User Action Args
2013-12-12 06:21:19vajraskysetrecipients: + vajrasky, barry, r.david.murray
2013-12-12 06:21:19vajraskysetmessageid: <1386829279.51.0.373470600297.issue19957@psf.upfronthosting.co.za>
2013-12-12 06:21:19vajraskylinkissue19957 messages
2013-12-12 06:21:18vajraskycreate