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

IndexError from _header_value_parser.py #1408

Open
josch opened this issue Jun 9, 2019 · 1 comment
Open

IndexError from _header_value_parser.py #1408

josch opened this issue Jun 9, 2019 · 1 comment

Comments

@josch
Copy link
Contributor

josch commented Jun 9, 2019

This problem occurs with alot from git. Steps to reproduce:

Consider this email:

To: foo <foo@bar.com>, 
From: baz <baz@blub.de>
Message-ID: <spamtest@spamtest.com>
Subject: test
Date: Sun, 09 Apr 2017 21:24:04 +0200

foobar

md5sum is 88473fa33cf507f2924f6ecdbee32fd9

If I try opening the thread of that mail in alot I get:

DEBUG:ui:fire first command
DEBUG:ui:global command string: "search id:spamtest@spamtest.com"
DEBUG:__init__:mode:global got commandline "search id:spamtest@spamtest.com"
DEBUG:__init__:ARGS: ['search', 'id:spamtest@spamtest.com']
DEBUG:__init__:cmd parms {'sort': None, 'query': ['id:spamtest@spamtest.com']}
DEBUG:manager:Worker process 13358 spawned
DEBUG:manager:Worker process 13358 exited successfully
DEBUG:utils:unquoted header: |baz <baz@blub.de>|
DEBUG:utils:Content-Transfer-Encoding: "7bit"
DEBUG:utils:assuming Content-Transfer-Encoding: 7bit
DEBUG:walker:EMPTY PIPE
DEBUG:ui:Got key (['enter'], [10])
DEBUG:ui:cmdline: 'select'
DEBUG:ui:search command string: "select"
DEBUG:__init__:mode:search got commandline "select"
DEBUG:__init__:ARGS: ['select']
DEBUG:__init__:cmd parms {}
INFO:search:open thread view for thread:0000000000036cfe: test
DEBUG:utils:unquoted header: |baz <baz@blub.de>|
DEBUG:utils:unquoted header: |baz <baz@blub.de>|
ERROR:ui:Traceback (most recent call last):
  File "/home/josch/git/alot/alot/ui.py", line 711, in apply_command
    cmd.apply(self)
  File "/home/josch/git/alot/alot/commands/search.py", line 41, in apply
    sb = buffers.ThreadBuffer(ui, self.thread)
  File "/home/josch/git/alot/alot/buffers/thread.py", line 37, in __init__
    self.rebuild()
  File "/home/josch/git/alot/alot/buffers/thread.py", line 73, in rebuild
    self._tree = ThreadTree(self.thread)
  File "/home/josch/git/alot/alot/widgets/thread.py", line 352, in __init__
    accumulate(msg)
  File "/home/josch/git/alot/alot/widgets/thread.py", line 331, in accumulate
    self._message[mid] = MessageTree(msg, odd)
  File "/home/josch/git/alot/alot/widgets/thread.py", line 172, in __init__
    self._maintree = SimpleTree(self._assemble_structure())
  File "/home/josch/git/alot/alot/widgets/thread.py", line 199, in _assemble_structure
    mainstruct.append((self._get_headers(), None))
  File "/home/josch/git/alot/alot/widgets/thread.py", line 255, in _get_headers
    headers)
  File "/home/josch/git/alot/alot/widgets/thread.py", line 283, in construct_header_pile
    values = mail.get_all(key)
  File "/usr/lib/python3.7/email/message.py", line 510, in get_all
    values.append(self.policy.header_fetch_parse(k, v))
  File "/usr/lib/python3.7/email/policy.py", line 162, in header_fetch_parse
    return self.header_factory(name, value)
  File "/usr/lib/python3.7/email/headerregistry.py", line 589, in __call__
    return self[name](name, value)
  File "/usr/lib/python3.7/email/headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
  File "/usr/lib/python3.7/email/headerregistry.py", line 340, in parse
    kwds['parse_tree'] = address_list = cls.value_parser(value)
  File "/usr/lib/python3.7/email/headerregistry.py", line 331, in value_parser
    address_list, value = parser.get_address_list(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1930, in get_address_list
    token, value = get_address(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1907, in get_address
    token, value = get_group(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1863, in get_group
    token, value = get_display_name(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1689, in get_display_name
    token, value = get_phrase(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1364, in get_phrase
    token, value = get_word(value)
  File "/usr/lib/python3.7/email/_header_value_parser.py", line 1339, in get_word
    if value[0]=='"':
IndexError: string index out of range

The problem goes away when I remove the trailing space in the To field.

@pazz
Copy link
Owner

pazz commented Jun 10, 2019

This very much looks like a bug in the email lib.
Can you reproduce this directly on the email, i.e., create an email.Message from your string and call get_all('To')?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants