2018-12-14 10:06:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
module ActionMailbox
|
2019-01-01 21:43:03 +00:00
|
|
|
# The base class for all Action Mailbox ingress controllers.
|
2018-12-26 21:18:42 +00:00
|
|
|
class BaseController < ActionController::Base
|
2019-04-10 07:08:32 +00:00
|
|
|
skip_forgery_protection if default_protect_from_forgery
|
2018-10-07 02:02:08 +00:00
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
before_action :ensure_configured
|
2018-12-24 20:16:22 +00:00
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
private
|
|
|
|
def ensure_configured
|
|
|
|
unless ActionMailbox.ingress == ingress_name
|
|
|
|
head :not_found
|
|
|
|
end
|
2018-11-05 14:11:01 +00:00
|
|
|
end
|
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def ingress_name
|
|
|
|
self.class.name.remove(/\AActionMailbox::Ingresses::/, /::InboundEmailsController\z/).underscore.to_sym
|
|
|
|
end
|
2018-11-05 14:11:01 +00:00
|
|
|
|
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def authenticate_by_password
|
|
|
|
if password.present?
|
|
|
|
http_basic_authenticate_or_request_with name: "actionmailbox", password: password, realm: "Action Mailbox"
|
|
|
|
else
|
|
|
|
raise ArgumentError, "Missing required ingress credentials"
|
|
|
|
end
|
2018-10-07 02:02:08 +00:00
|
|
|
end
|
2018-10-29 18:19:46 +00:00
|
|
|
|
2018-12-26 21:18:42 +00:00
|
|
|
def password
|
|
|
|
Rails.application.credentials.dig(:action_mailbox, :ingress_password) || ENV["RAILS_INBOUND_EMAIL_PASSWORD"]
|
|
|
|
end
|
|
|
|
end
|
2018-10-07 02:02:08 +00:00
|
|
|
end
|