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 2016/12/18 21:11:02 UTC

incubator-ponymail git commit: manage e-mails can create multiple identical alternate addresses

Repository: incubator-ponymail
Updated Branches:
  refs/heads/master 05ee6da3d -> 0834913ee


manage e-mails can create multiple identical alternate addresses

This fixes #307

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

Branch: refs/heads/master
Commit: 0834913eeaf08648bcf2e78d5e95a8e3f751bf8b
Parents: 05ee6da
Author: Sebb <se...@apache.org>
Authored: Sun Dec 18 21:10:47 2016 +0000
Committer: Sebb <se...@apache.org>
Committed: Sun Dec 18 21:10:47 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md             |  1 +
 site/api/preferences.lua | 42 ++++++++++++++++++++++++++++++++++++------
 2 files changed, 37 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0834913e/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88a3866..b8bc46b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -87,6 +87,7 @@
 - Move common anonymizing code to utils (#308)
 - Move extractCanonEmail to utils
 - preferences does not properly remove nulls from account.credentials.altemail (#309)
+- manage e-mails can create multiple identical alternate addresses (#307)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0834913e/site/api/preferences.lua
----------------------------------------------------------------------
diff --git a/site/api/preferences.lua b/site/api/preferences.lua
index dcad4db..70b158a 100644
--- a/site/api/preferences.lua
+++ b/site/api/preferences.lua
@@ -94,7 +94,31 @@ function handle(r)
                 end
             end
         end
-        
+
+        if get.associate == account.credentials.email then
+            r:puts(JSON.encode{error="The primary mail address cannot be added as an alternate"})
+            return cross.OK
+        end
+
+
+        account.credentials.altemail = account.credentials.altemail or {}
+        filtertable(account.credentials.altemail)
+        local duplicateRequest = false
+        for k, v in pairs(account.credentials.altemail) do
+            if v.email == get.associate then -- duplicate request
+                if v.verified then -- already exists
+                    r:puts(JSON.encode{error="That email is already defined as an alternate"})
+                    -- OK to return here as we don't need to update anything
+                    return cross.OK
+                else -- pending verification, update the hash
+                    v.hash = hash -- update all pending requests to the new hash
+                    -- cannot return here in case there are multiple entries
+                    -- also we need to mail the new hash to the user
+                    duplicateRequest = true
+                end
+            end
+        end
+
         local hash = r:md5(math.random(1,999999) .. os.time() .. account.cid)
         local scheme = "https"
         if r.port == 80 then
@@ -118,8 +142,11 @@ function handle(r)
                     },
                 body = ([[
 You (or someone else) has requested to associate the email address '%s' with the account '%s' in Pony Mail.
-If you wish to complete this association, please visit %s whilst logged in to Pony Mail.
- ...Or don't if you didn't request this, just ignore this email.
+If you wish to complete this association, please visit
+%s
+whilst logged in to Pony Mail.
+Note: if you have repeated the association request, only the last URL will work.
+ ...Or if you didn't request this, just ignore this email.
 
 With regards,
 Pony Mail - Email for Ponies and People.
@@ -136,8 +163,9 @@ Pony Mail - Email for Ponies and People.
         }
          -- only update the account if the mail was sent OK
         if rv then
-            account.credentials.altemail = account.credentials.altemail or {}
-            table.insert(account.credentials.altemail, { email = get.associate, hash = hash, verified = false})
+            if not duplicateRequest then
+                table.insert(account.credentials.altemail, { email = get.associate, hash = hash, verified = false})
+            end
             user.save(r, account, true)
         end
         r:puts(JSON.encode{requested = rv or er})
@@ -151,11 +179,13 @@ Pony Mail - Email for Ponies and People.
         for k, v in pairs(account.credentials.altemail) do
             if v.hash == get.hash then
                 account.credentials.altemail[k].verified = true
+                account.credentials.altemail[k].hash = nil
                 verified = true
-                break
+                -- fix all the matches
             end
         end
         user.save(r, account, true)
+        -- response goes back to the browser direct
         cross.contentType(r, "text/plain")
         if verified then
             r:puts("Email address verified! Thanks for shopping at Pony Mail!\n")