aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/action_mailroom/inbound_emails_controller.rb14
-rw-r--r--config/routes.rb7
-rw-r--r--test/unit/controller_test.rb19
3 files changed, 40 insertions, 0 deletions
diff --git a/app/controllers/action_mailroom/inbound_emails_controller.rb b/app/controllers/action_mailroom/inbound_emails_controller.rb
new file mode 100644
index 0000000000..0c74d4b29a
--- /dev/null
+++ b/app/controllers/action_mailroom/inbound_emails_controller.rb
@@ -0,0 +1,14 @@
+class ActionMailroom::InboundEmailsController < ActionController::Base
+ skip_forgery_protection
+ before_action :require_rfc822_message
+
+ def create
+ ActionMailroom::InboundEmail.create!(raw_email: params[:message])
+ head :created
+ end
+
+ private
+ def require_rfc822_message
+ head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822'
+ end
+end
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000000..1ba01f4bf9
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+Rails.application.routes.draw do
+ scope :action_mailroom do
+ post "/inbound_emails" => "action_mailroom/inbound_emails#create", as: :rails_inbound_emails
+ end
+end
diff --git a/test/unit/controller_test.rb b/test/unit/controller_test.rb
new file mode 100644
index 0000000000..c9ba1ba45f
--- /dev/null
+++ b/test/unit/controller_test.rb
@@ -0,0 +1,19 @@
+require_relative '../test_helper'
+
+class ActionMailroom::InboundEmailsControllerTest < ActionDispatch::IntegrationTest
+ test "receiving a valid RFC 822 message" do
+ assert_difference -> { ActionMailroom::InboundEmail.count }, +1 do
+ post_inbound_email "welcome.eml"
+ end
+
+ assert_response :created
+
+ inbound_email = ActionMailroom::InboundEmail.last
+ assert_equal file_fixture('../files/welcome.eml').read, inbound_email.raw_email.download
+ end
+
+ private
+ def post_inbound_email(fixture_name)
+ post rails_inbound_emails_url, params: { message: fixture_file_upload("files/#{fixture_name}", 'message/rfc822') }
+ end
+end