You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

misc.lua 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --[[
  2. Copyright (c) 2011-2015, Vsevolod Stakhov <vsevolod@highsecure.ru>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice, this
  7. list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  12. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  13. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  14. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  15. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  16. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  17. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  18. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  20. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. ]]--
  22. -- This is main lua config file for rspamd
  23. local util = require "rspamd_util"
  24. local reconf = config['regexp']
  25. -- Uncategorized rules
  26. -- Local rules
  27. local r_bgcolor = '/BGCOLOR=/iP'
  28. local r_font_color = '/font color=[\\"\']?\\#FFFFFF[\\"\']?/iP'
  29. reconf['R_WHITE_ON_WHITE'] = string.format('(!(%s) & (%s))', r_bgcolor, r_font_color)
  30. reconf['R_FLASH_REDIR_IMGSHACK'] = '/^(?:http:\\/\\/)?img\\d{1,5}\\.imageshack\\.us\\/\\S+\\.swf/U'
  31. -- Different text parts
  32. rspamd_config.R_PARTS_DIFFER = function(task)
  33. local distance = task:get_mempool():get_variable('parts_distance', 'int')
  34. if distance then
  35. local nd = tonumber(distance)
  36. if nd < 50 then
  37. local score = 1 - util.tanh(nd / 100.0)
  38. task:insert_result('R_PARTS_DIFFER', score, tostring(nd) .. '%')
  39. end
  40. end
  41. return false
  42. end
  43. -- Date issues
  44. rspamd_config.MISSING_DATE = function(task)
  45. if rspamd_config:get_api_version() >= 5 then
  46. if not task:get_header_raw('Date') then
  47. return true
  48. end
  49. end
  50. return false
  51. end
  52. rspamd_config.DATE_IN_FUTURE = function(task)
  53. if rspamd_config:get_api_version() >= 5 then
  54. local dm = task:get_date{format = 'message'}
  55. local dt = task:get_date{format = 'connect'}
  56. -- An 2 hour
  57. if dm > 0 and dm - dt > 7200 then
  58. return true
  59. end
  60. end
  61. return false
  62. end
  63. rspamd_config.DATE_IN_PAST = function(task)
  64. if rspamd_config:get_api_version() >= 5 then
  65. local dm = task:get_date{format = 'message', gmt = true}
  66. local dt = task:get_date{format = 'connect', gmt = true}
  67. -- A day
  68. if dm > 0 and dt - dm > 86400 then
  69. return true
  70. end
  71. end
  72. return false
  73. end