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 uckelman
Recipients barry, r.david.murray, uckelman
Date 2017-02-01.13:53:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Test case:

  import email
  import email.policy
  txt = '''From:
  To: (Recipient list suppressed)
  Date: Thu, 22 Aug 2013 04:13:02 +0000
  Subject: ADSF-1082
  msg = email.message_from_string(txt)
  msg = email.message_from_string(txt, policy=email.policy.default)

The second msg.get() throws an IndexError:

  Traceback (most recent call last):
    File "", line 16, in <module>
      print(msg.get('to'))    # throws IndexError
    File "/usr/lib64/python3.5/email/", line 472, in get
      return self.policy.header_fetch_parse(k, v)
    File "/usr/lib64/python3.5/email/", line 153, in header_fetch_parse
      return self.header_factory(name, ''.join(value.splitlines()))
    File "/usr/lib64/python3.5/email/", line 586, in __call__
      return self[name](name, value)
    File "/usr/lib64/python3.5/email/", line 197, in __new__
      cls.parse(value, kwds)
    File "/usr/lib64/python3.5/email/", line 337, in parse
      kwds['parse_tree'] = address_list = cls.value_parser(value)
    File "/usr/lib64/python3.5/email/", line 328, in value_parser
      address_list, value = parser.get_address_list(value)
    File "/usr/lib64/python3.5/email/", line 2336, in get_address_list
      token, value = get_address(value)
    File "/usr/lib64/python3.5/email/", line 2313, in get_address
      token, value = get_group(value)
    File "/usr/lib64/python3.5/email/", line 2269, in get_group
      token, value = get_display_name(value)
    File "/usr/lib64/python3.5/email/", line 2095, in get_display_name
      token, value = get_phrase(value)
    File "/usr/lib64/python3.5/email/", line 1770, in get_phrase
      token, value = get_word(value)
    File "/usr/lib64/python3.5/email/", line 1745, in get_word
      if value[0]=='"':
  IndexError: string index out of range

The docs say that email.policy.default has raise_on_defect set to False, hence parse errors ought to be reported via EmailMessage.defects, not by throwing an exception.
Date User Action Args
2017-02-01 13:53:21uckelmansetrecipients: + uckelman, barry, r.david.murray
2017-02-01 13:53:21uckelmansetmessageid: <>
2017-02-01 13:53:21uckelmanlinkissue29412 messages
2017-02-01 13:53:21uckelmancreate