Module: Sisimai::SMTP::Failure
- Defined in:
- lib/sisimai/smtp/failure.rb
Overview
Sisimai::SMTP::Failure is utilities for checking SMTP Errors from error message text.
Class Method Summary collapse
-
.is_hardbounce(argv1 = '', argv2 = '') ⇒ Boolean
Checks the reason sisimai detected is a hard bounce or not.
-
.is_permanent(argv1 = '') ⇒ Boolean
Returns true if the given string indicates a permanent error.
-
.is_softbounce(argv1 = '', argv2 = '') ⇒ Boolean
Checks the reason sisimai detected is a soft bounce or not.
-
.is_temporary(argv1 = '') ⇒ Boolean
Returns true if the given string indicates a temporary error.
Class Method Details
.is_hardbounce(argv1 = '', argv2 = '') ⇒ Boolean
Checks the reason sisimai detected is a hard bounce or not
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sisimai/smtp/failure.rb', line 45 def is_hardbounce(argv1 = '', argv2 = '') return false if argv1.to_s == "" return false if argv1 == "undefined" || argv1 == "onhold" return false if argv1 == "delivered" || argv1 == "feedback" || argv1 == "vacation" return true if argv1 == "hasmoved" || argv1 == "userunknown" || argv1 == "hostunknown" return false if argv1 != "notaccept" # NotAccept: 5xx => hard bounce, 4xx => soft bounce hardbounce = false if argv2.size > 0 # Check the 2nd argument(a status code or a reply code) cv = Sisimai::SMTP::Status.find(argv2, "") cv = Sisimai::SMTP::Reply.find(argv2, "") if cv.empty? # The SMTP status code or the SMTP reply code starts with "5" # Deal as a hard bounce when the error message does not indicate a temporary error hardbounce = true if cv[0, 1] == "5" || Sisimai::SMTP::Failure.is_temporary(argv2) == false else # Deal "NotAccept" as a hard bounce when the 2nd argument is empty hardbounce = true end return hardbounce end |
.is_permanent(argv1 = '') ⇒ Boolean
Returns true if the given string indicates a permanent error
14 15 16 17 18 19 20 21 22 |
# File 'lib/sisimai/smtp/failure.rb', line 14 def is_permanent(argv1 = '') return false if argv1.to_s == "" statuscode = Sisimai::SMTP::Status.find(argv1) statuscode = Sisimai::SMTP::Reply.find(argv1) if statuscode.empty? return true if statuscode[0, 1] == "5" return true if argv1.downcase.include?(' permanent ') return false end |
.is_softbounce(argv1 = '', argv2 = '') ⇒ Boolean
Checks the reason sisimai detected is a soft bounce or not
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sisimai/smtp/failure.rb', line 73 def is_softbounce(argv1 = '', argv2 = '') return false if argv1.to_s == "" return false if argv1 == "delivered" || argv1 == "feedback" || argv1 == "vacation" return false if argv1 == "hasmoved" || argv1 == "userunknown" || argv1 == "hostunknown" return true if argv1 == "undefined" || argv1 == "onhold" return true if argv1 != "notaccept" # NotAccept: 5xx => hard bounce, 4xx => soft bounce softbounce = false if argv2.size > 0 # Check the 2nd argument(a status code or a reply code) cv = Sisimai::SMTP::Status.find(argv2, "") cv = Sisimai::SMTP::Reply.find(argv2, "") if cv.empty? # The SMTP status code or the SMTP reply code starts with "4" softbounce = true if cv[0, 1] == "4" end return softbounce end |
.is_temporary(argv1 = '') ⇒ Boolean
Returns true if the given string indicates a temporary error
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sisimai/smtp/failure.rb', line 29 def is_temporary(argv1 = '') return false if argv1.to_s == "" statuscode = Sisimai::SMTP::Status.find(argv1); statuscode = Sisimai::SMTP::Reply.find(argv1) if statuscode.empty? issuedcode = argv1.downcase return true if statuscode[0, 1] == "4" return true if issuedcode.include?(' temporar') || issuedcode.include?(' persistent') return false end |