Class: MultiMail::Receiver::Mandrill
- Includes:
- Base
- Defined in:
- lib/multi_mail/mandrill/receiver.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Mandrill
constructor
A new instance of Mandrill.
-
#spam?(message) ⇒ Boolean
Whether the message is spam.
-
#transform(params) ⇒ Array<Mail::Message>
Messages.
-
#valid?(params) ⇒ Boolean
Whether the request originates from Mandrill.
Methods included from Base
Methods inherited from Service
recognized, recognizes, requirements, requires, validate_options
Constructor Details
#initialize(options = {}) ⇒ Mandrill
Returns a new instance of Mandrill.
10 11 12 13 |
# File 'lib/multi_mail/mandrill/receiver.rb', line 10 def initialize( = {}) super @mandrill_api_key = [:mandrill_api_key] end |
Instance Method Details
#spam?(message) ⇒ Boolean
Returns whether the message is spam.
25 26 27 |
# File 'lib/multi_mail/mandrill/receiver.rb', line 25 def spam?() false end |
#transform(params) ⇒ Array<Mail::Message>
TODO:
parse attachments properly
Returns messages.
32 33 34 35 36 37 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 |
# File 'lib/multi_mail/mandrill/receiver.rb', line 32 def transform(params) JSON.parse(params['mandrill_events']).map do |event| = Mail.new do headers event['msg']['headers'].reject{|k,_| k=='Received'} # @todo # The following are redundant with `message-headers`: # # address = Mail::Address.new event['msg']['from_email'] # address.display_name = event['msg']['from_name'] # # from address.format # to event['msg']['to'].flatten.compact # subject event['msg']['subject'] text_part do body event['msg']['text'] end html_part do content_type 'text/html; charset=UTF-8' # unsure about charset body event['msg']['html'] end end # Extra Mandrill parameters. Discard `raw_msg`. [ 'email', 'tags', 'sender', ].each do |key| if !event['msg'][key].nil? && !event['msg'][key].empty? [key] = event['msg'][key] end end end end |
#valid?(params) ⇒ Boolean
Returns whether the request originates from Mandrill.
17 18 19 20 21 |
# File 'lib/multi_mail/mandrill/receiver.rb', line 17 def valid?(params) JSON.parse(params['mandrill_events']).all? do |event| event.fetch('event') == 'inbound' end end |