mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add simply bounce handling
Bouncing is not an exceptional state, so let's not use exceptions to deal with it.
This commit is contained in:
parent
26f4e359bf
commit
8eb239bd1a
2 changed files with 16 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue