Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6D058200BED for ; Sun, 18 Dec 2016 02:55:16 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6B97E160B28; Sun, 18 Dec 2016 01:55:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8B0BA160B16 for ; Sun, 18 Dec 2016 02:55:15 +0100 (CET) Received: (qmail 57265 invoked by uid 500); 18 Dec 2016 01:55:14 -0000 Mailing-List: contact commits-help@ponymail.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ponymail.incubator.apache.org Delivered-To: mailing list commits@ponymail.incubator.apache.org Received: (qmail 57256 invoked by uid 99); 18 Dec 2016 01:55:14 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Dec 2016 01:55:14 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5AC1A18068F for ; Sun, 18 Dec 2016 01:55:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id VtNwpl1efrNi for ; Sun, 18 Dec 2016 01:55:10 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id A19215F306 for ; Sun, 18 Dec 2016 01:55:09 +0000 (UTC) Received: (qmail 57209 invoked by uid 99); 18 Dec 2016 01:55:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Dec 2016 01:55:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BECB3DFB8A; Sun, 18 Dec 2016 01:55:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sebb@apache.org To: commits@ponymail.incubator.apache.org Message-Id: <5883cd27d9aa49189c904a389c28cf50@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-ponymail git commit: Move common anonymizing code to utils Date: Sun, 18 Dec 2016 01:55:08 +0000 (UTC) archived-at: Sun, 18 Dec 2016 01:55:16 -0000 Repository: incubator-ponymail Updated Branches: refs/heads/master 60b8bac89 -> b78032b5c Move common anonymizing code to utils This fixes #308 Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/b78032b5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/b78032b5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/b78032b5 Branch: refs/heads/master Commit: b78032b5c021ab0321ff46b35f86ff1819edf662 Parents: 60b8bac Author: Sebb Authored: Sun Dec 18 01:54:53 2016 +0000 Committer: Sebb Committed: Sun Dec 18 01:54:53 2016 +0000 ---------------------------------------------------------------------- CHANGELOG.md | 1 + site/api/email.lua | 21 ++------------------- site/api/lib/utils.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ site/api/thread.lua | 18 ++---------------- 4 files changed, 49 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/b78032b5/CHANGELOG.md ---------------------------------------------------------------------- diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ee724..ecf2502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ - preferences.lua should not update the user account if the mail is not sent OK (#306) - alts.js does not check for errors when calling preferences.lua (#304) - An unauthorised private mail should be treated like a non-existent mail (#295) +- Move common anonymizing code to utils (#308) ## CHANGES in 0.9b: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/b78032b5/site/api/email.lua ---------------------------------------------------------------------- diff --git a/site/api/email.lua b/site/api/email.lua index 8654224..1139f3c 100644 --- a/site/api/email.lua +++ b/site/api/email.lua @@ -25,20 +25,6 @@ local cross = require 'lib/cross' local config = require 'lib/config' local utils = require 'lib/utils' --- anonymizer func -local function anonymize(doc) - if doc.from and doc.from ~= JSON.null and #doc.from > 0 then - doc.from = doc.from:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - if doc.cc and doc.cc ~= JSON.null and #doc.cc > 0 then - doc.cc = doc.cc:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - if doc.to and doc.to ~= JSON.null and #doc.to > 0 then - doc.to = doc.to:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - return doc -end - function handle(r) cross.contentType(r, "application/json") local get = r:parseargs() @@ -106,15 +92,12 @@ function handle(r) eml = "unknown" end if not account then -- anonymize email address if not logged in - doc = anonymize(doc) - if doc.from_raw then - doc.from_raw = doc.from_raw:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end + doc = utils.anonymizeHdrs(doc, true) end -- Anonymize any email address mentioned in the email if not logged in if not account and config.antispam then - doc.body = doc.body:gsub("<(%S+)@([-a-zA-Z0-9_.]+)>", function(a,b) return "<" .. a:sub(1,2) .. "..." .. "@" .. b .. ">" end) + doc.body = utils.anonymizeBody(doc.body) end http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/b78032b5/site/api/lib/utils.lua ---------------------------------------------------------------------- diff --git a/site/api/lib/utils.lua b/site/api/lib/utils.lua index 1b27645..13e77c0 100644 --- a/site/api/lib/utils.lua +++ b/site/api/lib/utils.lua @@ -17,6 +17,8 @@ -- This is lib/utils.lua - utility methods +local JSON = require 'cjson' -- for JSON.null + -- find the original topic starter local function findParent(r, doc, elastic) local step = 0 @@ -42,6 +44,48 @@ local function findParent(r, doc, elastic) end + +--[[ + Anonymize the document body +]] +local function anonymizeBody(body) + return body:gsub("<(%S+)@([-a-zA-Z0-9_.]+)>", function(a,b) return "<" .. a:sub(1,2) .. "..." .. "@" .. b .. ">" end) +end + +--[[ + Anonymize an email address +]] +local function anonymizeEmail(email) + return email:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) +end + +--[[ + Anonymize document headers: + - from + - cc + - to + Also processes from_raw if specified +]] +local function anonymizeHdrs(doc, from_raw) + if doc.from and doc.from ~= JSON.null and #doc.from > 0 then + doc.from = anonymizeEmail(doc.from) + end + if doc.cc and doc.cc ~= JSON.null and #doc.cc > 0 then + doc.cc = anonymizeEmail(doc.cc) + end + if doc.to and doc.to ~= JSON.null and #doc.to > 0 then + doc.to = anonymizeEmail(doc.to) + end + if from_raw and doc.from_raw then + doc.from_raw = anonymizeEmail(doc.from_raw) + end + return doc +end + + return { + anonymizeHdrs = anonymizeHdrs, + anonymizeBody = anonymizeBody, + anonymizeEmail = anonymizeEmail, findParent = findParent } http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/b78032b5/site/api/thread.lua ---------------------------------------------------------------------- diff --git a/site/api/thread.lua b/site/api/thread.lua index 62039f7..7be9c47 100644 --- a/site/api/thread.lua +++ b/site/api/thread.lua @@ -28,20 +28,6 @@ local utils = require 'lib/utils' local emls_thrd --- anonymizer func -local function anonymize(doc) - if doc.from and doc.from ~= JSON.null and #doc.from > 0 then - doc.from = doc.from:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - if doc.cc and doc.cc ~= JSON.null and #doc.cc > 0 then - doc.cc = doc.cc:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - if doc.to and doc.to ~= JSON.null and #doc.to > 0 then - doc.to = doc.to:gsub("(%S+)@(%S+)", function(a,b) return a:sub(1,2) .. "..." .. "@" .. b end) - end - return doc -end - -- func that fetches all children of an original topic email thingy local function fetchChildren(r, pdoc, c, biglist, account) c = (c or 0) + 1 @@ -60,7 +46,7 @@ local function fetchChildren(r, pdoc, c, biglist, account) biglist[doc['message-id']] = true local mykids = fetchChildren(r, doc, c, biglist, account) if not account and config.antispam then - doc = anonymize(doc) + doc = utils.anonymizeHdrs(doc) end local dc = { tid = doc.mid, @@ -112,7 +98,7 @@ function handle(r) local account = user.get(r) if doc and doc.mid and aaa.canAccessDoc(r, doc, account) then if not account and config.antispam then - doc = anonymize(doc) + doc = utils.anonymizeHdrs(doc) end table.insert(emls_thrd, doc) doc.children = fetchChildren(r, doc, 1, nil, account)