module Sisimai::SMTP::Reply

Sisimai::SMTP::Reply is utilities for getting SMTP Reply Code value from error message text.

Constants

IP4Re

Public Class Methods

find(argv1 = nil) click to toggle source

Get SMTP Reply Code from the given string @param [String] argv1 String including SMTP Reply Code like 550 @return [String] SMTP Reply Code or Nil if the first argument

did not include SMTP Reply Code value
# File lib/sisimai/smtp/reply.rb, line 75
def find(argv1 = nil)
  return nil unless argv1
  return nil if argv1.empty?
  return nil if argv1.upcase.include?('X-UNIX')

  # Convert found IPv4 addresses to '***.***.***.***' to avoid that
  # the following code detects an octet of the IPv4 adress as an SMTP
  # reply code.
  argv1 = argv1.gsub(/#{IP4Re}/, '***.***.***.***') if argv1 =~ IP4Re

  if cv = argv1.match(/\b([45][0-7][0-9])\b/) || argv1.match(/\b(25[0-3])\b/)
    # 550, 447, or 250
    return cv[1]
  else
    return nil
  end
end