]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support using request headers in settings 1507/head
authorAndrew Lewis <nerf@judo.za.org>
Thu, 9 Mar 2017 16:06:59 +0000 (18:06 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 9 Mar 2017 16:06:59 +0000 (18:06 +0200)
 - Issue: #1502

src/plugins/lua/settings.lua

index a3a41440a61ed60e429bab1f159097125436ce0e..758bc9b94b84ecbdc76e35352bc08bcca202361d 100644 (file)
@@ -225,6 +225,19 @@ local function check_settings(task)
       end
     end
 
+    if rule['request_header'] then
+      for k, v in pairs(rule['request_header']) do
+        local h = task:get_request_header(k)
+        res = (h and v:match(h))
+        if res then
+          break
+        end
+      end
+      if not res then
+        return nil
+      end
+    end
+
     if res then
       if rule['whitelist'] then
         rule['apply'] = {whitelist = true}
@@ -445,6 +458,19 @@ local function process_settings_table(tbl)
     if elt['authenticated'] then
       out['authenticated'] = true
     end
+    if elt['request_header'] then
+      local rho = {}
+      for k, v in pairs(elt['request_header']) do
+        local re = rspamd_regexp.get_cached(v)
+        if not re then
+          re = rspamd_regexp.create_cached(v)
+        end
+        if re then
+          rho[k] = re
+        end
+      end
+      out['request_header'] = rho
+    end
 
     -- Now we must process actions
     if elt['symbols'] then out['symbols'] = elt['symbols'] end