]> source.dussan.org Git - rspamd.git/commitdiff
Make R_EMPTY_IMAGE tutorial function.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 19:40:41 +0000 (20:40 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jul 2015 19:40:41 +0000 (20:40 +0100)
conf/lua/html.lua
src/lua/lua_html.c

index 951cc4952c413dcc28ebbe3445709a7024556f92..1b218357b063be5debc62f4c5640fb9bcf8c3bb8 100644 (file)
@@ -53,20 +53,20 @@ rspamd_config.HTML_SHORT_LINK_IMG_3 = function(task)
   return check_html_image(task, 1536, 2048)
 end
 rspamd_config.R_EMPTY_IMAGE = function(task)
-  local tp = task:get_text_parts()
+  local tp = task:get_text_parts() -- get text parts in a message
   
-  for _,p in ipairs(tp) do
-    if p:is_html() then
-      local hc = p:get_html()
-      local len = p:get_length()
+  for _,p in ipairs(tp) do -- iterate over text parts array using `ipairs`
+    if p:is_html() then -- if the current part is html part
+      local hc = p:get_html() -- we get HTML context
+      local len = p:get_length() -- and part's length
       
-      if len < 50 then
-        local images = hc:get_images()
+      if len < 50 then -- if we have a part that has less than 50 bytes of text
+        local images = hc:get_images() -- then we check for HTML images
         
-        if images then
-          for _,i in ipairs(images) do
-            if i['height'] + i['width'] >= 400 then
-              return true
+        if images then -- if there are images
+          for _,i in ipairs(images) do -- then iterate over images in the part
+            if i['height'] + i['width'] >= 400 then -- if we have a large image
+              return true -- add symbol
             end
           end
         end
index 79abc0a3979bcbcf7ec49a55ec5fc8f2dd55e270..855904c38b690d1056411edbfc26ce97c4ee247f 100644 (file)
  * This module provides different methods to access HTML tags. To get HTML context
  * from an HTML part you could use method `part:get_html()`
  * @example
-rspamd_config.R_HTML_IMAGE = function (task)
-       parts = task:get_text_parts()
-       if parts then
-               for _,part in ipairs(parts) do
-                       if part:is_html() then
-                               local html = part:get_html()
-                               -- Do something with html
-                       end
-               end
-       end
-       return false
+rspamd_config.R_EMPTY_IMAGE = function(task)
+  local tp = task:get_text_parts() -- get text parts in a message
+
+  for _,p in ipairs(tp) do -- iterate over text parts array using `ipairs`
+    if p:is_html() then -- if the current part is html part
+      local hc = p:get_html() -- we get HTML context
+      local len = p:get_length() -- and part's length
+
+      if len < 50 then -- if we have a part that has less than 50 bytes of text
+        local images = hc:get_images() -- then we check for HTML images
+
+        if images then -- if there are images
+          for _,i in ipairs(images) do -- then iterate over images in the part
+            if i['height'] + i['width'] >= 400 then -- if we have a large image
+              return true -- add symbol
+            end
+          end
+        end
+      end
+    end
+  end
 end
  */