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.

subject_checks.lua 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --[[
  2. Copyright (c) 2022, Vsevolod Stakhov <vsevolod@rspamd.com>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ]]--
  13. local rspamd_regexp = require "rspamd_regexp"
  14. local util = require "rspamd_util"
  15. -- Uncategorized rules
  16. local subject_re = rspamd_regexp.create('/^(?:(?:Re|Fwd|Fw|Aw|Antwort|Sv):\\s*)+(.+)$/i')
  17. local function test_subject(task, check_function, rate)
  18. local function normalize_linear(a, x)
  19. local f = a * x
  20. return true, ((f < 1) and f or 1), tostring(x)
  21. end
  22. local sbj = task:get_header('Subject')
  23. if sbj then
  24. local stripped_subject = subject_re:search(sbj, false, true)
  25. if stripped_subject and stripped_subject[1] and stripped_subject[1][2] then
  26. sbj = stripped_subject[1][2]
  27. end
  28. local l = util.strlen_utf8(sbj)
  29. if check_function(sbj, l) then
  30. return normalize_linear(rate, l)
  31. end
  32. end
  33. return false
  34. end
  35. rspamd_config.SUBJ_ALL_CAPS = {
  36. callback = function(task)
  37. local caps_test = function(sbj)
  38. return util.is_uppercase(sbj)
  39. end
  40. return test_subject(task, caps_test, 1.0 / 40.0)
  41. end,
  42. score = 3.0,
  43. group = 'subject',
  44. type = 'mime',
  45. description = 'Subject contains mostly capital letters'
  46. }
  47. rspamd_config.LONG_SUBJ = {
  48. callback = function(task)
  49. local length_test = function(_, len)
  50. return len > 200
  51. end
  52. return test_subject(task, length_test, 1.0 / 400.0)
  53. end,
  54. score = 3.0,
  55. group = 'subject',
  56. type = 'mime',
  57. description = 'Subject is very long'
  58. }