Skip to content

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

Closed

Description

@frispete
mannequin
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']

    Activity

    1. frispete commented on Jul 14, 2016

      frispetemannequin
      MannequinAuthor

      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..

    2. added
      type-crash
      on Jul 14, 2016
    3. frispete commented on Jul 14, 2016

      frispetemannequin
      MannequinAuthor

      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.

    4. bitdancer commented on Jul 14, 2016

      @bitdancer
      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.

    5. changed the title [-]email.utils.getaddresses raises exception from erroneous message get_all input[/-] [+]email.utils.getaddresses does not handle Header objects[/+] on Jul 14, 2016
    6. added
      type-bug
      and removed
      type-crash
      on Jul 11, 2018
    7. added
      3.7 (EOL)
      3.8 (EOL)
      on Jun 4, 2019
    8. ambv commented on Jul 19, 2021

      @ambv
      Contributor

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

    9. ambv commented on Jul 19, 2021

      @ambv
      Contributor

      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

    10. added
      3.10 (EOL)
      3.11
      and removed
      3.7 (EOL)
      3.8 (EOL)
      on Jul 19, 2021
    11. ambv commented on Jul 19, 2021

      @ambv
      Contributor

      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

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)3.11topic-emailtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions