Class: MailDiode::AliasFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/maildiode-plugins/alias.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ AliasFilter

Returns a new instance of AliasFilter.



18
19
20
21
# File 'lib/maildiode-plugins/alias.rb', line 18

def initialize(settings)
	@aliases = []
	load_settings(settings)
end

Instance Method Details

#load_settings(settings) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/maildiode-plugins/alias.rb', line 40

def load_settings(settings)
	settings.get_settings('alias').each do | setting |
		pattern = setting.key
		target = setting.value
		@aliases << [pattern, target]
		MailDiode::log_debug "  #{pattern} -> #{target}"
	end
end

#process(filterable_data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/maildiode-plugins/alias.rb', line 23

def process(filterable_data)
	recipient = filterable_data.recipient
	@aliases.each do | pattern_and_target |
		pattern = pattern_and_target[0]
		target = pattern_and_target[1]
		MailDiode::log_debug "alias checking: #{pattern}"
		re = Regexp.new(pattern, Regexp::IGNORECASE)
		if(recipient.match(re))
			MailDiode::log_debug "Alias #{recipient} --> #{target}"
			filterable_data.recipient = target
			return
		end
	end
	
	MailDiode::log_debug "No alias for #{recipient}"
end