module MultiMail::Receiver::Base

Abstract class for incoming email receivers.

The `transform` instance method must be implemented in sub-classes. The `valid?` and `spam?` instance methods may be implemented in sub-classes.

Public Class Methods

included(subclass) click to toggle source
# File lib/multi_mail/receiver/base.rb, line 8
def self.included(subclass)
  subclass.class_eval do
    extend MultiMail::Service
    extend MultiMail::Receiver::Base::ClassMethods
  end
end
new(options = {}) click to toggle source

Initializes an incoming email receiver.

@param [Hash] options required and optional arguments

# File lib/multi_mail/receiver/base.rb, line 18
def initialize(options = {})
  self.class.validate_options(options)
end

Public Instance Methods

process(raw) click to toggle source

Ensures a request is authentic, parses it into a params hash, and transforms it into a list of messages.

@param [String,Array,Hash,Rack::Request] raw raw POST data or a params hash @return [Array<Mail::Message>] messages @raise [ForgedRequest] if the request is not authentic

# File lib/multi_mail/receiver/base.rb, line 28
def process(raw)
  params = self.class.parse(raw)
  if valid?(params)
    transform(params)
  else
    raise ForgedRequest
  end
end
spam?(message) click to toggle source

Returns whether a message is spam.

@param [Mail::Message] message a message @return [Boolean] whether the message is spam

# File lib/multi_mail/receiver/base.rb, line 57
def spam?(message)
  false
end
transform(params) click to toggle source

Transforms the content of a provider's webhook into a list of messages.

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

# File lib/multi_mail/receiver/base.rb, line 49
def transform(params)
  raise NotImplementedError
end
valid?(params) click to toggle source

Returns whether a request is authentic.

@param [Hash] params the content of the provider's webhook @return [Boolean] whether the request is authentic

# File lib/multi_mail/receiver/base.rb, line 41
def valid?(params)
  true
end