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: stats.lua uses inconsistent email canonicalisation code
Date Fri, 16 Dec 2016 19:01:59 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master bc42f8efb -> 57f5b3f54


stats.lua uses inconsistent email canonicalisation code

This fixes #300

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

Branch: refs/heads/master
Commit: 57f5b3f540a46817e11c7b39af0d59b1bb5d16be
Parents: bc42f8e
Author: Sebb <sebb@apache.org>
Authored: Fri Dec 16 19:01:36 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Fri Dec 16 19:01:36 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md       |  1 +
 site/api/stats.lua | 28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/57f5b3f5/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37c3941..c05ece2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,7 @@
 - lib/aaa.lua overwrites local customisations on updates (#292)
 - rights checking should be localised (#293)
 - pminfo.lua does some unnecessary work (#220)
+- stats.lua uses inconsistent email canonicalisation code (#300)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/57f5b3f5/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index a77ef12..3226314 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -66,6 +66,16 @@ local function leapYear(year)
     end
 end
 
+-- extract canonical email address from from field
+local function extractCanonEmail(from)
+    local eml = from:match("<(.-)>") or from:match("%S+@%S+") or nil
+    if eml == nil and from:match(".- at .- %(") then
+        eml = from:match("(.- at .-) %("):gsub(" at ", "@")
+    elseif eml == nil then
+        eml = "unknown"
+    end
+    return eml
+end
 
 function handle(r)
     cross.contentType(r, "application/json")
@@ -359,12 +369,7 @@ function handle(r)
         tnow = r:clock()
         
         for x,y in pairs (doc.aggregations.from.buckets) do
-            local eml = y.key:match("<(.-)>") or y.key:match("%S+@%S+") or nil
-            if eml == nil and y.key:match(".- at .- %(") then
-                eml = y.key:match("(.- at .-) %("):gsub(" at ", "@")
-            elseif eml == nil then
-                eml = "unknown"
-            end
+            local eml = extractCanonEmail(y.key)
             local gravatar = r:md5(eml:lower())
             local name = y.key:match("([^<]+)%s*<.->") or y.key:match("%S+@%S+")
or "unknown"
             name = name:gsub("\"", "")
@@ -584,12 +589,7 @@ function handle(r)
             h = h + 1
             
             if not config.slow_count then
-                local eml = email.from:match("<(.-)>") or email.from:match("%S+@%S+")
or nil
-                if eml == nil and email.from:match(".- at .- %(") then
-                    eml = email.from:match("(.- at .-) %("):gsub(" at ", "@")
-                elseif eml == nil then
-                    eml = "unknown"
-                end
+                local eml = extractCanonEmail(email.from)
                 local gravatar = r:md5(eml:lower())
                 local name = email.from:match("([^<]+)%s*<.->") or email.from:match("%S+@%S+")
or email.from:match("%((.-)%)") or "unknown"
                 email.gravatar = gravatar
@@ -689,8 +689,7 @@ function handle(r)
             end
         elseif config.slow_count then
             for k, v in pairs(top10) do
-                local eml = email.from:match("<(.-)>") or email.from:match("%S+@%S+")
or "unknown"
-                if v.email == eml then
+                if v.email == extractCanonEmail(email.from) then
                     v.count = v.count - 1
                 end
             end
@@ -765,6 +764,7 @@ function handle(r)
     tnow = r:clock()
     
     listdata.debug = t
+    listdata.slow_count = config.slow_count -- debug
     
     r:puts(JSON.encode(listdata))
     


Mime
View raw message