Module: SendGridMailer::Interceptor::RecipientInterceptor

Defined in:
lib/send_grid_mailer/interceptor/recipient_interceptor.rb

Class Method Summary collapse

Class Method Details

.add_custom_headers(sg_definition) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/send_grid_mailer/interceptor/recipient_interceptor.rb', line 30

def self.add_custom_headers(sg_definition)
  {
    'X-Intercepted-To' => sg_definition.personalization.tos || [],
    'X-Intercepted-Cc' => sg_definition.personalization.ccs || [],
    'X-Intercepted-Bcc' => sg_definition.personalization.bccs || []
  }.each do |header, addresses|
    addresses_str = addresses.map { |a| a["email"] }.join(", ")
    sg_definition.add_header(header, addresses_str)
  end
end

.add_recipients(sg_definition, interceptor) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/send_grid_mailer/interceptor/recipient_interceptor.rb', line 22

def self.add_recipients(sg_definition, interceptor)
  recipients = interceptor.instance_variable_get(:@recipients)
  sg_definition.clean_recipients(:to)
  sg_definition.clean_recipients(:cc)
  sg_definition.clean_recipients(:bcc)
  sg_definition.set_recipients(:to, recipients)
end

.add_subject_prefix(sg_definition, interceptor) ⇒ Object



16
17
18
19
20
# File 'lib/send_grid_mailer/interceptor/recipient_interceptor.rb', line 16

def self.add_subject_prefix(sg_definition, interceptor)
  subject_prefix = interceptor.instance_variable_get(:@subject_prefix)
  subject = [subject_prefix, sg_definition.personalization.subject].join(" ").strip
  sg_definition.set_subject(subject)
end

.exec_recipients_interceptor(sg_definition, interceptor) ⇒ Object



10
11
12
13
14
# File 'lib/send_grid_mailer/interceptor/recipient_interceptor.rb', line 10

def self.exec_recipients_interceptor(sg_definition, interceptor)
  add_custom_headers(sg_definition)
  add_recipients(sg_definition, interceptor)
  add_subject_prefix(sg_definition, interceptor)
end

.perform(sg_definition, interceptor) ⇒ Object



4
5
6
7
8
# File 'lib/send_grid_mailer/interceptor/recipient_interceptor.rb', line 4

def self.perform(sg_definition, interceptor)
  add_custom_headers(sg_definition)
  add_recipients(sg_definition, interceptor)
  add_subject_prefix(sg_definition, interceptor)
end