class ActionMailbox::Ingresses::Ses::InboundEmailsController

  • 422 Unprocessable Entity if a request provides invalid parameters
    - 404 Not Found if the Amazon ingress has not been configured
    - 401 Unauthorized if a request does not contain a valid signature
    - 204 No Content if a request is successfully processed
    Returns:
    All requests are authenticated by validating the provided AWS signature.
    - Type: Type of event (“SubscriptionConfirmation”)
    - TopicArn: Topic identifier
    - SubscribeURL: Topic identifier
    - Timestamp: iso8601 timestamp
    - MessagId: Notification unique identifier
    - Message: Notification content
    Inbound email events must provide the following parameters in a JSON body:
    - Type: Type of event (“Subscription”)
    - TopicArn: Topic identifier
    - Timestamp: iso8601 timestamp
    - MessagId: Notification unique identifier
    - Message: Notification content
    Subscription requests must provide the following parameters in a JSON body:
    Ingests inbound emails from Amazon SES/SNS and confirms subscriptions.

def confirm_subscription

def confirm_subscription
  return unless notification.type == 'SubscriptionConfirmation'
  return head :ok if notification.subscription_confirmed?
  Rails.logger.error('SNS subscription confirmation request rejected.')
  head :unprocessable_entity
end

def create

def create
  head :bad_request unless notification.message_content.present?
  ActionMailbox::InboundEmail.create_and_extract_message_id!(notification.message_content)
  head :no_content
end

def notification

def notification
  @notification ||= Aws::Rails::ActionMailbox::SnsNotification.new(request.raw_post)
end

def topic

def topic
  @topic ||= notification.topic
end

def valid_topic

def valid_topic
  ::Rails.configuration.action_mailbox.ses.subscribed_topic
end

def validate_topic

def validate_topic
  return if valid_topic == notification.topic
  Rails.logger.warn("Ignoring unknown topic: #{topic}")
  head :unauthorized
end

def verify_authenticity

def verify_authenticity
  head :bad_request unless notification.present?
  head :unauthorized unless notification.verified?
end