Module: DMCourier::Services::MessageHelper
Instance Method Summary collapse
- #attachments(filter = {}) ⇒ Object
- #attachments?(filter = {}) ⇒ Boolean
- #extract_params(params) ⇒ Object
- #fallback_options(field) ⇒ Object
- #from ⇒ Object
- #from_address ⇒ Object
- #from_email ⇒ Object
- #from_name ⇒ Object
- #html_part ⇒ Object
- #nil_true_false?(field) ⇒ Boolean
- #return_string_value(field) ⇒ Object
- #subject ⇒ Object
- #text_part ⇒ Object
Instance Method Details
#attachments(filter = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dm_courier/message_helper.rb', line 66 def (filter = {}) Enumerator.new do |y| = mail. = if filter[:inline] .select(&:inline?) else .reject(&:inline?) end if filter.key?(:inline) .map do || y.yield(name: .inline? ? .cid : .filename, type: .mime_type, content: Base64.encode64(.body.decoded), inline: .inline?) end end end |
#attachments?(filter = {}) ⇒ Boolean
84 85 86 87 88 89 90 91 92 |
# File 'lib/dm_courier/message_helper.rb', line 84 def (filter = {}) found = mail. && !mail..empty? if found && filter.key?(:inline) found &&= mail..any? { |a| a.inline? == filter[:inline] } end found end |
#extract_params(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dm_courier/message_helper.rb', line 6 def extract_params(params) json = {} json .merge!(Hash[ params[:nil_true_false].map { |name, key| [name.to_sym, nil_true_false?(key.to_sym)] } ]) if params.key?(:nil_true_false) json .merge!(Hash[ params[:string].map { |name, key| [name.to_sym, return_string_value(key.to_sym)] } ]) if params.key?(:string) json end |
#fallback_options(field) ⇒ Object
62 63 64 |
# File 'lib/dm_courier/message_helper.rb', line 62 def (field) mail[field] || [field] end |
#from ⇒ Object
30 31 32 |
# File 'lib/dm_courier/message_helper.rb', line 30 def from Mail::Address.new(from_address) end |
#from_address ⇒ Object
34 35 36 |
# File 'lib/dm_courier/message_helper.rb', line 34 def from_address mail[:from] ? mail[:from].formatted.first : [:from] end |
#from_email ⇒ Object
22 23 24 |
# File 'lib/dm_courier/message_helper.rb', line 22 def from_email from.address if from_address end |
#from_name ⇒ Object
26 27 28 |
# File 'lib/dm_courier/message_helper.rb', line 26 def from_name from.display_name if from_address end |
#html_part ⇒ Object
43 44 45 |
# File 'lib/dm_courier/message_helper.rb', line 43 def html_part mail.html_part ? mail.html_part.body.decoded : mail.body.decoded end |
#nil_true_false?(field) ⇒ Boolean
56 57 58 59 60 |
# File 'lib/dm_courier/message_helper.rb', line 56 def nil_true_false?(field) value = (field) return nil if value.nil? value.to_s == "true" ? true : false end |
#return_string_value(field) ⇒ Object
51 52 53 54 |
# File 'lib/dm_courier/message_helper.rb', line 51 def return_string_value(field) value = (field) value ? value.to_s : nil end |
#subject ⇒ Object
47 48 49 |
# File 'lib/dm_courier/message_helper.rb', line 47 def subject mail.subject end |
#text_part ⇒ Object
38 39 40 41 |
# File 'lib/dm_courier/message_helper.rb', line 38 def text_part return mail.text_part.body.decoded if mail.multipart? && mail.text_part nil end |