martinrusev / imbox

Python IMAP for Human beings
MIT License
1.18k stars 188 forks source link

Avoiding the error - ValueError: invalid literal for int() with base 10 #201

Closed Anderseta closed 3 years ago

Anderseta commented 3 years ago

Traceback (most recent call last): File "/opt/mailbox/inbox.py", line 161, in read_imap for uid, message in unread_inbox_messages: File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 55, in _fetch_email_list yield uid, self._fetch_email(uid) File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 44, in _fetch_email parser_policy=self.parser_policy) File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 155, in fetch_email_by_uid email_object = parse_email(raw_email, policy=parser_policy) File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 212, in parse_email attachment = parse_attachment(part) File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 122, 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 think the problem is because (not sure): For some pdf attachments the filename field is empty. This is because sometimes the file name is indicated in the content-type field.

This simple change avoid the whole script loop being stuck