Class: Gluttonberg::Content::DespamilatorFilter::Emails

Inherits:
Gluttonberg::Content::Despamilator::Filter show all
Defined in:
lib/gluttonberg/content/despamilator/filter/emails.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



13
14
15
# File 'lib/gluttonberg/content/despamilator/filter/emails.rb', line 13

def description
  'Detects each emails in a string'
end

#nameObject



9
10
11
# File 'lib/gluttonberg/content/despamilator/filter/emails.rb', line 9

def name
  'Emails'
end

#parse(subject) ⇒ Object



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
# File 'lib/gluttonberg/content/despamilator/filter/emails.rb', line 17

def parse subject
  @email_regex ||= begin
    email_name_regex  = '[A-Z0-9_\.%\+\-\']+'
    domain_head_regex = '(?:[A-Z0-9\-]+\.)+'
    domain_tld_regex  = '(?:[A-Z]{2,4}|museum|travel)'
    /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
  end

  comment_email_as_spam = Gluttonberg::Setting.get_setting("comment_email_as_spam")
  if comment_email_as_spam == "Yes"
    text = subject.text.strip
    subject.register_match!({
     :score => 1.0, :filter => self
    }) if @email_regex.match(text)
  end

  comment_number_of_emails_allowed = Gluttonberg::Setting.get_setting("comment_number_of_emails_allowed")
  if !comment_number_of_emails_allowed.blank? && comment_number_of_emails_allowed.to_i > 0
    comment_number_of_emails_allowed = comment_number_of_emails_allowed.to_i
    subject.text.split(/%s/).each do |word|
      subject.register_match!({
       :score => (1.0/comment_number_of_emails_allowed), :filter => self
      }) if @email_regex.match(word)
    end
  end

end