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

attachments parser got ValueError #198

Open
mr-pounds opened this issue Mar 18, 2021 · 2 comments
Open

attachments parser got ValueError #198

mr-pounds opened this issue Mar 18, 2021 · 2 comments

Comments

@mr-pounds
Copy link

mr-pounds commented Mar 18, 2021

When I try to get message, I got ValueError.

Traceback (most recent call last):
File "myimap.py", line 70, in
result = obj.get_emails(date_gt='2021-03-17')
File "myimap.py", line 42, in get_emails
_, message = all_inbox_messages[index]
File "C:\Users\admin\anaconda3\envs\grades\lib\site-packages\imbox\messages.py", line 77, in getitem
return uid, self._fetch_email(uid)
File "C:\Users\admin\anaconda3\envs\grades\lib\site-packages\imbox\messages.py", line 42, in _fetch_email
return fetch_email_by_uid(uid=uid,
File "C:\Users\admin\anaconda3\envs\grades\lib\site-packages\imbox\parser.py", line 156, in fetch_email_by_uid
email_object = parse_email(raw_email, policy=parser_policy)
File "C:\Users\admin\anaconda3\envs\grades\lib\site-packages\imbox\parser.py", line 213, in parse_email
attachment = parse_attachment(part)
File "C:\Users\admin\anaconda3\envs\grades\lib\site-packages\imbox\parser.py", line 123, in parse_attachment
filename_parts.insert(int(s_name[1]),value[1:-1] if value.startswith('"') else value)
ValueError: invalid literal for int() with base 10: ''

I found 【s_name = ['file_name', '']】, so I add some code.

if s_name[0] == 'filename':
    # If this is a split file name - use the number after the * as an index to insert this part
    if len(s_name) > 1 and s_name[1] != '':
        filename_parts.insert(int(s_name[1]),value[1:-1] if value.startswith('"') else value)
    else:
        filename_parts.insert(0,value[1:-1] if value.startswith('"') else value)

I don't kown why s_name has '', but it's working.

@allanjonis
Copy link

allanjonis commented Apr 29, 2021

Thank you, your code solve the problem here, apparently the cause is character encoding.

@kelwin-fc
Copy link

I added and s_name[1].isdigit() to the same line. I guess it's slightly more robust in case s_name[1] has a non-empty string that isn't a number.

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

3 participants