Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email.quoprimime.body_encode can't handle characters that encodings.quopri_codec can #61697

Closed
rpatterson mannequin opened this issue Mar 20, 2013 · 5 comments
Closed
Labels
topic-email type-bug An unexpected behavior, bug, or error

Comments

@rpatterson
Copy link
Mannequin

rpatterson mannequin commented Mar 20, 2013

BPO 17495
Nosy @warsaw, @bitdancer
Superseder
  • bpo-16948: email.mime.text.MIMEText: QP encoding broken with charset!=ISO-8859-1
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-03-20.19:08:50.452>
    created_at = <Date 2013-03-20.18:15:36.510>
    labels = ['type-bug', 'expert-email']
    title = "email.quoprimime.body_encode can't handle characters that encodings.quopri_codec can"
    updated_at = <Date 2013-03-20.19:12:55.316>
    user = 'https://bugs.python.org/rpatterson'

    bugs.python.org fields:

    activity = <Date 2013-03-20.19:12:55.316>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-03-20.19:08:50.452>
    closer = 'rpatterson'
    components = ['email']
    creation = <Date 2013-03-20.18:15:36.510>
    creator = 'rpatterson'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 17495
    keywords = []
    message_count = 5.0
    messages = ['184772', '184774', '184777', '184778', '184779']
    nosy_count = 3.0
    nosy_names = ['barry', 'r.david.murray', 'rpatterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '16948'
    type = 'behavior'
    url = 'https://bugs.python.org/issue17495'
    versions = ['Python 3.3']

    @rpatterson
    Copy link
    Mannequin Author

    rpatterson mannequin commented Mar 20, 2013

    When using email.charset.Charset to encode MIME bodie as quoted-printable, some characters that are encodable with the quopri_codec cause a KeyError in email.quoprimime:

    Python 3.3.0 (default, Oct  7 2012, 14:43:21) 
    [GCC 4.6.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> text_encoded = b'mo \xe2\x82\xac'
    >>> text = text_encoded.decode('utf-8')
    >>> print(text)
    mo €
    >>> import codecs
    >>> codecs.getencoder('quopri_codec')(text_encoded)[0]
    b'mo=20=E2=82=AC'
    >>> from email import charset
    >>> c = charset.Charset('utf-8')
    >>> c.header_encoding = charset.QP
    >>> c.body_encoding = charset.QP
    >>> c.header_encode(text)
    '=?utf-8?q?mo_=E2=82=AC?='
    >>> c.body_encode(text)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.3/email/charset.py", line 395, in body_encode
        return email.quoprimime.body_encode(string)
      File "/usr/lib/python3.3/email/quoprimime.py", line 240, in body_encode
        if body_check(ord(c)):
      File "/usr/lib/python3.3/email/quoprimime.py", line 81, in body_check
        return chr(octet) != _QUOPRI_BODY_MAP[octet]
    KeyError: 8364

    @rpatterson rpatterson mannequin added topic-email type-bug An unexpected behavior, bug, or error labels Mar 20, 2013
    @rpatterson
    Copy link
    Mannequin Author

    rpatterson mannequin commented Mar 20, 2013

    What is the reason that email.quoprimime doesn't use codecs.getencoder('quopri_codec') to do the actual character encoding?

    @bitdancer
    Copy link
    Member

    There is a long history behind quoprime in the email package, and I don't know all of it. It is on my list of things to sort out (there is also potential duplication with the binascii module), but I haven't gotten to it yet.

    The issue you report, though is a duplicate of bpo-16948 and is already fixed in the repo.

    You checked off 2.7. Did you actually see a failure in 2.7? It shouldn't be broken there.

    @rpatterson
    Copy link
    Mannequin Author

    rpatterson mannequin commented Mar 20, 2013

    I thought I had tested it under 2.7, but I'm not entirely sure.

    @rpatterson rpatterson mannequin closed this as completed Mar 20, 2013
    @bitdancer
    Copy link
    Member

    OK, if you find it is a bug on 2.7 you can reopen.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant