Repository: incubator-ponymail Updated Branches: refs/heads/master 9b08bfe33 -> 0f0301f9a
Bug: may corrupt 8bit message source if it is not encoded in UTF-8 This fixes #366 Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/0f0301f9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/0f0301f9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/0f0301f9 Branch: refs/heads/master Commit: 0f0301f9aedd9693a865de8b110ce0a7973e156f Parents: 9b08bfe Author: Sebb <s...@apache.org> Authored: Sun Mar 19 23:54:05 2017 +0000 Committer: Sebb <s...@apache.org> Committed: Sun Mar 19 23:54:05 2017 +0000 ---------------------------------------------------------------------- CHANGELOG.md | 1 + site/api/lib/elastic.lua | 12 ++++++++++++ tools/archiver.py | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0f0301f9/CHANGELOG.md ---------------------------------------------------------------------- diff --git a/CHANGELOG.md b/CHANGELOG.md index ee542d4..e4ab96f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,6 +143,7 @@ - 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) +- Bug: may corrupt 8bit message source if it is not encoded in UTF-8 (#366) ## CHANGES in 0.9b: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0f0301f9/site/api/lib/elastic.lua ---------------------------------------------------------------------- diff --git a/site/api/lib/elastic.lua b/site/api/lib/elastic.lua index f53286b..3a1505b 100644 --- a/site/api/lib/elastic.lua +++ b/site/api/lib/elastic.lua @@ -20,6 +20,7 @@ local http = require 'socket.http' local JSON = require 'cjson' local config = require 'lib/config' +local mime = require('mime') local default_doc = "mbox" -- http code return check @@ -108,6 +109,17 @@ local function getDoc (ty, id, ok404) if ty == "mbox" and json._source.body == JSON.null then json._source.body = '' end + if ty == "mbox_source" then + local src = json._source.source + -- could it be base64 encoded? + -- Unencoded source must contain at least one space; b64 does not + if src:len() % 4 == 0 and src:find(' ') == nil then + src = (mime.unb64(src)) + if src ~= nil then + json._source.source = src + end + end + end end return (json and json._source) and json._source or {}, status end http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0f0301f9/tools/archiver.py ---------------------------------------------------------------------- diff --git a/tools/archiver.py b/tools/archiver.py index 2061841..4e4a4e7 100755 --- a/tools/archiver.py +++ b/tools/archiver.py @@ -516,7 +516,7 @@ class Archiver(object): def mbox_source(self, msg): # Common method shared with import-mbox policy = msg.policy.clone(max_line_length=0) # don't wrap headers - return msg.as_bytes(policy=policy).decode('utf-8', errors='replace') + return encode_base64(msg.as_bytes(policy=policy)) def list_url(self, mlist): """ Required by MM3 plugin API