Class: SubjectFilter

Inherits:
BasicFilter show all
Defined in:
lib/filter/subject_filter.rb

Overview

Checks the subject of the incomming message for a specific password and rejects the mail if the passwort is not present.

Instance Method Summary collapse

Constructor Details

#initialize(password, charset = "UTF-8") ⇒ SubjectFilter

Returns a new instance of SubjectFilter.



5
6
7
8
# File 'lib/filter/subject_filter.rb', line 5

def initialize(password, charset = "UTF-8")
  super(charset)
  @password = password
end

Instance Method Details

#passed_filter?(tmail) ⇒ Boolean

Returns true if password is present. Password will be removed from the subject.

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/filter/subject_filter.rb', line 12

def passed_filter?(tmail)
  password_is_present = !tmail.subject.match(@password).nil?

  password_matcher = Regexp.new("#{@password}\s+")
  
  if password_is_present then
    # Remove password from the subject
    tmail.subject = tmail.subject(@charset).gsub(password_matcher, "")
  end
  
  return password_is_present
end