aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb
blob: 557d1aeb04b2ab887a06c13363a4f5daf399c7cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class ActionMailbox::Ingresses::Amazon::InboundEmailsController < ActionMailbox::BaseController
  before_action :ensure_verified

  # TODO: Lazy-load the AWS SDK
  require "aws-sdk-sns/message_verifier"
  cattr_accessor :verifier, default: Aws::SNS::MessageVerifier.new

  def create
    ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(:content)
  end

  private
    def ensure_verified
      head :unauthorized unless verified?
    end

    def verified?
      verifier.authentic?(request.body)
    end
end