From 016ba4dbfa4946658c4ec6200bad73757f30be30 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 18 Sep 2018 16:26:30 -0700 Subject: Process inbound emails with state and exceptions --- lib/action_mailroom/mailbox.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/action_mailroom') diff --git a/lib/action_mailroom/mailbox.rb b/lib/action_mailroom/mailbox.rb index e873b55544..7f16165221 100644 --- a/lib/action_mailroom/mailbox.rb +++ b/lib/action_mailroom/mailbox.rb @@ -1,7 +1,11 @@ +require "active_support/rescuable" + class ActionMailroom::Mailbox + include ActiveSupport::Rescuable + class << self def receive(inbound_email) - new(inbound_email).process + new(inbound_email).process_with_state_and_exception_handling end def routing(routes) @@ -16,6 +20,16 @@ class ActionMailroom::Mailbox @inbound_email = inbound_email end + def process_with_state_and_exception_handling + inbound_email.processing! + process + inbound_email.delivered! + rescue => exception + inbound_email.failed! + rescue_with_handler(exception) || raise + end + def process + # Overwrite in subclasses end end -- cgit v1.2.3