From: Florian Klink <flokli@flokli.de>
To: notmuch@notmuchmail.org
Subject: [PATCH] python: open messages in binary mode
Date: Thu, 24 Aug 2017 23:30:01 +0200 [thread overview]
Message-ID: <20170824213001.22353-1-flokli@flokli.de> (raw)
currently, notmuch's get_message_parts() opens the file in text mode and passes
the file object to email.message_from_file(fp). In case the email contains
UTF-8 characters, reading might fail inside email.parser with the following exception:
File "/usr/lib/python3.6/site-packages/notmuch/message.py", line 591, in get_message_parts
email_msg = email.message_from_binary_file(fp)
File "/usr/lib/python3.6/email/__init__.py", line 62, in message_from_binary_file
return BytesParser(*args, **kws).parse(fp)
File "/usr/lib/python3.6/email/parser.py", line 110, in parse
return self.parser.parse(fp, headersonly)
File "/usr/lib/python3.6/email/parser.py", line 54, in parse
data = fp.read(8192)
File "/usr/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1865: invalid continuation byte
To fix this, read file in binary mode and pass to
email.message_from_binary_file(fp).
Signed-off-by: Florian Klink <flokli@flokli.de>
---
bindings/python/notmuch/message.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index cce377d0..531b22d0 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -587,8 +587,8 @@ class Message(Python3StringMixIn):
def get_message_parts(self):
"""Output like notmuch show"""
- fp = open(self.get_filename())
- email_msg = email.message_from_file(fp)
+ fp = open(self.get_filename(), 'rb')
+ email_msg = email.message_from_binary_file(fp)
fp.close()
out = []
--
2.14.1
next reply other threads:[~2017-08-24 21:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 21:30 Florian Klink [this message]
2017-08-24 22:11 ` [PATCH] python: open messages in binary mode David Bremner
2017-08-25 6:08 ` Gaute Hope
2017-08-25 10:18 ` Florian Klink
2017-09-24 12:36 ` [PATCH v2 1/2] " Florian Klink
2017-09-24 12:36 ` [PATCH v2 2/2] T390-python: add test for get_message_parts and special characters Florian Klink
2017-10-02 11:04 ` [PATCH v2 1/2] python: open messages in binary mode David Bremner
2017-10-02 11:39 ` Florian Klink
2017-10-05 15:50 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170824213001.22353-1-flokli@flokli.de \
--to=flokli@flokli.de \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).