123456789_123456789_123456789_123456789_123456789_

Class: Net::SMTP::Response

Relationships & Source Files
Inherits: Object
Defined in: lib/net/smtp.rb

Overview

This class represents a response received by the ::Net::SMTP server. Instances of this class are created by the ::Net::SMTP class; they should not be directly created by the user. For more information on ::Net::SMTP responses, view Section 4.2 of RFC 5321

Class Method Summary

  • .new(status, string) ⇒ Response constructor

    Creates a new instance of the Response class and sets the status and string attributes.

  • .parse(str)

    Parses the received response and separates the reply code and the human readable reply text.

Instance Attribute Summary

Instance Method Summary

  • #capabilities

    Returns a hash of the human readable reply text in the response if it is multiple lines.

  • #cram_md5_challenge

    Creates a CRAM-MD5 challenge.

  • #exception_class

    Determines whether there was an error and raises the appropriate error based on the reply code of the response.

  • #message

    The first line of the human readable reply text.

  • #status_type_char

    Takes the first digit of the reply code to determine the status type.

Constructor Details

.new(status, string) ⇒ Response

Creates a new instance of the Response class and sets the status and string attributes

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1059

def initialize(status, string)
  @status = status
  @string = string
end

Class Method Details

.parse(str)

Parses the received response and separates the reply code and the human readable reply text

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1053

def self.parse(str)
  new(str[0,3], str)
end

Instance Attribute Details

#continue?Boolean (readonly)

Determines whether the response received was a Positive Intermediate reply (3xx reply code)

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1083

def continue?
  status_type_char() == '3'
end

#status (readonly)

The three digit reply code of the ::Net::SMTP response

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1065

attr_reader :status

#string (readonly)

The human readable reply text of the ::Net::SMTP response

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1068

attr_reader :string

#success?Boolean (readonly)

Determines whether the response received was a Positive Completion reply (2xx reply code)

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1077

def success?
  status_type_char() == '2'
end

Instance Method Details

#capabilities

Returns a hash of the human readable reply text in the response if it is multiple lines. It does not return the first line. The key of the hash is the first word the value of the hash is an array with each word thereafter being a value in the array

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1102

def capabilities
  return {} unless @string[3, 1] == '-'
  h = {}
  @string.lines.drop(1).each do |line|
    k, *v = line[4..-1].split(' ')
    h[k] = v
  end
  h
end

#cram_md5_challenge

Creates a CRAM-MD5 challenge. You can view more information on CRAM-MD5 on Wikipedia: en.wikipedia.org/wiki/CRAM-MD5

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1094

def cram_md5_challenge
  @string.split(/ /)[1].unpack1('m')
end

#exception_class

Determines whether there was an error and raises the appropriate error based on the reply code of the response

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1114

def exception_class
  case @status
  when /\A4/  then SMTPServerBusy
  when /\A50/ then SMTPSyntaxError
  when /\A53/ then SMTPAuthenticationError
  when /\A5/  then SMTPFatalError
  else             SMTPUnknownError
  end
end

#message

The first line of the human readable reply text

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1088

def message
  @string.lines.first
end

#status_type_char

Takes the first digit of the reply code to determine the status type

[ GitHub ]

  
# File 'lib/net/smtp.rb', line 1071

def status_type_char
  @status[0, 1]
end