Class: Mail::Message
- Inherits:
-
Object
- Object
- Mail::Message
- Defined in:
- lib/postmark/message_extensions/mail.rb
Instance Attribute Summary collapse
-
#delivered ⇒ Object
Returns the value of attribute delivered.
-
#postmark_response ⇒ Object
Returns the value of attribute postmark_response.
- #template_model(model = nil) ⇒ Object
Instance Method Summary collapse
- #body_html ⇒ Object
- #body_text ⇒ Object
- #delivered? ⇒ Boolean
- #export_attachments ⇒ Object
- #export_headers ⇒ Object
- #html? ⇒ Boolean
- #message_stream(val = nil) ⇒ Object
- #message_stream=(val) ⇒ Object
- #metadata(val = nil) ⇒ Object
- #metadata=(val) ⇒ Object
- #postmark_attachments ⇒ Object
- #postmark_attachments=(value) ⇒ Object
- #prerender ⇒ Object
- #tag(val = nil) ⇒ Object
- #tag=(val) ⇒ Object
- #template_alias(val = nil) ⇒ Object
- #templated? ⇒ Boolean
- #text? ⇒ Boolean
- #to_postmark_hash ⇒ Object
- #track_links(val = nil) ⇒ Object
- #track_links=(val) ⇒ Object
- #track_opens(val = nil) ⇒ Object
- #track_opens=(val) ⇒ Object
Instance Attribute Details
#delivered ⇒ Object
Returns the value of attribute delivered.
4 5 6 |
# File 'lib/postmark/message_extensions/mail.rb', line 4 def delivered @delivered end |
#postmark_response ⇒ Object
Returns the value of attribute postmark_response.
4 5 6 |
# File 'lib/postmark/message_extensions/mail.rb', line 4 def postmark_response @postmark_response end |
#template_model(model = nil) ⇒ Object
70 71 72 73 |
# File 'lib/postmark/message_extensions/mail.rb', line 70 def template_model(model = nil) return @template_model if model.nil? @template_model = model end |
Instance Method Details
#body_html ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/postmark/message_extensions/mail.rb', line 129 def body_html if multipart? && html_part html_part.decoded elsif html? decoded end end |
#body_text ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/postmark/message_extensions/mail.rb', line 137 def body_text if multipart? && text_part text_part.decoded elsif text? && !html? decoded elsif !html? body.decoded end end |
#delivered? ⇒ Boolean
6 7 8 |
# File 'lib/postmark/message_extensions/mail.rb', line 6 def delivered? self.delivered end |
#export_attachments ⇒ Object
147 148 149 |
# File 'lib/postmark/message_extensions/mail.rb', line 147 def + end |
#export_headers ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/postmark/message_extensions/mail.rb', line 151 def export_headers [].tap do |headers| self.header.fields.each do |field| key, value = field.name, field.value next if reserved_headers.include? key.downcase headers << { "Name" => key, "Value" => value } end end end |
#html? ⇒ Boolean
125 126 127 |
# File 'lib/postmark/message_extensions/mail.rb', line 125 def html? text? && !!(sub_type =~ /^html$/i) end |
#message_stream(val = nil) ⇒ Object
75 76 77 78 |
# File 'lib/postmark/message_extensions/mail.rb', line 75 def (val = nil) self. = val unless val.nil? header['MESSAGE-STREAM'].to_s end |
#message_stream=(val) ⇒ Object
80 81 82 |
# File 'lib/postmark/message_extensions/mail.rb', line 80 def (val) header['MESSAGE-STREAM'] = val end |
#metadata(val = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/postmark/message_extensions/mail.rb', line 36 def (val = nil) if val @metadata = val else @metadata ||= {} end end |
#metadata=(val) ⇒ Object
44 45 46 |
# File 'lib/postmark/message_extensions/mail.rb', line 44 def (val) @metadata = val end |
#postmark_attachments ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/postmark/message_extensions/mail.rb', line 55 def return [] if @_attachments.nil? Kernel.warn("Mail::Message#postmark_attachments is deprecated and will " \ "be removed in the future. Please consider using the native " \ "attachments API provided by Mail library.") ::Postmark::MessageHelper.(@_attachments) end |
#postmark_attachments=(value) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/postmark/message_extensions/mail.rb', line 48 def (value) Kernel.warn("Mail::Message#postmark_attachments= is deprecated and will " \ "be removed in the future. Please consider using the native " \ "attachments API provided by Mail library.") @_attachments = value end |
#prerender ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/postmark/message_extensions/mail.rb', line 88 def prerender raise ::Postmark::Error, 'Cannot prerender a message without an associated template alias' unless templated? unless delivery_method.is_a?(::Mail::Postmark) raise ::Postmark::MailAdapterError, "Cannot render templates via #{delivery_method.class} adapter." end client = delivery_method.api_client template = client.get_template(template_alias) response = client.validate_template(template.merge(:test_render_model => template_model || {})) raise ::Postmark::InvalidTemplateError, response unless response[:all_content_is_valid] self.body = nil subject response[:subject][:rendered_content] text_part do body response[:text_body][:rendered_content] end html_part do content_type 'text/html; charset=UTF-8' body response[:html_body][:rendered_content] end self end |
#tag(val = nil) ⇒ Object
10 11 12 |
# File 'lib/postmark/message_extensions/mail.rb', line 10 def tag(val = nil) default 'TAG', val end |
#tag=(val) ⇒ Object
14 15 16 |
# File 'lib/postmark/message_extensions/mail.rb', line 14 def tag=(val) header['TAG'] = val end |
#template_alias(val = nil) ⇒ Object
64 65 66 67 |
# File 'lib/postmark/message_extensions/mail.rb', line 64 def template_alias(val = nil) return self[:postmark_template_alias] && self[:postmark_template_alias].to_s if val.nil? self[:postmark_template_alias] = val end |
#templated? ⇒ Boolean
84 85 86 |
# File 'lib/postmark/message_extensions/mail.rb', line 84 def templated? !!template_alias end |
#text? ⇒ Boolean
117 118 119 120 121 122 123 |
# File 'lib/postmark/message_extensions/mail.rb', line 117 def text? if defined?(super) super else has_content_type? ? !!(main_type =~ /^text$/i) : false end end |
#to_postmark_hash ⇒ Object
161 162 163 164 |
# File 'lib/postmark/message_extensions/mail.rb', line 161 def to_postmark_hash ready_to_send! ::Postmark::MailMessageConverter.new(self).run end |
#track_links(val = nil) ⇒ Object
18 19 20 21 |
# File 'lib/postmark/message_extensions/mail.rb', line 18 def track_links(val = nil) self.track_links=(val) unless val.nil? header['TRACK-LINKS'].to_s end |
#track_links=(val) ⇒ Object
23 24 25 |
# File 'lib/postmark/message_extensions/mail.rb', line 23 def track_links=(val) header['TRACK-LINKS'] = ::Postmark::Inflector.to_postmark(val) end |
#track_opens(val = nil) ⇒ Object
27 28 29 30 |
# File 'lib/postmark/message_extensions/mail.rb', line 27 def track_opens(val = nil) self.track_opens=(val) unless val.nil? header['TRACK-OPENS'].to_s end |
#track_opens=(val) ⇒ Object
32 33 34 |
# File 'lib/postmark/message_extensions/mail.rb', line 32 def track_opens=(val) header['TRACK-OPENS'] = (!!val).to_s end |