From 0108169c85c7404aeafbdfe1ad8176240853ef6a Mon Sep 17 00:00:00 2001 From: "john.hackett@bytemark.co.uk" Date: Thu, 7 Feb 2013 17:19:27 +0000 Subject: Cleaned up logic with inversion and return to be a bit less cumbersome and marginally less ugly. --- lib/custodian/protocoltest/smtprelay.rb | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb index d6c5bb4..2280f10 100644 --- a/lib/custodian/protocoltest/smtprelay.rb +++ b/lib/custodian/protocoltest/smtprelay.rb @@ -71,22 +71,22 @@ module Custodian sent = smtp.send_message message, "noreply@bytemark.co.uk", "noreply@bytemark.co.uk" @status = sent.status.to_s - if @inverted === true - @success = true - @failure = false - else - @success = false - @failure = true - end - - if @status === "250" #and @inverted == true + if @status === "250" @error = "NOT OK: message sent on #{@host} with status #{@status}" - return @success - else + else @error = "OK: message not sent on #{@host} with status #{@status}" - return @failure end - + + # + # give the parser an appropriate response depending on the smtp code + # and whether or not we're inverting the test. (eg, 'must not') + # + + return @inverted if @status == "250" and @inverted + return !@inverted if @status == "250" and !@inverted + return @inverted if @status != "250" and !@inverted + return !@inverted if @status != "250" and @inverted + end # Net SMTP rescue Exception => ex @@ -94,7 +94,8 @@ module Custodian # for if we fail to send a message; this is a good thing # @error = "OK: Timed out or connection refused on #{@host} with status #{@status}" - return @failure + return !@inverted if @inverted + return @inverted if !@inverted end end -- cgit v1.2.1