diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-21 16:44:48 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2018-09-21 16:44:48 -0700 |
commit | 8eb239bd1a1350b151d57a639e589c68aed1f47a (patch) | |
tree | 64f98ff2a5690320d171b85be9bcbddb312adcad | |
parent | 26f4e359bf7ffc4612b3170e1423aaedfee62ef8 (diff) | |
download | rails-8eb239bd1a1350b151d57a639e589c68aed1f47a.tar.gz rails-8eb239bd1a1350b151d57a639e589c68aed1f47a.tar.bz2 rails-8eb239bd1a1350b151d57a639e589c68aed1f47a.zip |
Add simply bounce handling
Bouncing is not an exceptional state, so let's not use exceptions to deal with it.
-rw-r--r-- | lib/action_mailroom/mailbox.rb | 4 | ||||
-rw-r--r-- | test/unit/mailbox/state_test.rb | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/action_mailroom/mailbox.rb b/lib/action_mailroom/mailbox.rb index de02e56f13..936054810f 100644 --- a/lib/action_mailroom/mailbox.rb +++ b/lib/action_mailroom/mailbox.rb @@ -8,7 +8,7 @@ class ActionMailroom::Mailbox include Callbacks, Routing attr_reader :inbound_email - delegate :mail, to: :inbound_email + delegate :mail, :bounced!, to: :inbound_email def self.receive(inbound_email) new(inbound_email).perform_processing @@ -37,7 +37,7 @@ class ActionMailroom::Mailbox def track_status_of_inbound_email inbound_email.processing! yield - inbound_email.delivered! + inbound_email.delivered! unless inbound_email.bounced? rescue => exception inbound_email.failed! raise diff --git a/test/unit/mailbox/state_test.rb b/test/unit/mailbox/state_test.rb index de9da54d3f..6215e02837 100644 --- a/test/unit/mailbox/state_test.rb +++ b/test/unit/mailbox/state_test.rb @@ -14,6 +14,14 @@ class UnsuccessfulMailbox < ActionMailroom::Mailbox end end +class BouncingMailbox < ActionMailroom::Mailbox + def process + $processed = :bounced + bounced! + end +end + + class ActionMailroom::Mailbox::StateTest < ActiveSupport::TestCase setup do $processed = false @@ -32,4 +40,10 @@ class ActionMailroom::Mailbox::StateTest < ActiveSupport::TestCase assert @inbound_email.failed? assert_equal :failure, $processed end + + test "bounced inbound emails are not delivered" do + BouncingMailbox.receive @inbound_email + assert @inbound_email.bounced? + assert_equal :bounced, $processed + end end |