You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2017/09/19 14:58:54 UTC

incubator-ponymail git commit: Bug: use actual envelope header if present

Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 2d0875715 -> e6daa748a


Bug: use actual envelope header if present

This fixes #412

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/e6daa748
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/e6daa748
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/e6daa748

Branch: refs/heads/master
Commit: e6daa748a6e57417b53abf24c2c298b74504a981
Parents: 2d08757
Author: Sebb <se...@apache.org>
Authored: Tue Sep 19 15:58:50 2017 +0100
Committer: Sebb <se...@apache.org>
Committed: Tue Sep 19 15:58:50 2017 +0100

----------------------------------------------------------------------
 CHANGELOG.md      |  1 +
 site/api/mbox.lua | 16 +++++++++++++---
 tools/archiver.py |  3 ++-
 3 files changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/e6daa748/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f62dfcd..0ecf255 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
 ## CHANGES in 0.10:
+- Bug: use actual envelope header if present (#412)
 - Bug: stats.lua should use UTC for calculating year and month (#409)
 - Bug: atom.lua - should generate date in UTC, not local time (#408)
 - Bug: shorten links does not work with cluster ids (#406)

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/e6daa748/site/api/mbox.lua
----------------------------------------------------------------------
diff --git a/site/api/mbox.lua b/site/api/mbox.lua
index 9f3aa31..68e164b 100644
--- a/site/api/mbox.lua
+++ b/site/api/mbox.lua
@@ -118,12 +118,22 @@ function handle(r)
             if listAccessible or not v.private then
                 local doc = elastic.get('mbox_source', v.mid)
                 if doc and doc.source then
-                    r:puts(getFromLine(r, doc.source))
-                    r:puts("\n")
+                    local checkFirst -- should we check the first line?
+                    if not doc.source:match('^From ') then -- only add the header if there is none
+                        r:puts(getFromLine(r, doc.source))
+                        r:puts("\n")
+                        checkFirst=true
+                    else
+                        checkFirst=false
+                    end
+                    
                     -- pick out individual lines (including last which may not have EOL)
+                    -- it's tricky to add the prefix to the output unless the From is at the start of a line
+                    -- so it's easier to just skip the first match if necessary
                     for line in doc.source:gmatch("[^\r\n]*\r?\n?") do
                         -- check if 'From ' needs to be escaped
-                        if line:match("^From ") then r:puts(">") end
+                        if checkFirst and line:match("^From ") then r:puts(">") end
+                        checkFirst=true
                         -- TODO consider whether to optionally prefix '>From ', '^>>From ' etc. 
                         -- If so, just change the RE to "^>*From "
                         r:puts(line) -- original line

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/e6daa748/tools/archiver.py
----------------------------------------------------------------------
diff --git a/tools/archiver.py b/tools/archiver.py
index b3246d2..3785c86 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -512,7 +512,8 @@ 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
-        b = msg.as_bytes(policy=policy)
+        hasFrom=(msg.get_unixfrom() != None) # only use the envelope if it exists
+        b = msg.as_bytes(unixfrom=hasFrom, policy=policy)
         try:
             # Can we store as ASCII?
             return b.decode('ascii', errors='strict')