module Sisimai::SMTP::Status

Sisimai::RFC3463 is utilities for getting D.S.N. value from error reason text, getting the reason from D.S.N. value, and getting D.S.N. from the text including D.S.N.

Constants

CodePatterns
InternalCode
StandardCode

Public Class Methods

code(argv1 = nil, argv2 = false) click to toggle source

Convert from the reason string to the internal status code @param [String] argv1 Reason name @param [True,False] argv2 false: Permanent error

true:  Temporary error

@return [String, Nil] DSN or Nil if the 1st argument is missing @see name

# File lib/sisimai/smtp/status.rb, line 719
def code(argv1 = nil, argv2 = false)
  return nil unless argv1
  return nil if argv1.empty?

  table = argv2 ? InternalCode[:temporary] : InternalCode[:permanent]
  code0 = table[argv1] || InternalCode[:permanent][argv1] || nil
  return code0
end
find(argv1 = nil) click to toggle source

Get a DSN code value from given string including DSN @param [String] argv1 String including DSN @return [String, Nil] DSN or Nil if the first agument did not

include DSN
# File lib/sisimai/smtp/status.rb, line 743
def find(argv1 = nil)
  return nil unless argv1
  return nil if argv1.empty?

  found = nil
  CodePatterns.each do |e|
    # Get the value of D.S.N. in the text
    next unless r = argv1.match(e)
    found = r[1]

    if argv1 =~ /\b(?:#{found}[.]\d{1,3}|\d{1,3}[.]#{found})\b/
      # Clear and skip if the value is an IPv4 address
      found = nil
      next
    end
    break
  end

  return found
end
name(argv1 = nil) click to toggle source

Convert from the status code to the reason string @param [String] argv1 Status code(DSN) @return [String, Nil] Reason name or Nil if the first argument did

not match with values in Sisimai's reason list

@see code

# File lib/sisimai/smtp/status.rb, line 733
def name(argv1 = nil)
  return nil unless argv1
  return nil unless argv1 =~ /\A[245][.]\d[.]\d+\z/
  return StandardCode[argv1] || nil
end