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.header.decode_header can not decode string with quotation #72309

Closed
sijianliang mannequin opened this issue Sep 13, 2016 · 3 comments
Closed

email.header.decode_header can not decode string with quotation #72309

sijianliang mannequin opened this issue Sep 13, 2016 · 3 comments
Labels
topic-email type-bug An unexpected behavior, bug, or error

Comments

@sijianliang
Copy link
Mannequin

sijianliang mannequin commented Sep 13, 2016

BPO 28122
Nosy @warsaw, @bitdancer
Files
  • demo.py
  • 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 2016-09-13.18:42:23.468>
    created_at = <Date 2016-09-13.08:49:33.812>
    labels = ['type-bug', 'expert-email']
    title = 'email.header.decode_header can not decode string with quotation'
    updated_at = <Date 2016-09-13.18:42:23.466>
    user = 'https://bugs.python.org/sijianliang'

    bugs.python.org fields:

    activity = <Date 2016-09-13.18:42:23.466>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-13.18:42:23.468>
    closer = 'r.david.murray'
    components = ['email']
    creation = <Date 2016-09-13.08:49:33.812>
    creator = 'sijian liang'
    dependencies = []
    files = ['44624']
    hgrepos = []
    issue_num = 28122
    keywords = []
    message_count = 3.0
    messages = ['276214', '276236', '276320']
    nosy_count = 4.0
    nosy_names = ['barry', 'r.david.murray', 'era', 'sijian liang']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28122'
    versions = ['Python 2.7']

    @sijianliang sijianliang mannequin added topic-email type-bug An unexpected behavior, bug, or error labels Sep 13, 2016
    @sijianliang
    Copy link
    Mannequin Author

    sijianliang mannequin commented Sep 13, 2016

    #!/usr/bin/python
    #-*- coding:utf-8 -*-
    import email
    # from email.parser import Parser
    def decode_email_header(header, sep=''):
    	l = []
    	for s, c in header:
    		if c:
    			l.append(s.decode(c))
    		else:
    			l.append(s)
    	return sep.join(l)
    s = email.Header.decode_header('"=?gb18030?B?bWFpbGZvcnRlc3R0?=" <2070776562@qq.com>')
    print decode_email_header(s)
    s = email.Header.decode_header('=?gb18030?B?bWFpbGZvcnRlc3R0?= <2070776562@qq.com>')
    print decode_email_header(s)

    # see output:
    # "=?gb18030?B?bWFpbGZvcnRlc3R0?=" <2070776562@qq.com>
    # mailfortestt<2070776562@qq.com>

    @era
    Copy link
    Mannequin

    era mannequin commented Sep 13, 2016

    The double quotes around the "human readable" part of the email address are not allowed. Python is handling this correctly.

    @bitdancer
    Copy link
    Member

    Note, however, that python3 will compensate for this bug in the input, and register a defect for it:

    >>> import email
    >>> import email.policy
    >>> msg = email.message_from_string('To: "=?gb18030?B?bWFpbGZvcnRlc3R0?=" <2070776562@qq.com>\n\ntest body', policy=email.policy.default)
    >>> print(msg)
    To: "=?gb18030?B?bWFpbGZvcnRlc3R0?=" <2070776562@qq.com>
    
    test body
    >>> msg['To']
    'mailfortestt <2070776562@qq.com>'
    >>> msg['To'].defects
    (InvalidHeaderDefect('encoded word inside quoted string',),)

    @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