ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: mbox export now generates valid From_ line
Date Fri, 09 Dec 2016 20:23:37 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master e2138b9d2 -> fd999621b


mbox export now generates valid From_ line

This fixes #190

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

Branch: refs/heads/master
Commit: fd999621bd34de7a6e5b0d3011a80e9889dc0792
Parents: e2138b9
Author: Sebb <sebb@apache.org>
Authored: Fri Dec 9 19:18:03 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Fri Dec 9 19:18:03 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md      |  1 +
 site/api/mbox.lua | 26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd999621/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dd722d..893f0c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## CHANGES in 0.10:
 - private messages are now included in downloads if the user has access to them (#169, #108)
+- mbox export now generates valid From_ line (#190)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/fd999621/site/api/mbox.lua
----------------------------------------------------------------------
diff --git a/site/api/mbox.lua b/site/api/mbox.lua
index a737d90..1a24ead 100644
--- a/site/api/mbox.lua
+++ b/site/api/mbox.lua
@@ -40,6 +40,29 @@ function leapYear(year)
     end
 end
 
+--[[
+    Parse the source to construct a valid 'From ' line.
+
+    Look for:
+    Return-Path: <dev-return-648-archive-asf-public=cust-asf.ponee.io@ponymail.incubator.apache.org>
+    ...
+    Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183])
+      by cust-asf2.ponee.io (Postfix) with ESMTP id 9B3A0200BD9
+      for <archive-asf-public-internal@cust-asf2.ponee.io>; Fri,  9 Dec 2016 13:48:01
+0100 (CET)
+    ...
+]]--
+function getFromLine(r, source)
+    local replyTo = source:match("Return%-Path: +<(.-)>")
+    if not replyTo then replyTo = "MAILER-DAEMON" end
+
+    local received = source:match("Received: +from .-; +(.-)[\r\n]")
+    if not received then received = "" end
+    local recd = r.date_parse_rfc(received) or 0
+    local timeStamp = os.date('%c',  recd) -- ctime format
+
+    return "From " .. replyTo .. " " .. timeStamp
+end
+
 function handle(r)
     r.content_type = "application/mbox"
     local get = r:parseargs()
@@ -116,7 +139,8 @@ 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("From \n")
+                    r:puts(getFromLine(r, doc.source))
+                    r:puts("\n")
                     r:puts(doc.source)
                     r:puts("\n")
                 end


Mime
View raw message