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.utils.getaddresses does not handle Header objects #71700

Closed
frispete mannequin opened this issue Jul 14, 2016 · 6 comments
Closed

email.utils.getaddresses does not handle Header objects #71700

frispete mannequin opened this issue Jul 14, 2016 · 6 comments
Labels
3.10 only security fixes 3.11 only security fixes topic-email type-bug An unexpected behavior, bug, or error

Comments

@frispete
Copy link
Mannequin

frispete mannequin commented Jul 14, 2016

BPO 27513
Nosy @warsaw, @bitdancer, @ambv, @ZackerySpytz, @miss-islington, @tirkarthi, @websurfer5
PRs
  • bpo-27513: email.utils.getaddresses() now handles Header objects #13797
  • [3.10] bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) #27242
  • [3.9] bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) #27245
  • Files
  • iso-8859-1-encoded-from-header.mail: test mail
  • decode_from_header.py: test program, that demonstrates the problem
  • 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 2021-07-19.16:55:54.871>
    created_at = <Date 2016-07-14.10:50:10.937>
    labels = ['type-bug', 'expert-email', '3.10', '3.11']
    title = 'email.utils.getaddresses does not handle Header objects'
    updated_at = <Date 2021-07-19.17:28:59.779>
    user = 'https://bugs.python.org/frispete'

    bugs.python.org fields:

    activity = <Date 2021-07-19.17:28:59.779>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-19.16:55:54.871>
    closer = 'lukasz.langa'
    components = ['email']
    creation = <Date 2016-07-14.10:50:10.937>
    creator = 'frispete'
    dependencies = []
    files = ['43714', '43715']
    hgrepos = []
    issue_num = 27513
    keywords = ['patch']
    message_count = 6.0
    messages = ['270399', '270401', '270425', '397812', '397815', '397820']
    nosy_count = 8.0
    nosy_names = ['barry', 'frispete', 'r.david.murray', 'lukasz.langa', 'ZackerySpytz', 'miss-islington', 'xtreak', 'Jeffrey.Kintscher']
    pr_nums = ['13797', '27242', '27245']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27513'
    versions = ['Python 3.10', 'Python 3.11']

    @frispete
    Copy link
    Mannequin Author

    frispete mannequin commented Jul 14, 2016

    An unfortunate combination of get_all and getaddresses results in a Traceback:

    Traceback (most recent call last):
      File "misc/decode_from_header.py", line 17, in <module>
        print('From: %s' % email.utils.getaddresses(val))
      File "/usr/lib64/python3.4/email/utils.py", line 112, in getaddresses
        all = COMMASPACE.join(fieldvalues)
    TypeError: sequence item 0: expected str instance, Header found

    Here's the relevant part of it:
    Content-type: text/html;charset=iso-8859-1
    From: Itaú Uniclass. <comunicado.com.br@atendimento.gotdns.ch>

    Obviously, the From header is iso-8859-1 encoded as well, and violates RFC 2822 as such. But making it crash in the usual combination of

        val = msg.get('from')
        email.utils.getaddresses([val])

    isn't the real McCoy either..

    @frispete frispete mannequin added type-crash A hard crash of the interpreter, possibly with a core dump topic-email labels Jul 14, 2016
    @frispete
    Copy link
    Mannequin Author

    frispete mannequin commented Jul 14, 2016

    message.get cannot decode the header correctly, and returns a Header instance instead, which makes email.utils.getaddresses stumble upon...

    A much better behavior for getaddresses in this case would be returning the perfectly valid address, and ignoring the invalid dtext part.

    @bitdancer
    Copy link
    Member

    This appears to be something that was overlooked when btyes support was added in 3.2. getaddresses should indeed be able to handle a Header object if handed one.

    @bitdancer bitdancer changed the title email.utils.getaddresses raises exception from erroneous message get_all input email.utils.getaddresses does not handle Header objects Jul 14, 2016
    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 11, 2018
    @ZackerySpytz ZackerySpytz mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Jun 4, 2019
    @ambv
    Copy link
    Contributor

    ambv commented Jul 19, 2021

    New changeset 89f4c34 by Zackery Spytz in branch 'main':
    bpo-27513: email.utils.getaddresses() now handles Header objects (bpo-13797)
    89f4c34

    @ambv
    Copy link
    Contributor

    ambv commented Jul 19, 2021

    New changeset 8c43bf1 by Miss Islington (bot) in branch '3.10':
    bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (GH-27242)
    8c43bf1

    @ambv ambv added 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes labels Jul 19, 2021
    @ambv ambv closed this as completed Jul 19, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Jul 19, 2021

    New changeset 9ee12cf by Miss Islington (bot) in branch '3.9':
    bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (bpo-27245)
    9ee12cf

    @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
    3.10 only security fixes 3.11 only security fixes topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants