aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb')
-rw-r--r--app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb
new file mode 100644
index 0000000000..7412928b56
--- /dev/null
+++ b/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb
@@ -0,0 +1,26 @@
+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! raw_email
+ head :no_content
+ end
+
+ private
+ def raw_email
+ StringIO.new params.require(:content)
+ end
+
+
+ def ensure_verified
+ head :unauthorized unless verified?
+ end
+
+ def verified?
+ verifier.authentic?(request.body)
+ end
+end