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

Index out of range in get of message.EmailMessage.get() #75626

Closed
Michala mannequin opened this issue Sep 13, 2017 · 5 comments
Closed

Index out of range in get of message.EmailMessage.get() #75626

Michala mannequin opened this issue Sep 13, 2017 · 5 comments
Labels
topic-email type-bug An unexpected behavior, bug, or error

Comments

@Michala
Copy link
Mannequin

Michala mannequin commented Sep 13, 2017

BPO 31445
Nosy @warsaw, @bitdancer, @maxking, @radar383
PRs
  • bpo-31445: Added two lines to avoid  #6825
  • bpo-31445: String index out of range in get_group(), email/_header_value_parser.py #6828
  • Files
  • _header_value_parser.py
  • 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 2019-07-10.01:08:34.137>
    created_at = <Date 2017-09-13.09:53:20.968>
    labels = ['type-bug', 'expert-email']
    title = 'Index out of range in get of message.EmailMessage.get()'
    updated_at = <Date 2019-07-10.01:08:34.133>
    user = 'https://bugs.python.org/Michala'

    bugs.python.org fields:

    activity = <Date 2019-07-10.01:08:34.133>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-07-10.01:08:34.137>
    closer = 'r.david.murray'
    components = ['email']
    creation = <Date 2017-09-13.09:53:20.968>
    creator = 'Michala'
    dependencies = []
    files = ['47197']
    hgrepos = []
    issue_num = 31445
    keywords = ['patch']
    message_count = 5.0
    messages = ['302043', '303948', '316565', '345629', '347589']
    nosy_count = 5.0
    nosy_names = ['barry', 'r.david.murray', 'maxking', 'Michala', 'radar383']
    pr_nums = ['6825', '6828']
    priority = 'normal'
    resolution = 'works for me'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31445'
    versions = ['Python 3.6']

    @Michala
    Copy link
    Mannequin Author

    Michala mannequin commented Sep 13, 2017

    This error occured when the email field "From" was demanded:

    File "/home/user/processing/Test/process_email.py", line 84, in __init__
    self.field_from_full = msg.get("From")
    File "/usr/local/lib/python3.6/email/message.py", line 471, in get
    return self.policy.header_fetch_parse(k, v)
    File "/usr/local/lib/python3.6/email/policy.py", line 162, in header_fetch_parse
    return self.header_factory(name, value)
    File "/usr/local/lib/python3.6/email/headerregistry.py", line 586, in __call__
    return self[name](name, value)
    File "/usr/local/lib/python3.6/email/headerregistry.py", line 197, in __new__
    cls.parse(value, kwds)
    File "/usr/local/lib/python3.6/email/headerregistry.py", line 337, in parse
    kwds['parse_tree'] = address_list = cls.value_parser(value)
    File "/usr/local/lib/python3.6/email/headerregistry.py", line 328, in value_parser
    address_list, value = parser.get_address_list(value)
    File "/usr/local/lib/python3.6/email/_header_value_parser.py", line 2336, in get_address_list
    token, value = get_address(value)
    File "/usr/local/lib/python3.6/email/_header_value_parser.py", line 2313, in get_address
    token, value = get_group(value)
    File "/usr/local/lib/python3.6/email/_header_value_parser.py", line 2284, in get_group
    if value[0] != ';':
    IndexError: string index out of range

    I used EmailPolicy, so the message object was instance of EmailMessage.
    Header field "From" had following form:
    "From: Bonifac Karaka : bonikar@gmail.com"

    @Michala Michala mannequin added topic-email type-bug An unexpected behavior, bug, or error labels Sep 13, 2017
    @Michala
    Copy link
    Mannequin Author

    Michala mannequin commented Oct 9, 2017

    I added 2 lines into the file "email/_header_value_parser.py"
    into the function "get_mailbox_list(value)" before return value:

        if not value:
            value = ';'
        return mailbox_list, value

    It is in attachments.

    @radar383
    Copy link
    Mannequin

    radar383 mannequin commented May 14, 2018

    Submitted pull request:
    fix-issue-31455: Changed by adding two lines in the module "email/_header_value_parser.py" into the function "get_mailbox_list(value)" before return mailbox_list, value to avoid IndexError.

    @maxking
    Copy link
    Contributor

    maxking commented Jun 14, 2019

    I can't reproduce this issue on the latest master branch. This seems to be fixed as a part of a different PR I suppose.

        >>> import email
        >>> msg = email.message_from_string("From: Bonifac Karaka : bonikar@gmail.com")
        >>> msg['From']
        'Bonifac Karaka : bonikar@gmail.com'

    This is very similar to bpo-32178, which also is now fixed.

    @david, @barry, I think we can close this issue.

    @bitdancer
    Copy link
    Member

    Note that the reporter indicated that the message was an instance of EmailMessage (the new API). You'd need to use policy-default to get that using message_from_string. But yes, this was fixed in another issue.

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

    No branches or pull requests

    2 participants