Sha256: 2e405501c02be7e378899da6955633cca7e4fce864f6f29cf3c00a8c4d5f167e

Contents?: true

Size: 1.49 KB

Versions: 12

Compression:

Stored size: 1.49 KB

Contents

module Gluttonberg
  module Content
    require 'despamilator/filter'

    module DespamilatorFilter

      class Emails < Despamilator::Filter

        def name
          'Emails'
        end

        def description
          'Detects each emails in a string'
        end

        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

      end

    end
  end #Content
end #Gluttonberg

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gluttonberg-core-3.0.2 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-3.0.1 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-3.0.0 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.6.4 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.6.3 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.6.2 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.6.1 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.6.0 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.5.9 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.5.8 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.5.7 lib/gluttonberg/content/despamilator/filter/emails.rb
gluttonberg-core-2.5.6 lib/gluttonberg/content/despamilator/filter/emails.rb