martinrusev / imbox

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

Issue with duplicate attachments #214

Open jimmi2051 opened 2 years ago

jimmi2051 commented 2 years ago

Hi, I'm Thanh. I have an issue with duplicate attachments. I have received an email with 5 attachments but it is the same file. And in Gmail show only 1 file. But in code, we read it is 5 attachments . So it is broken.

image

image

sebix commented 2 years ago

What does the emails source code reveal?

jimmi2051 commented 2 years ago

yep, here is my issue >

  File "/usr/src/app/sap/model_helpers/email_attachment_mixin.py", line 57, in pull_attachments_from_email
    for (uid, message) in unread_inbox_messages:
  File "/root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.8/site-packages/imbox/messages.py", line 55, in _fetch_email_list
    yield uid, self._fetch_email(uid)
  File "/root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.8/site-packages/imbox/messages.py", line 42, in _fetch_email
    return fetch_email_by_uid(uid=uid,
  File "/root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.8/site-packages/imbox/parser.py", line 155, in fetch_email_by_uid
    email_object = parse_email(raw_email, policy=parser_policy)
  File "/root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.8/site-packages/imbox/parser.py", line 212, in parse_email
    attachment = parse_attachment(part)
  File "/root/.local/share/virtualenvs/app-lp47FrbD/lib/python3.8/site-packages/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: ''
sebix commented 2 years ago

Duplicate of #198

jimmi2051 commented 2 years ago

Thanks @sebix . I have tried to bypass function parse and I got names of some files are utf-8-'***' Example:

[ '02 Vu Thi My Hao.docx', 
'CV Hoang Minh Tu.docx', 
"utf-8''L%C3%AA%20H%E1%BB%AFu%20Vi%E1%BB%87t%20%2D%20QA%20%2D%20H%C3%A0%20N%E1%BB%99i.docx", 
'04 Pham Nguyen Huyen Thanh.doc', 
"utf-8''HO%5FSO%5FTh%C3%B4ng%20tin%20c%C3%A1%20nh%C3%A2n%2Dmss%20h%C3%A0.doc", 'VoThiThuyTien.pdf', 
'NguyenThanhHauResume.pdf', 
'NGUYEN-CONG-MINH-TopCV.vn-080720.03323.pdf']