ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [2/2] incubator-ponymail git commit: lua modules should define local functions only
Date Tue, 13 Dec 2016 21:45:57 GMT
lua modules should define local functions only

This fixes #294

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

Branch: refs/heads/master
Commit: f40dd3c63edbf8ffb99aea444a5a45ddc8bd9ab3
Parents: 94e61db
Author: Sebb <sebb@apache.org>
Authored: Tue Dec 13 21:45:33 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Tue Dec 13 21:45:33 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.md                          |  1 +
 aaa_examples/aaa_by_email_address.lua |  4 ++--
 aaa_examples/aaa_by_portal.lua        |  2 +-
 aaa_examples/aaa_with_subgroups.lua   |  2 +-
 site/api/atom.lua                     |  2 +-
 site/api/email.lua                    |  2 +-
 site/api/lib/aaa.lua                  |  6 +++---
 site/api/lib/cross.lua                |  4 ++--
 site/api/lib/elastic.lua              | 20 ++++++++++----------
 site/api/lib/user.lua                 | 10 +++++-----
 site/api/mbox.lua                     |  4 ++--
 site/api/static.lua                   |  4 ++--
 site/api/stats.lua                    |  6 +++---
 site/api/thread.lua                   |  4 ++--
 14 files changed, 36 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8979895..25dd5d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@
 - does not handle text/enriched mails (#289)
 - ll.py retrieves results but does not use them (#291)
 - lib/aaa.lua various bugs (#140)
+- lua modules should define local functions only (#294)
 
 ## CHANGES in 0.9b:
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/aaa_examples/aaa_by_email_address.lua
----------------------------------------------------------------------
diff --git a/aaa_examples/aaa_by_email_address.lua b/aaa_examples/aaa_by_email_address.lua
index 9fd4588..66466d6 100644
--- a/aaa_examples/aaa_by_email_address.lua
+++ b/aaa_examples/aaa_by_email_address.lua
@@ -30,7 +30,7 @@ local grant_access_to = "*" -- use * for access to all, or specify a (sub)domain
 local useAlternates = false -- also check against alternate email addresses??
 
 -- Is email a valid foocorp email?
-function validateEmail(r, email)
+local function validateEmail(r, email)
     -- do a GLOB match, testing email aginst valid_email
     if r:strcmp_match(valid_email, email) then
         return true
@@ -40,7 +40,7 @@ end
 
 
 -- Get a list of domains the user has private email access to (or wildcard if org member)
-function getRights(r, usr)
+local function getRights(r, usr)
     if not usr.credentials then
         return {}
     end

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/aaa_examples/aaa_by_portal.lua
----------------------------------------------------------------------
diff --git a/aaa_examples/aaa_by_portal.lua b/aaa_examples/aaa_by_portal.lua
index ba62470..0eeaa6f 100644
--- a/aaa_examples/aaa_by_portal.lua
+++ b/aaa_examples/aaa_by_portal.lua
@@ -28,7 +28,7 @@ local valid_portal = "www.googleapis.com"
 local grant_access_to = "*" -- use * for access to all, or specify a (sub)domain to grant
access to
 
 -- Get rights (full or no access)
-function getRights(r, usr)
+local function getRights(r, usr)
     if not usr.credentials then
         return {}
     end

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/aaa_examples/aaa_with_subgroups.lua
----------------------------------------------------------------------
diff --git a/aaa_examples/aaa_with_subgroups.lua b/aaa_examples/aaa_with_subgroups.lua
index 2b11819..62a12aa 100644
--- a/aaa_examples/aaa_with_subgroups.lua
+++ b/aaa_examples/aaa_with_subgroups.lua
@@ -46,7 +46,7 @@ local access_list = {
 }
 
 -- Get rights (full or no access)
-function getRights(r, usr)
+local function getRights(r, usr)
     if not usr.credentials then
         return {}
     end

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/atom.lua
----------------------------------------------------------------------
diff --git a/site/api/atom.lua b/site/api/atom.lua
index cabdff4..caa6b3a 100644
--- a/site/api/atom.lua
+++ b/site/api/atom.lua
@@ -28,7 +28,7 @@ require 'lib/utils'
 local emls_thrd
 
 -- func for fetching all child emails of a parent topic
-function fetchChildren(r, pdoc, c, biglist)
+local function fetchChildren(r, pdoc, c, biglist)
     c = (c or 0) + 1
     if c > 250 then
         return {}

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/email.lua
----------------------------------------------------------------------
diff --git a/site/api/email.lua b/site/api/email.lua
index a3c4705..8c36fa0 100644
--- a/site/api/email.lua
+++ b/site/api/email.lua
@@ -25,7 +25,7 @@ local cross = require 'lib/cross'
 local config = require 'lib/config'
 
 -- anonymizer func
-function anonymize(doc)
+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

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/lib/aaa.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/aaa.lua b/site/api/lib/aaa.lua
index 4d0de9f..d116909 100644
--- a/site/api/lib/aaa.lua
+++ b/site/api/lib/aaa.lua
@@ -20,7 +20,7 @@
 local config = require 'lib/config'
 
 -- Get a list of PMCs the user is a part of
-function getPMCs(r, uid)
+local function getPMCs(r, uid)
     local groups = {}
     local ldapdata = io.popen( ([[ldapsearch -x -LLL "(|(memberUid=%s)(member=uid=%s,ou=people,dc=apache,dc=org))"
cn]]):format(uid,uid) )
     local data = ldapdata:read("*a")
@@ -32,7 +32,7 @@ end
 
 
 -- Is $uid a member of the org?
-function isMember(r, uid)
+local function isMember(r, uid)
     
     -- First, check the 30 minute cache
     local NOWISH = math.floor(os.time() / 1800)
@@ -63,7 +63,7 @@ function isMember(r, uid)
 end
 
 -- Get a list of domains the user has private email access to (or wildcard if org member)
-function getRights(r, usr)
+local function getRights(r, usr)
     if not usr.credentials then
         return {}
     end

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/lib/cross.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/cross.lua b/site/api/lib/cross.lua
index a2fd889..9539ae2 100644
--- a/site/api/lib/cross.lua
+++ b/site/api/lib/cross.lua
@@ -17,7 +17,7 @@
 
 -- cross-server module for making apache and nginx work roughly the same way
 
-function setContentType(r, foo)
+local function setContentType(r, foo)
     if ngx and ngx.header then
         ngx.header['Content-Type'] = foo
     else
@@ -30,7 +30,7 @@ _M = {}
 apr = nil
 pcall(function() apr = require 'apr' end)
 
-function ngstart(handler)
+local function ngstart(handler)
     if ngx then
         _G.apache2 = {
             OK = 0

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/lib/elastic.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/elastic.lua b/site/api/lib/elastic.lua
index a3154f2..c1e0b87 100644
--- a/site/api/lib/elastic.lua
+++ b/site/api/lib/elastic.lua
@@ -65,7 +65,7 @@ local function performRequest(url, query)
 end
 
 -- Standard ES query, returns $size results of any doc of type $doc, sorting by $sitem
-function getHits(query, size, doc, sitem)
+local function getHits(query, size, doc, sitem)
     doc = doc or "mbox"
     sitem = sitem or "epoch"
     size = size or 10
@@ -87,7 +87,7 @@ function getHits(query, size, doc, sitem)
 end
 
 -- Get a single document
-function getDoc (ty, id)
+local function getDoc (ty, id)
     local url = config.es_url  .. ty .. "/" .. id
     local json = performRequest(url)
     if json and json._source then
@@ -101,7 +101,7 @@ end
 
 -- Get results (a'la getHits), but only return email headers, not the body
 -- provides faster transport when we don't need everything
-function getHeaders(query, size, doc)
+local function getHeaders(query, size, doc)
     doc = doc or "mbox"
     size = size or 10
     query = query:gsub(" ", "+")
@@ -118,7 +118,7 @@ function getHeaders(query, size, doc)
 end
 
 -- Same as above, but reverse return order
-function getHeadersReverse(query, size, doc)
+local function getHeadersReverse(query, size, doc)
     doc = doc or "mbox"
     size = size or 10
     query = query:gsub(" ", "+")
@@ -144,7 +144,7 @@ local function contains(table,value)
 end
 
 -- Do a raw ES query with a JSON query
-function raw(query, doctype)
+local function raw(query, doctype)
     doctype = doctype or default_doc
     local url = config.es_url .. doctype .. "/_search"
     local json = performRequest(url, query)
@@ -167,7 +167,7 @@ end
 local scanHasBody = {}
 
 -- Raw query with scroll/scan
-function scan(query, doctype)
+local function scan(query, doctype)
     doctype = doctype or default_doc
     local url = config.es_url .. doctype .. "/_search?search_type=scan&scroll=1m"
     local json = performRequest(url, query)
@@ -184,7 +184,7 @@ function scan(query, doctype)
     return nil
 end
 
-function scroll(sid)
+local function scroll(sid)
     -- We have to do some gsubbing here, as ES expects us to be at the root of the ES URL
     -- But in case we're being proxied, let's just cut off the last part of the URL
     local url = config.es_url:gsub("[^/]+/?$", "") .. "/_search/scroll?scroll=1m&scroll_id="
.. sid
@@ -208,7 +208,7 @@ function scroll(sid)
 end
 
 -- Update a document
-function update(doctype, id, query, consistency)
+local function update(doctype, id, query, consistency)
     doctype = doctype or default_doc
     local url = config.es_url .. doctype .. "/" .. id .. "/_update"
     if consistency then
@@ -219,7 +219,7 @@ function update(doctype, id, query, consistency)
 end
 
 -- Put a new document somewhere
-function index(id, ty, body, consistency)
+local function index(id, ty, body, consistency)
     if not id then
         error("id parameter must be provided", 3)
     end
@@ -231,7 +231,7 @@ function index(id, ty, body, consistency)
     return json or {}
 end
 
-function setDefault(typ)
+local function setDefault(typ)
     default_doc = typ
 end
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/lib/user.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/user.lua b/site/api/lib/user.lua
index 065e835..712517a 100644
--- a/site/api/lib/user.lua
+++ b/site/api/lib/user.lua
@@ -18,7 +18,7 @@ local JSON = require 'cjson'
 local elastic = require 'lib/elastic'
 
 -- Get user data from DB
-function getUser(r, override)
+local function getUser(r, override)
     local ocookie = r:getcookie("ponymail")
     local login = {}
     if override or (ocookie and #ocookie > 43) then
@@ -51,7 +51,7 @@ function getUser(r, override)
 end
 
 -- Update or set up a new user
-function updateUser(r, cid, data)
+local function updateUser(r, cid, data)
     local cookie = r:sha1(r.useragent_ip .. ':' .. (math.random(1,9999999)*os.time()) ..
r:clock())
     
     -- Does this account exists? If so, grab the prefs first
@@ -88,7 +88,7 @@ end
 
 
 -- Log out a user
-function logoutUser(r, usr)
+local function logoutUser(r, usr)
     if usr and usr.cid then
         local js = elastic.get('account', r:sha1(usr.cid))
         js.internal.cookie = 'nil'
@@ -103,7 +103,7 @@ end
 
 
 -- Save preferences
-function savePreferences(r, usr, alts)
+local function savePreferences(r, usr, alts)
     if usr and usr.cid then
         local js = elastic.get('account', r:sha1(usr.cid))
         js.preferences = usr.preferences
@@ -115,7 +115,7 @@ function savePreferences(r, usr, alts)
 end
 
 -- Save favorites
-function saveFavorites(r, usr)
+local function saveFavorites(r, usr)
     if usr and usr.cid then
         local js = elastic.get('account', r:sha1(usr.cid))
         js.favorites = usr.favorites

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/mbox.lua
----------------------------------------------------------------------
diff --git a/site/api/mbox.lua b/site/api/mbox.lua
index 3bffafd..bd01364 100644
--- a/site/api/mbox.lua
+++ b/site/api/mbox.lua
@@ -27,7 +27,7 @@ local days = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 
 }
 
-function leapYear(year)
+local function leapYear(year)
     if (year % 4 == 0) then
         if (year%100 == 0)then                
             if (year %400 == 0) then                    
@@ -51,7 +51,7 @@ end
       for <archive-asf-public-internal@cust-asf2.ponee.io>; Fri,  9 Dec 2016 13:48:01
+0100 (CET)
     ...
 ]]--
-function getFromLine(r, source)
+local function getFromLine(r, source)
     local replyTo = source:match("Return%-Path: +<(.-)>")
     if not replyTo then replyTo = "MAILER-DAEMON" end
 

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/static.lua
----------------------------------------------------------------------
diff --git a/site/api/static.lua b/site/api/static.lua
index 6068986..6f6ae98 100644
--- a/site/api/static.lua
+++ b/site/api/static.lua
@@ -28,7 +28,7 @@ local days = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 
 }
 
-function sortEmail(thread)
+local function sortEmail(thread)
     if thread.children and type(thread.children) == "table" then
         table.sort (thread.children, function (k1, k2) return k1.epoch > k2.epoch end
)
         for k, v in pairs(thread.children) do
@@ -37,7 +37,7 @@ function sortEmail(thread)
     end
 end
 
-function showThreads(r, thread, emails)
+local function showThreads(r, thread, emails)
     r:puts("<ul>\n")
     for k, v in pairs(thread.children) do
         local email = nil

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/stats.lua
----------------------------------------------------------------------
diff --git a/site/api/stats.lua b/site/api/stats.lua
index e8cf3e1..8e009f7 100644
--- a/site/api/stats.lua
+++ b/site/api/stats.lua
@@ -28,7 +28,7 @@ local days = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31 
 }
 
-function sortEmail(thread)
+local function sortEmail(thread)
     if thread.children and type(thread.children) == "table" then
         table.sort (thread.children, function (k1, k2) return k1.epoch > k2.epoch end
)
         for k, v in pairs(thread.children) do
@@ -39,7 +39,7 @@ end
 
 -- findSubject: match an email with an earlier one with the same topic
 -- used for orphaned emails
-function findSubject(gblob, blob, subject, epoch, maxAge)
+local function findSubject(gblob, blob, subject, epoch, maxAge)
     local subj = subject:gsub("^[A-Za-z]:%s+", "")
     for k, v in pairs(blob) do
         if v.subject and v.subject == subj and v.epoch < epoch and (not maxAge or (maxAge
and v.epoch >= (epoch - (maxAge*86400)))) then
@@ -52,7 +52,7 @@ function findSubject(gblob, blob, subject, epoch, maxAge)
     return nil
 end
 
-function leapYear(year)
+local function leapYear(year)
     if (year % 4 == 0) then
         if (year%100 == 0)then                
             if (year %400 == 0) then                    

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/f40dd3c6/site/api/thread.lua
----------------------------------------------------------------------
diff --git a/site/api/thread.lua b/site/api/thread.lua
index dcbb363..9c92ac8 100644
--- a/site/api/thread.lua
+++ b/site/api/thread.lua
@@ -30,7 +30,7 @@ local emls_thrd
 require 'lib/utils'
 
 -- anonymizer func
-function anonymize(doc)
+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
@@ -44,7 +44,7 @@ function anonymize(doc)
 end
 
 -- func that fetches all children of an original topic email thingy
-function fetchChildren(r, pdoc, c, biglist, rights, account)
+local function fetchChildren(r, pdoc, c, biglist, rights, account)
     c = (c or 0) + 1
     -- don't fetch more than 250 subtrees, we don't want to nest ad nauseam
     if c > 250 then


Mime
View raw message