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: properly remove nulls from account.credentials.altemail
Date Sun, 18 Dec 2016 12:44:43 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master ade18f4a5 -> 05ee6da3d


properly remove nulls from account.credentials.altemail 

This fixes #309

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

Branch: refs/heads/master
Commit: 05ee6da3d7b5e451254d24182591cec38cef15dd
Parents: ade18f4
Author: Sebb <sebb@apache.org>
Authored: Sun Dec 18 12:25:25 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Sun Dec 18 12:25:25 2016 +0000

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


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/05ee6da3/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index daef88f..88a3866 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -86,6 +86,7 @@
 - An unauthorised private mail should be treated like a non-existent mail (#295)
 - Move common anonymizing code to utils (#308)
 - Move extractCanonEmail to utils
+- preferences does not properly remove nulls from account.credentials.altemail (#309)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/05ee6da3/site/api/preferences.lua
----------------------------------------------------------------------
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index da1d944..dcad4db 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -27,6 +27,28 @@ local aaa = require 'lib/aaa'
 local utils = require 'lib/utils'
 
 --[[
+    Remove nulls values from a table
+    This is for use in tidying up account.credentials.altemail
+    which may contain null entries.
+    Rather than continually check for them, remove them from
+    the input before use.
+]]
+local function filtertable(input)
+    -- table.remove can affect pairs()
+    -- so repeat until no more to do
+    repeat
+        local isClean = true
+        for k, v in pairs(input) do
+            if not v or v == JSON.null then
+                table.remove(input, k)
+                isClean = false
+                break
+            end
+        end
+    until isClean
+end
+
+--[[
 Get login details (if logged in), mail list counts and descriptions
 
 Parameters: (cookie required)
@@ -124,17 +146,14 @@ Pony Mail - Email for Ponies and People.
     
     -- verify alt email?
     if get.verify and get.hash and account and account.credentials.altemail then
+        filtertable(account.credentials.altemail)
         local verified = false
         for k, v in pairs(account.credentials.altemail) do
-            if v and not (v == JSON.null) and v.hash == get.hash then
+            if v.hash == get.hash then
                 account.credentials.altemail[k].verified = true
                 verified = true
                 break
             end
-            if v == JSON.null then
-                table.remove(account.credentials.altemail, k)
-                break
-            end
         end
         user.save(r, account, true)
         cross.contentType(r, "text/plain")
@@ -148,9 +167,9 @@ Pony Mail - Email for Ponies and People.
     
     -- remove alt email?
     if get.removealt and account and account.credentials.altemail then
+        filtertable(account.credentials.altemail)
         for k, v in pairs(account.credentials.altemail) do
-            -- allow for null just in case table was corrupted
-            if v and not (v == JSON.null) and v.email == get.removealt then
+            if v.email == get.removealt then
                 table.remove(account.credentials.altemail, k)
                 break
             end
@@ -378,14 +397,8 @@ Pony Mail - Email for Ponies and People.
     
     local alts = {}
     if account and account.credentials and type(account.credentials.altemail) == "table"
then
+        filtertable(account.credentials.altemail)
         for k, v in pairs(account.credentials.altemail) do
-                
-            -- null check from previous corruptions
-            if v == JSON.null then
-                table.remove(account.credentials.altemail, k)
-                break
-            end
-            
             if v.verified then
                 table.insert(alts, v.email)
             end


Mime
View raw message