diff options
author | George Claghorn <george@basecamp.com> | 2018-10-06 22:15:36 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-10-06 22:15:36 -0400 |
commit | 7b95ebc9e44b7dba1e4aa32b773a124f75de9474 (patch) | |
tree | 46bda2e17a446dbbbb626153622d9bbfe2d82f1f /lib | |
parent | 015c33f4cd6758e2c7d43f82ff5da93bac5cf3e3 (diff) | |
download | rails-7b95ebc9e44b7dba1e4aa32b773a124f75de9474.tar.gz rails-7b95ebc9e44b7dba1e4aa32b773a124f75de9474.tar.bz2 rails-7b95ebc9e44b7dba1e4aa32b773a124f75de9474.zip |
Terminate processing if inbound email is marked as delivered in callback
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_mailbox/base.rb | 7 | ||||
-rw-r--r-- | lib/action_mailbox/callbacks.rb | 12 |
2 files changed, 9 insertions, 10 deletions
diff --git a/lib/action_mailbox/base.rb b/lib/action_mailbox/base.rb index 66a3b7fd32..3b12493662 100644 --- a/lib/action_mailbox/base.rb +++ b/lib/action_mailbox/base.rb @@ -8,7 +8,7 @@ class ActionMailbox::Base include ActionMailbox::Callbacks, ActionMailbox::Routing attr_reader :inbound_email - delegate :mail, :bounced!, to: :inbound_email + delegate :mail, :delivered!, :bounced!, to: :inbound_email delegate :logger, to: ActionMailbox @@ -35,6 +35,11 @@ class ActionMailbox::Base # Overwrite in subclasses end + def finished_processing? + inbound_email.delivered? || inbound_email.bounced? + end + + def bounce_with(message) inbound_email.bounced! message.deliver_later diff --git a/lib/action_mailbox/callbacks.rb b/lib/action_mailbox/callbacks.rb index a5f7aa7e6f..5f39faa01e 100644 --- a/lib/action_mailbox/callbacks.rb +++ b/lib/action_mailbox/callbacks.rb @@ -5,15 +5,9 @@ module ActionMailbox extend ActiveSupport::Concern include ActiveSupport::Callbacks - TERMINATOR = ->(target, chain) do - terminate = true - - catch(:abort) do - chain.call - terminate = target.inbound_email.bounced? - end - - terminate + TERMINATOR = ->(mailbox, chain) do + chain.call + mailbox.finished_processing? end included do |