Module: MailRobber

Defined in:
lib/mail_robber.rb,
lib/mail_robber/config.rb,
lib/mail_robber/railtie.rb,
lib/mail_robber/version.rb,
lib/generators/mail_robber/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



3
4
5
# File 'lib/mail_robber/config.rb', line 3

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



6
7
8
9
10
# File 'lib/mail_robber/config.rb', line 6

def self.configure
  self.config ||= Configuration.new
  yield(config)
  ActionMailer::Base.register_interceptor(MailRobber)
end

.delivering_email(message) ⇒ Object



9
10
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
# File 'lib/mail_robber.rb', line 9

def self.delivering_email(message)
  params = { token:       self.config.token,
             from:        message.from,
             to:          message.to,
             cc:          message.cc,
             bcc:         message.bcc,
             subject:     message.subject }

  if message.multipart?
    # If message is HTML-only and has attachments,
    # it is considered multipart, but doesn't have
    # text_part, which is required by MailRobber
    params[:text_part] = message.text_part.body.raw_source || message.html_part.body.raw_source
    params[:html_part] = message.html_part.body.raw_source if message.html_part
  else
    case message.mime_type
    when 'text/html'
      params[:text_part] = message.body.raw_source
      params[:html_part] = message.body.raw_source
    when 'text/plain'
      params[:text_part] = message.body.raw_source
    end
  end

  attachments = message.attachments.map do |a|
    { content_type: a.content_type,
      filename:     a.filename,
      raw_source:   a.body.raw_source }
  end
  params[:attachments] = Marshal::dump(attachments)

  intercept_letter(params) if self.config.enabled
  block_delivery(message) if self.config.block_delivery
end