]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Banish table.maxn from Lua parts 923/head
authorAndrew Lewis <nerf@judo.za.org>
Thu, 1 Sep 2016 08:22:50 +0000 (10:22 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 1 Sep 2016 08:22:50 +0000 (10:22 +0200)
rules/rspamd.classifiers.lua
src/lua/lua_mimepart.c
src/plugins/lua/emails.lua
src/plugins/lua/forged_recipients.lua
src/plugins/lua/hfilter.lua
src/plugins/lua/ratelimit.lua

index c509ef23d5d7ed57a7eb4ac3f942cf681164e612..77f506ee828c32e723ce684c951d8d324d925bdd 100644 (file)
@@ -34,8 +34,7 @@ local function get_specific_statfiles(classifier, task)
        local st_many = classifier:get_statfile_by_label(many_recipients_label)
        if st_many then
                rcpt = task:get_recipients(2)
-               if rcpt and table.maxn(rcpt) > 5 then
-                       print(table.maxn(rcpt))
+               if rcpt and #rcpt > 5 then
                        table.foreach(st_many, function(i,v) table.insert(spec_st,v) end)
                end
        end
@@ -43,7 +42,7 @@ local function get_specific_statfiles(classifier, task)
        local st_undisc = classifier:get_statfile_by_label(undisclosed_recipients_label)
        if st_undisc then
                rcpt = task:get_recipients(2)
-               if rcpt and table.maxn(rcpt) == 0 then
+               if rcpt and #rcpt == 0 then
                        table.foreach(st_undisc, function(i,v) table.insert(spec_st,v) end)
                end
        end
@@ -64,7 +63,7 @@ local function get_specific_statfiles(classifier, task)
                end
        end
        
-       if table.maxn(spec_st) > 1 then
+       if #spec_st > 1 then
                return spec_st
        else
                return nil
@@ -109,7 +108,7 @@ classifiers['bayes'] = function(classifier, task, is_learn, is_spam)
                                end
                        end
                end
-               if table.maxn(selected) > 1 then
+               if #selected > 1 then
                        return selected
                end
        end
@@ -125,7 +124,7 @@ classifiers['bayes'] = function(classifier, task, is_learn, is_spam)
                        end
                end
        end
-       if table.maxn(selected) > 1 then
+       if #selected > 1 then
                return selected
        end
        
index b8f7d8f85e0018021ff808834c5c016398e73995..d519cccbe75e4add6d6547b5832bfdfd5fb129f9 100644 (file)
@@ -151,7 +151,7 @@ static const struct luaL_reg textpartlib_m[] = {
 @example
 rspamd_config.MISSING_CONTENT_TYPE = function(task)
        local parts = task:get_parts()
-       if parts and table.maxn(parts) > 1 then
+       if parts and #parts > 1 then
                -- We have more than one part
                for _,p in ipairs(parts) do
                        local ct = p:get_header('Content-Type')
index 862d82725930c9c8c57fbcdcc7aaf137c8d17b2c..9d9a54d03c2bda3437a28b170705ade2fce99e09 100644 (file)
@@ -107,7 +107,7 @@ if opts and type(opts) == 'table' then
   end
 end
 
-if table.maxn(rules) > 0 then
+if #rules > 0 then
   -- add fake symbol to check all maps inside a single callback
   local id = rspamd_config:register_symbol({
     type = 'callback',
index a9347a685a3b0cd994a677f9812e9c209915ac65..957491a56df4f898a28b738ec07d0b27f28aea6c 100644 (file)
@@ -30,9 +30,9 @@ local function check_forged_headers(task)
     local mime_rcpt = task:get_recipients(2)
     local count = 0
     if mime_rcpt then
-      count = table.maxn(mime_rcpt)
+      count = #mime_rcpt
     end
-    if count > 0 and count < table.maxn(smtp_rcpt) then
+    if count > 0 and count < #smtp_rcpt then
       task:insert_result(symbol_rcpt, 1)
     elseif count > 0 then
       -- Find pair for each smtp recipient recipient in To or Cc headers
index 7db6eab5f7c3830b12ae3ee1aa5bc1965d88470a..34a679641581a42d9a1dceee8cd04758548f61d9 100644 (file)
@@ -395,7 +395,7 @@ local function hfilter(task)
       --FROM host check
       for _,fr in ipairs(from) do
         local fr_split = rspamd_str_split(fr['addr'], '@')
-        if table.maxn(fr_split) == 2 then
+        if #fr_split == 2 then
           check_host(task, fr_split[2], 'FROMHOST', '', '')
           if fr_split[1] == 'postmaster' then
             frombounce = true
@@ -414,7 +414,7 @@ local function hfilter(task)
   if config['rcpt_enabled'] then
     local rcpt = task:get_recipients()
     if rcpt then
-      local count_rcpt = table.maxn(rcpt)
+      local count_rcpt = #rcpt
       if frombounce then
         if count_rcpt > 1 then
           task:insert_result('HFILTER_RCPT_BOUNCEMOREONE', 1.00)
@@ -428,7 +428,7 @@ local function hfilter(task)
     local message_id = task:get_message_id()
     if message_id then
       local mid_split = rspamd_str_split(message_id, '@')
-      if table.maxn(mid_split) == 2 and not string.find(mid_split[2], 'local') then
+      if #mid_split == 2 and not string.find(mid_split[2], 'local') then
         check_host(task, mid_split[2], 'MID')
       end
     end
@@ -509,6 +509,6 @@ if config['url_enabled'] then
 end
 
 --dumper(symbols_enabled)
-if table.maxn(symbols_enabled) > 0 then
+if #symbols_enabled > 0 then
   rspamd_config:register_symbols(hfilter, 1.0, "HFILTER", symbols_enabled);
 end
index b80a122f174cb5e1a71602ae9ffa8aa63a7d3a28..d8e53d4d00ed54c054e3104bb666ee15ab20d2b8 100644 (file)
@@ -414,7 +414,7 @@ local function parse_limit(str)
     limit[2] = tonumber(rate)
   end
 
-  if table.maxn(params) ~= 3 then
+  if #params ~= 3 then
     rspamd_logger.errx(rspamd_config, 'invalid limit definition: ' .. str)
     return
   end