Class: TestMailInterceptor

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

Defined Under Namespace

Classes: Engine

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mail) ⇒ TestMailInterceptor

Returns a new instance of TestMailInterceptor.



25
26
27
# File 'lib/test_mail_interceptor.rb', line 25

def initialize(mail)
  @mail = mail
end

Instance Attribute Details

#mailObject (readonly)

Returns the value of attribute mail.



23
24
25
# File 'lib/test_mail_interceptor.rb', line 23

def mail
  @mail
end

Class Method Details

.delivering_email(mail) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/test_mail_interceptor.rb', line 10

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



43
44
45
# File 'lib/test_mail_interceptor.rb', line 43

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

#clean_cc_and_bcc_recipientsObject



47
48
49
50
# File 'lib/test_mail_interceptor.rb', line 47

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

#handle_multipart_mailObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/test_mail_interceptor.rb', line 29

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