Class: MultiMail::Message::Mandrill

Inherits:
Base
  • Object
show all
Defined in:
lib/multi_mail/mandrill/message.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from MultiMail::Message::Base

Instance Attribute Details

#dkim_signedObject

Returns the value of attribute dkim_signed.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def dkim_signed
  @dkim_signed
end

#dkim_validObject

Returns the value of attribute dkim_valid.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def dkim_valid
  @dkim_valid
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def email
  @email
end

#spam_report_scoreObject

Returns the value of attribute spam_report_score.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def spam_report_score
  @spam_report_score
end

#spf_resultObject

Returns the value of attribute spf_result.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def spf_result
  @spf_result
end

#tsObject

Returns the value of attribute ts.



5
6
7
# File 'lib/multi_mail/mandrill/message.rb', line 5

def ts
  @ts
end

Instance Method Details

#mandrill_attachmentsArray<Faraday::UploadIO>

Returns the message's attachments in Mandrill format.

Returns:

  • (Array<Faraday::UploadIO>)

    the attachments in Mandrill format



42
43
44
45
46
47
48
49
50
# File 'lib/multi_mail/mandrill/message.rb', line 42

def mandrill_attachments
  attachments.map do |attachment|
    {
      'type'    => attachment.content_type,
      'name'    => attachment.filename,
      'content' => Base64.encode64(attachment.body.decoded)
    }
  end
end

#mandrill_headersHash

Returns the message headers in Mandrill format.

Returns:

  • (Hash)

    the message headers in Mandrill format



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/multi_mail/mandrill/message.rb', line 26

def mandrill_headers
  hash = {}
  header_fields.each do |field|
    key = field.name.downcase
    # Mandrill only allows Reply-To and X-* headers currently.
    # https://mandrillapp.com/api/docs/messages.ruby.html
    if key == 'reply-to' || key.start_with?('x-')
      hash[field.name] = field.value
    end
  end
  hash
end

#mandrill_toArray<Hash>

Returns the To header in Mandrill format.

Returns:

  • (Array<Hash>)

    the To header in Mandrill format



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

def mandrill_to
  if to
    to.each_with_index.map do |value,index|
      {
        'email' => value,
        'name'  => self[:to].display_names[index]
      }
    end
  else
    []
  end
end

#to_mandrill_hashHash

Returns the message as parameters to POST to Mandrill.

Returns:

  • (Hash)

    the message as parameters to POST to Mandrill



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/multi_mail/mandrill/message.rb', line 55

def to_mandrill_hash
  images, attachments = mandrill_attachments.partition do |attachment|
    attachment['type'].start_with?('image/')
  end

  hash = {
    'html'        => body_html,
    'text'        => body_text,
    'subject'     => subject,
    'from_email'  => from && from.first,
    'from_name'   => from && self[:from].display_names.first,
    'to'          => mandrill_to,
    'headers'     => mandrill_headers,
    'attachments' => attachments,
    'images'      => images,
    'tags'        => tags,
  }

  normalize(hash)
end