class MultiMail::Receiver::Simple

A simple incoming email receiver.

Public Class Methods

new(options = {}) click to toggle source

Initializes a simple incoming email receiver.

@param [Hash] options required and optional arguments @option options [String] :secret a secret key

Calls superclass method MultiMail::Receiver::Base::new
# File lib/multi_mail/simple/receiver.rb, line 13
def initialize(options = {})
  super
  @secret = options[:secret]
end

Public Instance Methods

signature(params) click to toggle source
# File lib/multi_mail/simple/receiver.rb, line 39
def signature(params)
  data = "#{params.fetch('timestamp')}#{params.fetch('token')}"
  OpenSSL::HMAC.hexdigest('sha256', @secret, data)
end
transform(params) click to toggle source

Expects a raw email message parsable by the Mail gem.

@param [Hash] params the content of the webhook @return [Array<Mail::Message>] messages

# File lib/multi_mail/simple/receiver.rb, line 35
def transform(params)
  [Mail.new(params)]
end
valid?(params) click to toggle source

Returns whether a request is authentic.

@param [Hash] params the content of the webhook @return [Boolean] whether the request is authentic @raise [IndexError] if the request is missing parameters

Calls superclass method MultiMail::Receiver::Base#valid?
# File lib/multi_mail/simple/receiver.rb, line 23
def valid?(params)
  if @secret
    params.fetch('signature') == signature(params)
  else
    super
  end
end