Class: MultiMail::Receiver::Simple

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/multi_mail/simple/receiver.rb

Overview

A simple incoming email receiver.

Instance Method Summary collapse

Methods included from Base

included, #process, #spam?

Constructor Details

#initialize(options = {}) ⇒ Simple

Initializes a simple incoming email receiver.

Parameters:

  • options (Hash) (defaults to: {})

    required and optional arguments

Options Hash (options):

  • :secret (String)

    a secret key



13
14
15
16
# File 'lib/multi_mail/simple/receiver.rb', line 13

def initialize(options = {})
  super
  @secret = options[:secret]
end

Instance Method Details

#signature(params) ⇒ Object



39
40
41
42
# 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) ⇒ Array<Mail::Message>

Expects a raw email message parsable by the Mail gem.

Parameters:

  • params (Hash)

    the content of the webhook

Returns:



35
36
37
# File 'lib/multi_mail/simple/receiver.rb', line 35

def transform(params)
  [Mail.new(params)]
end

#valid?(params) ⇒ Boolean

Returns whether a request is authentic.

Parameters:

  • params (Hash)

    the content of the webhook

Returns:

  • (Boolean)

    whether the request is authentic

Raises:

  • (IndexError)

    if the request is missing parameters



23
24
25
26
27
28
29
# File 'lib/multi_mail/simple/receiver.rb', line 23

def valid?(params)
  if @secret
    params.fetch('signature') == signature(params)
  else
    super
  end
end