Class: Net::SMTP::Response
- Inherits:
-
Object
- Object
- Net::SMTP::Response
- Defined in:
- lib/net/smtp.rb
Overview
This class represents a response received by the SMTP server. Instances of this class are created by the SMTP class; they should not be directly created by the user. For more information on SMTP responses, view Section 4.2 of RFC 5321
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
The three digit reply code of the SMTP response.
-
#string ⇒ Object
readonly
The human readable reply text of the SMTP response.
Class Method Summary collapse
-
.parse(str) ⇒ Object
Parses the received response and separates the reply code and the human readable reply text.
Instance Method Summary collapse
-
#capabilities ⇒ Object
Returns a hash of the human readable reply text in the response if it is multiple lines.
-
#continue? ⇒ Boolean
Determines whether the response received was a Positive Intermediate reply (3xx reply code).
-
#cram_md5_challenge ⇒ Object
Creates a CRAM-MD5 challenge.
-
#exception_class ⇒ Object
Determines whether there was an error and raises the appropriate error based on the reply code of the response.
-
#initialize(status, string) ⇒ Response
constructor
Creates a new instance of the Response class and sets the status and string attributes.
-
#message ⇒ Object
The first line of the human readable reply text.
-
#status_type_char ⇒ Object
Takes the first digit of the reply code to determine the status type.
-
#success? ⇒ Boolean
Determines whether the response received was a Positive Completion reply (2xx reply code).
Constructor Details
#initialize(status, string) ⇒ Response
Creates a new instance of the Response class and sets the status and string attributes
1111 1112 1113 1114 |
# File 'lib/net/smtp.rb', line 1111 def initialize(status, string) @status = status @string = string end |
Instance Attribute Details
#status ⇒ Object (readonly)
The three digit reply code of the SMTP response
1117 1118 1119 |
# File 'lib/net/smtp.rb', line 1117 def status @status end |
#string ⇒ Object (readonly)
The human readable reply text of the SMTP response
1120 1121 1122 |
# File 'lib/net/smtp.rb', line 1120 def string @string end |
Class Method Details
.parse(str) ⇒ Object
Parses the received response and separates the reply code and the human readable reply text
1105 1106 1107 |
# File 'lib/net/smtp.rb', line 1105 def self.parse(str) new(str[0,3], str) end |
Instance Method Details
#capabilities ⇒ Object
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
1154 1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/net/smtp.rb', line 1154 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 |
#continue? ⇒ Boolean
Determines whether the response received was a Positive Intermediate reply (3xx reply code)
1135 1136 1137 |
# File 'lib/net/smtp.rb', line 1135 def continue? status_type_char() == '3' end |
#cram_md5_challenge ⇒ Object
Creates a CRAM-MD5 challenge. You can view more information on CRAM-MD5 on Wikipedia: en.wikipedia.org/wiki/CRAM-MD5
1146 1147 1148 |
# File 'lib/net/smtp.rb', line 1146 def cram_md5_challenge @string.split(/ /)[1].unpack1('m') end |
#exception_class ⇒ Object
Determines whether there was an error and raises the appropriate error based on the reply code of the response
1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/net/smtp.rb', line 1166 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 ⇒ Object
The first line of the human readable reply text
1140 1141 1142 |
# File 'lib/net/smtp.rb', line 1140 def @string.lines.first end |
#status_type_char ⇒ Object
Takes the first digit of the reply code to determine the status type
1123 1124 1125 |
# File 'lib/net/smtp.rb', line 1123 def status_type_char @status[0, 1] end |
#success? ⇒ Boolean
Determines whether the response received was a Positive Completion reply (2xx reply code)
1129 1130 1131 |
# File 'lib/net/smtp.rb', line 1129 def success? status_type_char() == '2' end |