Repository: incubator-ponymail Updated Branches: refs/heads/master 0783a476d -> 9b08bfe33
Bug: archiver stores attachment binary data types with embedded newlines This fixes #262 Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/9b08bfe3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/9b08bfe3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/9b08bfe3 Branch: refs/heads/master Commit: 9b08bfe33db81b1e0fcf5beec8060a4e0a78514b Parents: 0783a47 Author: Sebb <s...@apache.org> Authored: Sun Mar 19 23:32:38 2017 +0000 Committer: Sebb <s...@apache.org> Committed: Sun Mar 19 23:32:38 2017 +0000 ---------------------------------------------------------------------- CHANGELOG.md | 1 + tools/archiver.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/9b08bfe3/CHANGELOG.md ---------------------------------------------------------------------- diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c05ad4..ee542d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,6 +142,7 @@ - Bug: invalid style setting: overflow:hide => overflow:hidden (#364) - Bug: wordcloud.js logs to the console (#363) - Bug: source.lua does not specify the charset (#367) +- Bug: archiver stores attachment binary data types with embedded newlines (#262) ## CHANGES in 0.9b: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/9b08bfe3/tools/archiver.py ---------------------------------------------------------------------- diff --git a/tools/archiver.py b/tools/archiver.py index f7d7896..2061841 100755 --- a/tools/archiver.py +++ b/tools/archiver.py @@ -49,7 +49,7 @@ from email import policy import time from collections import namedtuple import re -import codecs +from base64 import standard_b64encode import chardet import configparser import os @@ -81,6 +81,10 @@ if config.has_option('elasticsearch', 'user'): archiver_generator = config.get("archiver", "generator", fallback="medium") +def encode_base64(bytes): + """ Convert bytes to base64 as text string (no newlines) """ + return standard_b64encode(bytes).decode('ascii', 'ignore') + def parse_attachment(part): cd = part.get("Content-Disposition", None) if cd: @@ -99,7 +103,7 @@ def parse_attachment(part): attachment['size'] = len(fd) attachment['filename'] = filename h = hashlib.sha256(fd).hexdigest() - b64 = codecs.encode(fd, "base64").decode('ascii', 'ignore') + b64 = encode_base64(fd) attachment['hash'] = h return attachment, b64 # Return meta data and contents separately return None, None