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

Class Method Details

.is_hardbounce(argv1 = '', argv2 = '') ⇒ Boolean

Checks the reason sisimai detected is a hard bounce or not

Parameters:

  • argv1 (String) (defaults to: '')

    Detected bounce reason

  • argv2 (String) (defaults to: '')

    String including SMTP Status code

Returns:

  • (Boolean)

    true: is a hard bounce



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sisimai/smtp/failure.rb', line 46

def is_hardbounce(argv1 = '', argv2 = '')
  return false if argv1.to_s == ""
  return false if argv1 == Sisimai::Eb::Re___0 || argv1 == Sisimai::Eb::Re___1
  return false if argv1 == Sisimai::Eb::ReSENT || argv1 == Sisimai::Eb::ReFEED || argv1 == Sisimai::Eb::ReAWAY
  return true  if argv1 == Sisimai::Eb::ReMOVE || argv1 == Sisimai::Eb::ReUSER || argv1 == Sisimai::Eb::ReHOST
  return false if argv1 != Sisimai::Eb::Re00MX

  # 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

Parameters:

  • argv1 (String) (defaults to: '')

    String including SMTP Status code

Returns:

  • (Boolean)

    true: Permanet error false: Is not a permanent error

Since:

  • v4.17.3



15
16
17
18
19
20
21
22
23
# File 'lib/sisimai/smtp/failure.rb', line 15

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

Parameters:

  • argv1 (String) (defaults to: '')

    Detected bounce reason

  • argv2 (String) (defaults to: '')

    String including SMTP Status code

Returns:

  • (Boolean)

    true: is a soft bounce



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sisimai/smtp/failure.rb', line 74

def is_softbounce(argv1 = '', argv2 = '')
  return false if argv1.to_s == ""
  return false if argv1 == Sisimai::Eb::ReSENT || argv1 == Sisimai::Eb::ReFEED || argv1 == Sisimai::Eb::ReAWAY
  return false if argv1 == Sisimai::Eb::ReMOVE || argv1 == Sisimai::Eb::ReUSER || argv1 == Sisimai::Eb::ReHOST
  return true  if argv1 == Sisimai::Eb::Re___0 || argv1 == Sisimai::Eb::Re___0
  return true  if argv1 != Sisimai::Eb::Re00MX

  # 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

Parameters:

  • argv1 (String) (defaults to: '')

    String including SMTP Status code

Returns:

  • (Boolean)

    true: Temporary error false: is not a temporary error

Since:

  • v5.2.0



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sisimai/smtp/failure.rb', line 30

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