diff options
author | George Claghorn <george@basecamp.com> | 2018-10-18 10:23:17 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-10-18 10:23:17 -0400 |
commit | b3919d01554d31c5486d17332f4a4dde89a23239 (patch) | |
tree | 42a4bcacda5f7e88824487b269e2893a96422333 /app/controllers/action_mailbox | |
parent | 88227658217ee82af7516d6a8013a6c04f037073 (diff) | |
download | rails-b3919d01554d31c5486d17332f4a4dde89a23239.tar.gz rails-b3919d01554d31c5486d17332f4a4dde89a23239.tar.bz2 rails-b3919d01554d31c5486d17332f4a4dde89a23239.zip |
Don't require Postfix to send form data
Diffstat (limited to 'app/controllers/action_mailbox')
5 files changed, 13 insertions, 23 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 index 7412928b56..53b9bd07ec 100644 --- a/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb @@ -6,16 +6,11 @@ class ActionMailbox::Ingresses::Amazon::InboundEmailsController < ActionMailbox: cattr_accessor :verifier, default: Aws::SNS::MessageVerifier.new def create - ActionMailbox::InboundEmail.create_and_extract_message_id! raw_email + ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(:content) head :no_content end private - def raw_email - StringIO.new params.require(:content) - end - - def ensure_verified head :unauthorized unless verified? end diff --git a/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb index 4d194a3e00..77e05d712a 100644 --- a/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb @@ -2,16 +2,11 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsController < ActionMailbox before_action :ensure_authenticated def create - ActionMailbox::InboundEmail.create_and_extract_message_id! raw_email + ActionMailbox::InboundEmail.create_and_extract_message_id! params.require("body-mime") head :ok end private - def raw_email - StringIO.new params.require("body-mime") - end - - def ensure_authenticated head :unauthorized unless authenticated? end @@ -26,7 +21,6 @@ class ActionMailbox::Ingresses::Mailgun::InboundEmailsController < ActionMailbox params.permit(:timestamp, :token, :signature).to_h.symbolize_keys end - class Authenticator cattr_accessor :key diff --git a/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb index 825ec6eabd..7910359f51 100644 --- a/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb @@ -13,8 +13,7 @@ class ActionMailbox::Ingresses::Mandrill::InboundEmailsController < ActionMailbo def raw_emails events.lazy. select { |event| event["event"] == "inbound" }. - collect { |event| event.dig("msg", "raw_msg") }. - collect { |message| StringIO.new message } + collect { |event| event.dig("msg", "raw_msg") } end def events diff --git a/app/controllers/action_mailbox/ingresses/postfix/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/postfix/inbound_emails_controller.rb index 2631302606..d34257f9e9 100644 --- a/app/controllers/action_mailbox/ingresses/postfix/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/postfix/inbound_emails_controller.rb @@ -2,10 +2,17 @@ class ActionMailbox::Ingresses::Postfix::InboundEmailsController < ActionMailbox cattr_accessor :username, default: "actionmailbox" cattr_accessor :password - before_action :authenticate + before_action :authenticate, :require_valid_rfc822_message def create - ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(:message) + ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read head :no_content end + + private + def require_valid_rfc822_message + unless request.content_type == "message/rfc822" + head :unsupported_media_type + end + end end diff --git a/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb index 0b9e2e1866..19c3b1b2c4 100644 --- a/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb @@ -5,12 +5,7 @@ class ActionMailbox::Ingresses::Sendgrid::InboundEmailsController < ActionMailbo before_action :authenticate def create - ActionMailbox::InboundEmail.create_and_extract_message_id! raw_email + ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(:email) head :no_content end - - private - def raw_email - StringIO.new params.require(:email) - end end |