Skip to content

Commit

Permalink
decode MailMessage text and html using encoding, specified in email
Browse files Browse the repository at this point in the history
  • Loading branch information
ikvk committed Jul 31, 2019
1 parent 56d045e commit 9908aec
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ Thanks to
| `thiebautdotdev <https://github.com/thiebautdotdev>`_
| `TpyoKnig <https://github.com/TpyoKnig>`_
| `parchd-1 <https://github.com/parchd-1>`_
| `dojasoncom <https://github.com/dojasoncom>`_
4 changes: 2 additions & 2 deletions imap_tools/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def text(self) -> str:
if part.get_content_maintype() == 'multipart':
continue
if part.get_content_type() in ('text/plain', 'text/'):
return part.get_payload(decode=True).decode('utf-8', 'ignore')
return part.get_payload(decode=True).decode(part.get_content_charset(failobj='utf-8'), 'ignore')
return ''

@property
Expand All @@ -190,7 +190,7 @@ def html(self) -> str:
if part.get_content_maintype() == 'multipart':
continue
if part.get_content_type() == 'text/html':
return part.get_payload(decode=True).decode('utf-8', 'ignore')
return part.get_payload(decode=True).decode(part.get_content_charset(failobj='utf-8'), 'ignore')
return ''

@property
Expand Down
4 changes: 4 additions & 0 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.7.0
=====
* decode MailMessage text and html using encoding, specified in email

0.6.0
=====

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='imap_tools',
version='0.6.0',
version='0.7.0',
packages=setuptools.find_packages(),
url='https://github.com/ikvk/imap_tools',
license='MIT',
Expand Down

0 comments on commit 9908aec

Please sign in to comment.