rickypc / robotframework-imaplibrary

IMAP email testing library for Robot Framework
https://pypi.python.org/pypi/robotframework-imaplibrary
Apache License 2.0
21 stars 35 forks source link

use codecs module to decode quoted printable email bodys #9

Open peritus opened 7 years ago

peritus commented 7 years ago

We're using Python 3.5 and we kept getting this error when parsing emails:

Documentation:  
Returns all links found in the email body from given email_index.
Start / End / Elapsed:  20170609 14:05:28.333 / 20170609 14:05:28.500 / 00:00:00.167
14:05:28.334    TRACE   Arguments: [ b'21' ]    
14:05:28.499    FAIL    LookupError: 'quoted-printable' is not a text encoding; use codecs.decode() to handle arbitrary codecs  
14:05:28.499    DEBUG   Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ImapLibrary/__init__.py", line 147, in get_links_from_email
    body = self.get_email_body(email_index)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ImapLibrary/__init__.py", line 135, in get_email_body
    decode('quoted-printable')

The attached code fixes that by using the codecs module [https://docs.python.org/3.6/library/codecs.html] to parse the quoted printable email bodies

AndyDeany commented 7 years ago

@peritus Actually, I've noticed that for my emails, the encoding is 'latin-1' instead of 'utf-8'. Any chance you could add an encoding='utf-8' default parameter to the method and then change the decoding step to read:

body = decode(encoded_body, 'quopri_codec').decode(encoding)

Thanks, Andrew

rickypc commented 6 years ago

Thank you, @peritus. Would you please fill in the CLA located here: https://goo.gl/forms/QMyqXJI2LM. Thanks.

nhtua commented 4 years ago

Is there any update since May 21?

lasselindqvist commented 4 years ago

Is there any update since May 21?

If you need this fix, you can try using https://github.com/lasselindqvist/robotframework-imaplibrary2 / https://pypi.org/project/robotframework-imaplibrary2/