vladimarius / imapy

Imapy: Imap for Humans
230 stars 22 forks source link

stopped working after upgrade to python 3.4 #13

Closed pareznik closed 5 years ago

pareznik commented 8 years ago
  File "/usr/local/lib/python3.4/dist-packages/imapy/email_message.py", line 43, in __init__
    self.parse()
  File "/usr/local/lib/python3.4/dist-packages/imapy/email_message.py", line 152, in parse
    attachment_fname = decode_header(part.get_filename())
  File "/usr/lib/python3.4/email/header.py", line 80, in decode_header
    if not ecre.search(header):
TypeError: expected string or buffer

Solution: Change imapy/email_message.py, line 152 from: attachment_fname = decode_header(part.get_filename()) to attachment_fname = decode_header(part.get_filename() or '')

vladimarius commented 8 years ago

Could you provide me with sample email which causes this error so i could include it in tests or at least see the error myself ?

p.s. - emails used for testing could be found here

pawelad commented 8 years ago

I can confirm this bug and working on providing you with an email. Do you need anything in particular?

pabluk commented 8 years ago

Same issue here, using python 3.5.2 too.

@vladimarius you can reproduce the error using the current sample e-mails and test suite.

Here's an example with the latest commit 75f6ffc4c735fe89b0a08fa139bf3c86af86145a:

>>> import tests
>>> tests.test_parsing_sample_emails()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pabluk/dev/projects/imapy/tests.py", line 659, in test_parsing_sample_emails
    email_obj=email_obj, imap_obj=None)
  File "/home/pabluk/dev/projects/imapy/imapy/email_message.py", line 43, in __init__
    self.parse()
  File "/home/pabluk/dev/projects/imapy/imapy/email_message.py", line 152, in parse
    attachment_fname = decode_header(part.get_filename())
  File "/usr/lib/python3.5/email/header.py", line 80, in decode_header
    if not ecre.search(header):
TypeError: expected string or bytes-like object
$ python
Python 3.5.2 (default, Sep 10 2016, 08:21:44) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
techstroke commented 6 years ago

This is a bug with Python 3.6 too, I love this library but right now I had to edit line 152 as mentioned by @pareznik to get things working. Kindly fix this, I don't like editing external libs :( and this bug is already a Year Old!

dfrison01 commented 6 years ago

Can confirm the error persists in Python 3.6.5 x86 to present date. Did the same as techstroke in order to bypass the problem. Any news on this? Thx!