Class: MultiMail::Message::Mailgun

Inherits:
Base
  • Object
show all
Defined in:
lib/multi_mail/mailgun/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

#content_id_mapObject

Returns the value of attribute content_id_map.



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

def content_id_map
  @content_id_map
end

#stripped_htmlObject

Returns the value of attribute stripped_html.



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

def stripped_html
  @stripped_html
end

#stripped_signatureObject

Returns the value of attribute stripped_signature.



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

def stripped_signature
  @stripped_signature
end

#stripped_textObject

Returns the value of attribute stripped_text.



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

def stripped_text
  @stripped_text
end

Instance Method Details

#mailgun_attachmentsMultimap

Returns the message's attachments in Mailgun format.

Returns:

  • (Multimap)

    the attachments in Mailgun format

See Also:



25
26
27
28
29
30
31
32
# File 'lib/multi_mail/mailgun/message.rb', line 25

def mailgun_attachments
  hash = Multimap.new
  attachments.each do |attachment|
    key = attachment.content_type.start_with?('image/') ? 'inline' : 'attachment'
    hash[key] = Faraday::UploadIO.new(StringIO.new(attachment.body.decoded), attachment.content_type, attachment.filename)
  end
  hash
end

#mailgun_headersMultimap

Returns the message headers in Mailgun format.

Returns:

  • (Multimap)

    the message headers in Mailgun format



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

def mailgun_headers
  hash = Multimap.new
  header_fields.each do |field|
    key = field.name.downcase
    unless %w(from to cc bcc subject tag).include?(key)
      hash["h:#{field.name}"] = field.value
    end
  end
  hash
end

#to_mailgun_hashHash

Returns the message as parameters to POST to Mailgun.

Returns:

  • (Hash)

    the message as parameters to POST to Mailgun

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/multi_mail/mailgun/message.rb', line 38

def to_mailgun_hash
  hash = Multimap.new

  %w(from subject).each do |field|
    if self[field]
      hash[field] = self[field].value
    end
  end

  %w(to cc bcc).each do |field|
    if self[field]
      if self[field].value.respond_to?(:each)
        self[field].value.each do |value|
          hash[field] = value
        end
      else
        hash[field] = self[field].value
      end
    end
  end

  if body_text && !body_text.empty?
    hash['text'] = body_text
  end
  if body_html && !body_html.empty?
    hash['html'] = body_html
  end

  tags.each do |tag|
    hash['o:tag'] = tag
  end

  normalize(hash.merge(mailgun_attachments).merge(mailgun_headers).to_hash)
end