]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Reformat dcc plugin code
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 6 Apr 2016 12:14:19 +0000 (13:14 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 6 Apr 2016 12:14:19 +0000 (13:14 +0100)
src/plugins/lua/dcc.lua

index c644deb0d266f9966e7a5903e24c2011f212297d..9dc7a8ea9d190e88e255e678c3abbcc3ea4adec1 100644 (file)
@@ -24,106 +24,106 @@ local tcp = require "rspamd_tcp"
 require "fun" ()
 
 local function check_dcc (task)
-    -- Connection
-    local client = '0.0.0.0'
-    local client_ip = task:get_from_ip()
-    if client_ip and client_ip:is_valid() then
-        client = client_ip:to_string()
-    end
-    local client_host = task:get_hostname()
-    if client_host and client_host ~= 'unknown' then
-        client = client .. "\r" .. client_host
-    end
+  -- Connection
+  local client = '0.0.0.0'
+  local client_ip = task:get_from_ip()
+  if client_ip and client_ip:is_valid() then
+    client = client_ip:to_string()
+  end
+  local client_host = task:get_hostname()
+  if client_host and client_host ~= 'unknown' then
+    client = client .. "\r" .. client_host
+  end
 
-    -- HELO
-    local helo = task:get_helo() or ''
+  -- HELO
+  local helo = task:get_helo() or ''
 
-    -- Envelope From
-    local ef = task:get_from()
-    local envfrom = 'test@example.com'
-    if ef and ef[1] then
-        envfrom = ef[1]['addr']
-    end
+  -- Envelope From
+  local ef = task:get_from()
+  local envfrom = 'test@example.com'
+  if ef and ef[1] then
+    envfrom = ef[1]['addr']
+  end
 
-    -- Envelope To
-    local envrcpt = 'test@example.com'
-    local rcpts = task:get_recipients();
-    if rcpts then
-      local r = table.concat(totable(map(function(rcpt)
-        return rcpt['addr'] end,
-        rcpts)), '\n')
-      if r then
-          envrcpt = r
-      end
+  -- Envelope To
+  local envrcpt = 'test@example.com'
+  local rcpts = task:get_recipients();
+  if rcpts then
+    local r = table.concat(totable(map(function(rcpt)
+      return rcpt['addr'] end,
+    rcpts)), '\n')
+    if r then
+      envrcpt = r
     end
+  end
 
-    -- Callback function to receive async result from DCC
-    local function cb(err, data)
-        if (err) then
-            logger.warnx(task, 'DCC error: %1', err)
-            return
-        end
-        -- Parse the response
-        local _,_,result,disposition,header = tostring(data):find("(.-)\n(.-)\n(.-)\n")
-        logger.debugx(task, 'DCC result=%1 disposition=%2 header="%3"',
-          result, disposition, header)
+  -- Callback function to receive async result from DCC
+  local function cb(err, data)
+    if (err) then
+      logger.warnx(task, 'DCC error: %1', err)
+      return
+    end
+    -- Parse the response
+    local _,_,result,disposition,header = tostring(data):find("(.-)\n(.-)\n(.-)\n")
+    logger.debugx(task, 'DCC result=%1 disposition=%2 header="%3"',
+      result, disposition, header)
 
-        if header then
-          local _,_,info = header:find("; (.-)$")
-          if (result == 'A') then
-              -- Accept
-          elseif (result == 'G') then
-              -- Greylist
-          elseif (result == 'R') then
-              -- Reject
-              task:insert_result(symbol_bulk, 1.0, info)
-          elseif (result == 'S') then
-              -- Accept for some recipients only
-          elseif (result == 'T') then
-              -- Temporary failure
-              logger.warnx(task, 'DCC returned a temporary failure result')
-          else
-              -- Unknown result
-              logger.warnx(task, 'DCC result error: %1', result);
-          end
-        end
+    if header then
+      local _,_,info = header:find("; (.-)$")
+      if (result == 'A') then
+      -- Accept
+      elseif (result == 'G') then
+      -- Greylist
+      elseif (result == 'R') then
+        -- Reject
+        task:insert_result(symbol_bulk, 1.0, info)
+      elseif (result == 'S') then
+      -- Accept for some recipients only
+      elseif (result == 'T') then
+        -- Temporary failure
+        logger.warnx(task, 'DCC returned a temporary failure result')
+      else
+        -- Unknown result
+        logger.warnx(task, 'DCC result error: %1', result);
+      end
     end
+  end
 
-    -- Build the DCC query
-    -- https://www.dcc-servers.net/dcc/dcc-tree/dccifd.html#Protocol
-    local data = {
-        "header\n",
-        client .. "\n",
-        helo .. "\n",
-        envfrom .. "\n",
-        envrcpt .. "\n",
-        "\n",
-        task:get_content()
-    }
+  -- Build the DCC query
+  -- https://www.dcc-servers.net/dcc/dcc-tree/dccifd.html#Protocol
+  local data = {
+    "header\n",
+    client .. "\n",
+    helo .. "\n",
+    envfrom .. "\n",
+    envrcpt .. "\n",
+    "\n",
+    task:get_content()
+  }
 
-    logger.debugx(task, 'sending to dcc: client=%1 helo="%2" envfrom="%3" envrcpt="%4"',
-                 client, helo, envfrom, envrcpt)
+  logger.debugx(task, 'sending to dcc: client=%1 helo="%2" envfrom="%3" envrcpt="%4"',
+    client, helo, envfrom, envrcpt)
 
-    tcp.request({
-        task = task,
-        host = opts['host'],
-        port = opts['port'] or 1,
-        shutdown = true,
-        data = data,
-        callback = cb
-    })
+  tcp.request({
+    task = task,
+    host = opts['host'],
+    port = opts['port'] or 1,
+    shutdown = true,
+    data = data,
+    callback = cb
+  })
 end
 
 -- Configuration
 if opts and opts['host'] then
-    rspamd_config:register_symbol(symbol_bulk, 1.0, check_dcc)
-    rspamd_config:set_metric_symbol({
-      group = 'dcc',
-      score = 2.0,
-      description = 'Detected as bulk mail by DCC',
-      one_shot = true,
-      name = symbol_bulk
-    })
+  rspamd_config:register_symbol(symbol_bulk, 1.0, check_dcc)
+  rspamd_config:set_metric_symbol({
+    group = 'dcc',
+    score = 2.0,
+    description = 'Detected as bulk mail by DCC',
+    one_shot = true,
+    name = symbol_bulk
+  })
 else
-    logger.infox('DCC module not configured');
+  logger.infox('DCC module not configured');
 end