/usr/lib/ruby/1.8/samizdat/antispam.rb is in libsamizdat-ruby1.8 0.6.2-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # Samizdat antispam filter
#
# Copyright (c) 2002-2009 Dmitry Borodaenko <angdraug@debian.org>
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU General Public License version 3 or later.
#
# vim: et sw=2 sts=2 ts=8 tw=0
require 'open-uri'
class Antispam
# only supply option values from safe source
#
# valid options:
#
# * check_roles - list of roles that should be subjected to antispam
# filtering
#
# * url - a URL from where a list of filtering regexps can be downloaded
#
# * exclude - a list of regexps used to drop items from regexp list
#
def initialize(options)
if options.kind_of?(Hash) and options['url'] and
options['check_roles'].kind_of?(Array) and options['check_roles'].size > 0
@roles = options['check_roles']
@regexp_list = load_regexp_list(options)
else
@roles = []
end
end
# check against a list of known spam patterns if it's enabled for this role
#
def spam?(role, text)
return false unless @roles.include?(role)
@regexp_list.each do |re|
if text =~ re
return true
end
end
false
end
private
# NB: define Kernel#log_exception to report failure to load the list of
# regexps from the supplied URL
#
def load_regexp_list(options)
if options['exclude'].kind_of? Array
exclude = Regexp.new(
options['exclude'].collect {|s| Regexp.escape(s) }.join('|')
).freeze
end
begin
Kernel.open(options['url'].untaint) {|f| f.read }
rescue => error
# report error when running from under Samizdat
log_exception(error) if Kernel.respond_to? :log_exception
# default to 68-char "GTUBE" spamstring, see
# http://spamassassin.apache.org/gtube/
'XJS\*C4JDBQADN1\.NSBN3\*2IDNEN\*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL\*C\.34X'
end.split(/[\r\n]+/).collect do |line|
line.gsub!(/\s*#.*\z/, '')
if line.size > 6 and
line !~ /\(\?\</ and # (?< ) not supported in Ruby
(exclude.nil? or line !~ exclude)
line
end
end.compact.collect do |line|
Regexp.new(line).freeze
end
end
end
|