diff --git a/outlookmsgfile.py b/outlookmsgfile.py index e98ce77..e76a480 100644 --- a/outlookmsgfile.py +++ b/outlookmsgfile.py @@ -26,6 +26,7 @@ from email.utils import parsedate_to_datetime, formatdate, formataddr import compoundfiles from rtfparse.parser import Rtf_Parser from rtfparse.renderers.de_encapsulate_html import De_encapsulate_HTML +import html2text logger = logging.getLogger(__name__) @@ -131,6 +132,12 @@ def load_message_stream(entry, is_top_level, doc): De_encapsulate_HTML().render(parsed, html_stream) html_body = html_stream.getvalue() + if not has_body: + # Try to convert that to plain/text if possible. + text_body = html2text.html2text(html_body) + msg.set_content(text_body, subtype="text", cte='quoted-printable') + has_body = True + if not has_body: msg.set_content(html_body, subtype="html", cte='quoted-printable') has_body = True diff --git a/requirements.txt b/requirements.txt index a79e1e1..05a56f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ compoundfiles compressed-rtf rtfparse # Python 3.9+ only +html2text \ No newline at end of file diff --git a/setup.py b/setup.py index 9ce64b5..53507c0 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ install_requires = [ 'compoundfiles', 'compressed_rtf', 'rtfparse', + 'html2text', ] with open("README.md", "r") as fh: