This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git
The following commit(s) were added to refs/heads/master by this push:
new cb8ef6f Bug: convertToWrapped expects a bytestring
cb8ef6f is described below
commit cb8ef6f70fc859472df47c059c088fa20d4b0480
Author: Sebb <[email protected]>
AuthorDate: Tue Aug 25 21:06:24 2020 +0100
Bug: convertToWrapped expects a bytestring
This fixes #518
---
CHANGELOG.md | 1 +
tools/archiver.py | 18 +++++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c89459..289604f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
## Changes in 0.12:
+- Bug: convertToWrapped expects a bytestring (#518)
- Bug: don't add archived-at header to parsed message (#521)
- Enh: Be more lenient when parsing List-Id headers (#511)
- Enh: add some debug output to import-mbox (#396)
diff --git a/tools/archiver.py b/tools/archiver.py
index 60966dd..a614b1b 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -344,13 +344,15 @@ class Archiver(object): # N.B. Also used by import-mbox.py
epoch = email.utils.mktime_tz(mdate)
mdatestring = time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(epoch))
body = self.msgbody(msg)
+ saved_body = None # for format=flowed
try:
if 'content-type' in msg_metadata and
msg_metadata['content-type'].find("flowed") != -1:
- # N.B. the convertToWrapped call always fails, because body is
a string instead of bytes
+ saved_body = body # so we can redo it properly later
+ # N.B. the convertToWrapped call usually fails, because body
is a generally a string here
+ # However sometimes body is bytes at this point in which case
it works
body = formatflowed.convertToWrapped(body,
character_set="utf-8")
# DO NOT FIX IT -- otherwise generated MIDs will change
- # If it is desired to activate flow-formatting, it can be done
after MID generation
- # N.B. This code cannot just be moved intact as it transforms
all input
+ # The code now applies the formatting properly later
if isinstance(body, str):
body = body.encode('utf-8')
except Exception:
@@ -386,6 +388,16 @@ class Archiver(object): # N.B. Also used by import-mbox.py
irt = msg_metadata.get('in-reply-to').__str__()
except:
irt = ""
+
+ if 'content-type' in msg_metadata and
msg_metadata['content-type'].find("flowed") != -1:
+ if isinstance(saved_body, str):
+ saved_body = saved_body.encode('utf-8', 'replace')
+ try:
+ body = formatflowed.convertToWrapped(saved_body,
wrap_fixed=False, character_set="utf-8")
+ # print(body,file=sys.stderr)
+ except:
+ pass # Don't try to recover
+
ojson = {
'from_raw': msg_metadata['from'],
'from': msg_metadata['from'],