aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/action_mailroom/inbound_emails_controller.rb25
-rw-r--r--app/controllers/rails/conductor/action_mailroom/inbound_emails_controller.rb30
-rw-r--r--app/controllers/rails/conductor/base_controller.rb10
3 files changed, 41 insertions, 24 deletions
diff --git a/app/controllers/action_mailroom/inbound_emails_controller.rb b/app/controllers/action_mailroom/inbound_emails_controller.rb
index b8fa6cde49..0723bd39c3 100644
--- a/app/controllers/action_mailroom/inbound_emails_controller.rb
+++ b/app/controllers/action_mailroom/inbound_emails_controller.rb
@@ -2,38 +2,15 @@
# TODO: Spam/malware catching?
# TODO: Specific bounces for SMTP good citizenship: 200/404/400
class ActionMailroom::InboundEmailsController < ActionController::Base
- layout "action_mailroom"
-
skip_forgery_protection
- before_action :ensure_development_env, except: :create
before_action :require_rfc822_message, only: :create
- def index
- @inbound_emails = ActionMailroom::InboundEmail.order(created_at: :desc)
- end
-
- def new
- end
-
- def show
- @inbound_email = ActionMailroom::InboundEmail.find(params[:id])
- end
-
def create
ActionMailroom::InboundEmail.create_from_raw_email!(params[:message])
-
- respond_to do |format|
- format.html { redirect_to main_app.rails_new_inbound_email_url }
- format.any { head :created }
- end
+ head :created
end
private
- # TODO: Should probably separate the admin interface and do more to ensure that it isn't exposed to the web
- def ensure_development_env
- head :forbidden unless Rails.env.development?
- end
-
def require_rfc822_message
head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822'
end
diff --git a/app/controllers/rails/conductor/action_mailroom/inbound_emails_controller.rb b/app/controllers/rails/conductor/action_mailroom/inbound_emails_controller.rb
new file mode 100644
index 0000000000..2281f5bcae
--- /dev/null
+++ b/app/controllers/rails/conductor/action_mailroom/inbound_emails_controller.rb
@@ -0,0 +1,30 @@
+class Rails::Conductor::ActionMailroom::InboundEmailsController < Rails::Conductor::BaseController
+ def index
+ @inbound_emails = ActionMailroom::InboundEmail.order(created_at: :desc)
+ end
+
+ def new
+ end
+
+ def show
+ @inbound_email = ActionMailroom::InboundEmail.find(params[:id])
+ end
+
+ def create
+ inbound_email = create_inbound_email(new_mail)
+ redirect_to main_app.rails_conductor_inbound_email_url(inbound_email)
+ end
+
+ private
+ def new_mail
+ Mail.new params.require(:mail).permit(:from, :to, :cc, :bcc, :subject, :body)
+ end
+
+ def create_inbound_email(mail)
+ ActionMailroom::InboundEmail.create! raw_email: new_raw_email(mail), message_id: mail.message_id
+ end
+
+ def new_raw_email(mail)
+ { io: StringIO.new(new_mail.to_s), filename: 'inbound.eml', content_type: 'message/rfc822', identify: false }
+ end
+end
diff --git a/app/controllers/rails/conductor/base_controller.rb b/app/controllers/rails/conductor/base_controller.rb
new file mode 100644
index 0000000000..cfa0b84963
--- /dev/null
+++ b/app/controllers/rails/conductor/base_controller.rb
@@ -0,0 +1,10 @@
+# TODO: Move this to Rails::Conductor gem
+class Rails::Conductor::BaseController < ActionController::Base
+ layout "rails/conductor"
+ before_action :ensure_development_env
+
+ private
+ def ensure_development_env
+ head :forbidden unless Rails.env.development?
+ end
+end