coddingtonbear / django-mailbox

Import mail from POP3, IMAP, local email mailboxes or directly from Postfix or Exim4 into your Django application automatically.
MIT License
356 stars 164 forks source link

AttributeError: 'int' object has no attribute 'decode' #242

Open dismine opened 3 years ago

dismine commented 3 years ago

Hi.

django-mailbox==4.8.1

From time to time when I call getmail command I get:

File "/opt/env/lib/python3.7/site-packages/django_mailbox/management/commands/getmail.py", line 25, in handle
    for message in messages:
  File "/opt/env/lib/python3.7/site-packages/django_mailbox/models.py", line 413, in get_new_mail
    for message in connection.get_message(condition):
  File "/opt/env/lib/python3.7/site-packages/django_mailbox/transports/imap.py", line 118, in get_message
    message = self.get_email_from_bytes(msg_contents[0][1])
  File "/opt/env/lib/python3.7/site-packages/django_mailbox/transports/base.py", line 15, in get_email_from_bytes
    message = email.message_from_bytes(contents)
  File "/usr/lib/python3.7/email/__init__.py", line 46, in message_from_bytes
    return BytesParser(*args, **kws).parsebytes(s)
  File "/usr/lib/python3.7/email/parser.py", line 123, in parsebytes
    text = text.decode('ASCII', errors='surrogateescape')
AttributeError: 'int' object has no attribute 'decode'
lampslave commented 5 months ago

This may occur when server returns error, something like [b'System Error (Failure)'] and [b'System Error (Failure)'][0][1] is 121 because these are bytes, not str.

smjaberl commented 1 month ago

I think it is a issue with the imaplib. My setup is a python 3.12.4 and imaplib in version 2.58. There is often the exception AttributeError: 'int' object has no attribute 'decode' I refactor my code and used imap_tools in version 1.7.1 and all things are fine.

Why do I answer here? I didn't found a better place after searching the issue.

pfouque commented 1 month ago

Thanks @smjaberl for this precious feedback! it would be interesting to see how difficult it would be to implement this library... Could you share some samples?