Class: TestMailInterceptor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mail) ⇒ TestMailInterceptor

Returns a new instance of TestMailInterceptor.



18
19
20
# File 'lib/test_mail_interceptor.rb', line 18

def initialize(mail)
  @mail = mail
end

Instance Attribute Details

#mailObject (readonly)

Returns the value of attribute mail.



16
17
18
# File 'lib/test_mail_interceptor.rb', line 16

def mail
  @mail
end

Class Method Details

.delivering_email(mail) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/test_mail_interceptor.rb', line 3

def self.delivering_email(mail)
  if Rails.application.config.mail_interceptor.intercept_mail
    interceptor = new(mail)
    interceptor.handle_multipart_mail
    interceptor.change_original_recipients_to_test_recipients
    interceptor.clean_cc_and_bcc_recipients

    return interceptor.mail
  end

  return mail
end

Instance Method Details

#change_original_recipients_to_test_recipientsObject



36
37
38
# File 'lib/test_mail_interceptor.rb', line 36

def change_original_recipients_to_test_recipients
  mail.to = Rails.application.config.mail_interceptor.test_recipient
end

#clean_cc_and_bcc_recipientsObject



40
41
42
43
# File 'lib/test_mail_interceptor.rb', line 40

def clean_cc_and_bcc_recipients
  mail.cc = nil
  mail.bcc = nil
end

#handle_multipart_mailObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/test_mail_interceptor.rb', line 22

def handle_multipart_mail
  if mail.multipart?
    mail.parts.each do |part|
      if part.content_type =~ /^text\/html/
        part.body = generate_test_mail_header_html + part.body.raw_source
      else
        part.body = generate_test_mail_header + part.body.raw_source
      end
    end
  else
    mail.body = generate_test_mail_header + mail.body.raw_source
  end
end