[ActionMailbox][Feature Proposal] Adding third-party ingress options through dependency injection and/or loadable modules

The current implementation of ActionMailbox comes with a number of ingress options out of the box, but as far as I can tell there’s no obvious way to add support for others without making a pull request to the Rails core and including a complete implementation.

I run a Rails-based email platform with an existing Ruby gem that we’re looking to extend to include ActionMailbox support. Based on testing versus the Rails 6 beta it looks like adding options could be considerably easier either through documentation or through support for loadable modules.

Issues Faced

The ActionMailbox ingress options are baked in to the ActionMailbox library.

Proposal

Adding ingress options to ActionMailbox should be an easy process based on following guidelines and examples.

So the two obvious options are:

  1. A non-invasive method would be to develop a well-documented example in the form of a minimal gem that uses dependency injection to create the appropriate ActionMailbox ingress routes and controllers. This would be a Rails engine-type package that can be easily added or removed to any Rails 6 application.

  2. A more direct method would be to develop a plug-in or module system for ActionMailbox that makes it easier to define ingress handlers, not unlike how ActionMailer’s handler can be extended or replaced in your Rails config very easily with a minimum of fuss.

Both of these allow third parties to independently iterate and improve on their ActionMailbox integrations without having to wait for a new ActionMailbox release for updates, so that could benefit everyone, even existing implementations.

Hey Scott,

There’s an ActionMailbox::BaseController already, so I think you could do this in an engine:

Follows the format of https://github.com/rails/rails/blob/62105f0aed847f0ab4012e1b91e094e218aa9e08/actionmailbox/app/controllers/action_mailbox/ingresses/mailgun/inbound_emails_controller.rb

class ActionMailbox::Ingresses::Postage::InboundEmailsController < ActionMailbox::BaseController

before_action :authenticate

def create
ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(…)
end

private

def authenticate

Hey oh!

end
end

And you’d need to setup a route in your engine that matches: https://github.com/rails/rails/blob/62105f0aed847f0ab4012e1b91e094e218aa9e08/actionmailbox/config/routes.rb#L7

Then config.action_mailbox.ingress = :postage should work.

Or perhaps you already tried something like this? :slight_smile:

Will have to try that and see how it goes.

Was having trouble posting to this mailing list so I wasn’t sure if anything was going through.

Thanks!

Cool, good luck!