1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_mailroom/mailbox.rb
David Heinemeier Hansson da697e8444 Attach a concrete router to the root mailbox and use it
Don't think this is how it's going to stay. Doesn't feel like the right place for it.
2018-09-19 15:52:16 -07:00

40 lines
849 B
Ruby

require "active_support/rescuable"
require "action_mailroom/mailbox/callbacks"
require "action_mailroom/mailbox/routing"
class ActionMailroom::Mailbox
include ActiveSupport::Rescuable
include Callbacks, Routing
attr_reader :inbound_email
delegate :mail, to: :inbound_email
def self.receive(inbound_email)
new(inbound_email).perform_processing
end
def initialize(inbound_email)
@inbound_email = inbound_email
end
def perform_processing
inbound_email.processing!
run_callbacks :process do
process
end
inbound_email.delivered!
rescue => exception
inbound_email.failed!
# TODO: Include a reference to the inbound_email in the exception raised so error handling becomes easier
rescue_with_handler(exception) || raise
end
def process
# Overwrite in subclasses
end
end