11
12
13
14
15
16
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
44
|
# File 'lib/catch_all.rb', line 11
def enable(*to_addresses)
to_addresses = to_addresses.flatten.compact
if to_addresses.length == 0
Kernel.warn("No email addresses passed to ActionMailer::CatchAll!")
end
if enabled?
disable
end
ActionMailer::Base.class_eval do
alias_method :mail_aliased_from_action_mailer_staging, :mail
define_method :mail do |*args, &block|
mailer = mail_aliased_from_action_mailer_staging(*args, &block)
to_values = Array(mailer[:to]).map do |field|
field.value
end
mailer['X-Action-Mailer-Staging-Original-Email-To'] = to_values.inspect
selected_to_addresses = to_values.select { |to| to_addresses.include?(to) }
if selected_to_addresses.any?
mailer[:to] = selected_to_addresses
else
mailer[:to] = to_addresses
end
mailer
end
end
end
|