Class: SpamProtection

Inherits:
Object
  • Object
show all
Defined in:
lib/spam_protection.rb

Constant Summary collapse

IP_RBLS =
["opm.blitzed.us", "bsb.empty.us"].freeze
HOST_RBLS =
["multi.surbl.org", "bsb.empty.us"].freeze
SECOND_LEVEL =
%w(co com net org gov).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_blog) ⇒ SpamProtection

Returns a new instance of SpamProtection.



12
13
14
# File 'lib/spam_protection.rb', line 12

def initialize(a_blog)
  self.this_blog = a_blog
end

Instance Attribute Details

#this_blogObject

Returns the value of attribute this_blog.



10
11
12
# File 'lib/spam_protection.rb', line 10

def this_blog
  @this_blog
end

Instance Method Details

#is_spam?(string) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spam_protection.rb', line 16

def is_spam?(string)
  return false unless this_blog.sp_global
  return false if string.blank?

  reason = catch(:hit) do
    case string
    when Format::IP_ADDRESS then scan_ip(string)
    when Format::HTTP_URI then scan_uris([string])
    else scan_text(string)
    end
  end

  if reason
    logger.info("[SP] Hit: #{reason}")
    true
  end
end