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

ValueError: invalid literal for int() with base 10 #64

Open
ncsalgado opened this issue Dec 20, 2024 · 1 comment
Open

ValueError: invalid literal for int() with base 10 #64

ncsalgado opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@ncsalgado
Copy link

Some attachments give the following error:
File "C:\Users\adminns\AppData\Roaming\Python\Python310\site-packages\imbox\messages.py", line 55, in _fetch_email_list yield uid, self._fetch_email(uid)
File "C:\Users\adminns\AppData\Roaming\Python\Python310\site-packages\imbox\messages.py", line 42, in _fetch_email return fetch_email_by_uid(uid=uid,
File "C:\Users\adminns\AppData\Roaming\Python\Python310\site-packages\imbox\parser.py", line 157, in fetch_email_by_uid email_object = parse_email(raw_email, policy=parser_policy)
File "C:\Users\adminns\AppData\Roaming\Python\Python310\site-packages\imbox\parser.py", line 214, in parse_email attachment = parse_attachment(part)
File "C:\Users\adminns\AppData\Roaming\Python\Python310\site-packages\imbox\parser.py", line 124, 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:

An example of value of var "param" in line 114 of file "parser" is: "filename*=iso-8859-1''PALLETWAYS_Renova%E7aoISO_0212.docx".
So var "s_name" as value ['filename', ''] and it breaks in line 122 in: ...int(s_name[1]) because s_name[1] is ''....

What I did was test if s_name[1] is '' and encode the file name if necessary, replacing line 122 with:
if s_name[1] != '':
filename_parts.insert(int(s_name[1]),value[1:-1] if value.startswith('"') else value)
elif "''" in value:
encoding, encoded_filename = value.split("''", 1)
filename_parts.insert(0, urllib.parse.unquote(encoded_filename, encoding))
else:
filename_parts.insert(0,value[1:-1] if value.startswith('"') else value)

Don't forget to include urllib.
Best regards,

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant