]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add more ratelimits: by digest, by attachments data, by filenames
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Aug 2018 11:17:15 +0000 (12:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Aug 2018 11:17:15 +0000 (12:17 +0100)
src/plugins/lua/ratelimit.lua

index c6caf6d41d8c69ba3030d9bfcf9c346f94541d34..59f3c052295b4494ffdeef9a945cf7b9dd32d946 100644 (file)
@@ -335,6 +335,48 @@ local keywords = {
       return task:get_principal_recipient()
     end,
   },
+  ['digest'] = {
+    ['get_value'] = function(task)
+      return task:get_digest()
+    end,
+  },
+  ['attachments'] = {
+    ['get_value'] = function(task)
+      local parts = task:get_parts() or E
+      local digests = {}
+
+      for _,p in ipairs(parts) do
+        if p:get_filename() then
+          table.insert(digests, p:get_digest())
+        end
+      end
+
+      if #digests > 0 then
+        return table.concat(digests, '')
+      end
+
+      return nil
+    end,
+  },
+  ['files'] = {
+    ['get_value'] = function(task)
+      local parts = task:get_parts() or E
+      local files = {}
+
+      for _,p in ipairs(parts) do
+        local fname = p:get_filename()
+        if fname then
+          table.insert(files, fname)
+        end
+      end
+
+      if #files > 0 then
+        return table.concat(files, ':')
+      end
+
+      return nil
+    end,
+  },
 }
 
 local function gen_rate_key(task, rtype, bucket)