module Sisimai::Rhost::ExchangeOnline

Sisimai::Rhost detects the bounce reason from the content of Sisimai::Data object as an argument of get() method when the value of “rhost” of the object is “*.protection.outlook.com”. This class is called only Sisimai::Data class.

Constants

MessagesOf
ReStatuses
StatusList

technet.microsoft.com/en-us/library/bb232118

Public Class Methods

get(argvs) click to toggle source

Detect bounce reason from Exchange Online @param [Sisimai::Data] argvs Parsed email object @return [String] The bounce reason for Exchange Online

# File lib/sisimai/rhost/exchangeonline.rb, line 123
def get(argvs)
  return argvs.reason unless argvs.reason.empty?

  statuscode = argvs.deliverystatus
  statusmesg = argvs.diagnosticcode
  reasontext = ''

  StatusList.each_key do |e|
    # Try to compare with each status code as a key
    next unless statuscode == e
    StatusList[e].each do |f|
      # Try to compare with each string of error messages
      next unless statusmesg.include?(f[:string])
      reasontext = f[:reason]
      break
    end
    break unless reasontext.empty?
  end
  return reasontext unless reasontext.empty?

  ReStatuses.each_key do |e|
    # Try to compare with each string of delivery status codes
    next unless statuscode =~ e
    ReStatuses[e].each do |f|
      # Try to compare with each string of error messages
      f[:string].each do |g|
        next unless statusmesg.include?(g)
        reasontext = f[:reason]
        break
      end
      break unless reasontext.empty?
    end
    break unless reasontext.empty?
  end
  return reasontext unless reasontext.empty?

  # D.S.N. included in the error message did not matched with any
  # key in ReStatuses
  MessagesOf.each_key do |e|
    # Try to compare with error messages defined in MessagesOf
    MessagesOf[e].each do |f|
      next unless statusmesg.include?(f)
      reasontext = e
      break
    end
    break unless reasontext.empty?
  end
  return reasontext
end