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 - inconsistent output between slow_count = true/false
Date Fri, 16 Dec 2016 22:16:18 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 57f5b3f54 -> 6a7bc6275


stats.lua - inconsistent output between slow_count = true/false

This fixes #301

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

Branch: refs/heads/master
Commit: 6a7bc6275710f8c407fffd1898b0248c4aa984a1
Parents: 57f5b3f
Author: Sebb <sebb@apache.org>
Authored: Fri Dec 16 22:15:45 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Fri Dec 16 22:15:45 2016 +0000

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


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/6a7bc627/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c05ece2..253ef50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -69,6 +69,7 @@
 - rights checking should be localised (#293)
 - pminfo.lua does some unnecessary work (#220)
 - stats.lua uses inconsistent email canonicalisation code (#300)
+- stats.lua - inconsistent output between slow_count = true/false (#301)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/6a7bc627/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index 3226314..79d41c7 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -66,6 +66,12 @@ local function leapYear(year)
     end
 end
 
+-- extract canonical email name from from field
+local function extractCanonName(from)
+    local name = from:match("([^<]+)%s*<.->") or from:match("%S+@%S+") or from:match("%((.-)%)")
or "unknown"
+    return name:gsub("\"", ""):gsub("%s+$", "")
+end
+
 -- extract canonical email address from from field
 local function extractCanonEmail(from)
     local eml = from:match("<(.-)>") or from:match("%S+@%S+") or nil
@@ -371,10 +377,8 @@ function handle(r)
         for x,y in pairs (doc.aggregations.from.buckets) do
             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("\"", "")
+            local name = extractCanonName(y.key)
             table.insert(top10, {
-                id = y.key,
                 email = eml,
                 gravatar = gravatar,
                 name = name,
@@ -587,13 +591,14 @@ function handle(r)
         if aaa.canAccessDoc(r, email, account) then
 
             h = h + 1
-            
+
+            -- This is needed by ths slow_count method            
+            local eml = extractCanonEmail(email.from)
+            local gravatar = r:md5(eml:lower())
+            email.gravatar = gravatar
+
             if not config.slow_count then
-                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
-                name = name:gsub("\"", ""):gsub("%s+$", "")
+                local name = extractCanonName(email.from)
                 local eid = ("%s <%s>"):format(name, eml)
                 senders[eid] = senders[eid] or {
                     email = eml,
@@ -691,6 +696,7 @@ function handle(r)
             for k, v in pairs(top10) do
                 if v.email == extractCanonEmail(email.from) then
                     v.count = v.count - 1
+                    break -- don't count the e-mail again
                 end
             end
         end
@@ -711,12 +717,20 @@ function handle(r)
             end
         end
     end
-    for k, v in pairs(top10) do
-        if v.count <= 0 then
-            top10[k] = nil
+
+    -- drop any non-participants and count the remainders
+    -- count the participants
+    if config.slow_count then
+        local top10_copy = top10
+        top10 = {}
+        for k, v in pairs(top10_copy) do
+            if v.count > 0 then
+                table.insert(top10, v)
+                allparts = allparts + 1
+            end
         end
     end
-    
+
     -- anonymize emails if not logged in - anti-spam!
     if not account and config.antispam then
         for k, v in pairs(top10) do


Mime
View raw message