Class: RecipientInterceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/recipient_interceptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(recipients, opts = {}) ⇒ RecipientInterceptor

Returns a new instance of RecipientInterceptor.



4
5
6
7
8
9
10
11
12
# File 'lib/recipient_interceptor.rb', line 4

def initialize(recipients, opts = {})
  @recipients = if recipients.respond_to?(:split)
    recipients.split(",")
  else
    recipients
  end

  @subject_prefix = opts[:subject_prefix]
end

Instance Method Details

#delivering_email(msg) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/recipient_interceptor.rb', line 14

def delivering_email(msg)
  if @subject_prefix.respond_to?(:call)
    msg.subject = "#{@subject_prefix.call(msg)} #{msg.subject}"
  elsif @subject_prefix
    msg.subject = "#{@subject_prefix} #{msg.subject}"
  end

  msg.header["X-Intercepted-To"] = msg.to || []
  msg.header["X-Intercepted-Cc"] = msg.cc || []
  msg.header["X-Intercepted-Bcc"] = msg.bcc || []

  msg.to = @recipients
  msg.cc = nil if msg.cc
  msg.bcc = nil if msg.bcc
end