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 Cacadril
Recipients Cacadril, barry, r.david.murray
Date 2018-05-20.12:12:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526818338.13.0.682650639539.issue33476@psf.upfronthosting.co.za>
In-reply-to
Content
Unsure how to issue a "PR" (Problem Report?) with a test case.

Here is my best effort:

Create a file "email.eml" in the current directory, as attached.
(The contents were lifted from RFC2822 section A.1.3, but I deleted the ";" at the end of the "To" header. The file has CRLF line endings.)

Then run the following test program (It appears that I can only attach one file to this ).

$ cat test-bug.py
from email.policy import default
import email

with open('email.eml', 'rb') as f:
    msg = email.message_from_binary_file(f, policy=default)
    toheader = msg['To']
    for addr in toheader.addresses:
        print(addr)

#----------------------------------------------------
# Output without the fix:

$ python3.6.5 test-bug.py
Traceback (most recent call last):
  File "test-bug.py", line 6, in <module>
    toheader = msg['To']
  File "C:\Program Files\Python36\lib\email\message.py", line 391, in __getitem__
    return self.get(name)
  File "C:\Program Files\Python36\lib\email\message.py", line 471, in get
    return self.policy.header_fetch_parse(k, v)
  File "C:\Program Files\Python36\lib\email\policy.py", line 162, in header_fetch_parse
    return self.header_factory(name, value)
  File "C:\Program Files\Python36\lib\email\headerregistry.py", line 589, in __call__
    return self[name](name, value)
  File "C:\Program Files\Python36\lib\email\headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
  File "C:\Program Files\Python36\lib\email\headerregistry.py", line 340, in parse
    kwds['parse_tree'] = address_list = cls.value_parser(value)
  File "C:\Program Files\Python36\lib\email\headerregistry.py", line 331, in value_parser
    address_list, value = parser.get_address_list(value)
  File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1931, in get_address_list
    token, value = get_address(value)
  File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1908, in get_address
    token, value = get_group(value)
  File "C:\Program Files\Python36\lib\email\_header_value_parser.py", line 1879, in get_group
    if value[0] != ';':
IndexError: string index out of range

#-----------------------------------------------------
# Output with the fix:

$ test-bug.py
Chris Jones <c@a.test>
joe@where.test
John <jdoe@one.test>
History
Date User Action Args
2018-05-20 12:12:18Cacadrilsetrecipients: + Cacadril, barry, r.david.murray
2018-05-20 12:12:18Cacadrilsetmessageid: <1526818338.13.0.682650639539.issue33476@psf.upfronthosting.co.za>
2018-05-20 12:12:18Cacadrillinkissue33476 messages
2018-05-20 12:12:17Cacadrilcreate