robotframework-imaplibrary icon indicating copy to clipboard operation
robotframework-imaplibrary copied to clipboard

use codecs module to decode quoted printable email bodys

Open peritus opened this issue 7 years ago • 4 comments

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

peritus avatar Jun 09 '17 12:06 peritus

@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

AndyDeany avatar Jun 28 '17 15:06 AndyDeany

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

rickypc avatar Apr 07 '18 09:04 rickypc

Is there any update since May 21?

nhtua avatar Nov 26 '19 05:11 nhtua

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/

lasselindqvist avatar Dec 03 '19 16:12 lasselindqvist