14
14
# NOTE: You can find Japanese version of this document at:
15
15
# http://www.ruby-lang.org/ja/man/html/net_smtp.html
17
# $Id: smtp.rb 30324 2010-12-23 12:46:02Z yugui $
17
# $Id: smtp.rb 31710 2011-05-23 00:21:10Z drbrain $
19
19
# See Net::SMTP for documentation.
229
229
"#<#{self.class} #{@address}:#{@port} started=#{@started}>"
232
# +true+ if the SMTP object uses ESMTP (which it does by default).
238
233
# Set whether to use ESMTP or not. This should be done before
239
234
# calling #start. Note that if #start is called in ESMTP mode,
241
236
# object will automatically switch to plain SMTP mode and
242
237
# retry (but not vice versa).
241
# +true+ if the SMTP object uses ESMTP (which it does by default).
250
244
# true if server advertises STARTTLS.
251
245
# You cannot get valid value before opening SMTP session.
970
# This class represents a response received by the SMTP server. Instances
971
# of this class are created by the SMTP class; they should not be directly
972
# created by the user. For more information on SMTP responses, view
973
# {Section 4.2 of RFC 5321}[http://tools.ietf.org/html/rfc5321#section-4.2]
975
# Parses the received response and separates the reply code and the human
976
# readable reply text
977
977
def self.parse(str)
978
978
new(str[0,3], str)
981
# Creates a new instance of the Response class and sets the status and
981
983
def initialize(status, string)
988
# The three digit reply code of the SMTP response
986
989
attr_reader :status
991
# The human readable reply text of the SMTP response
987
992
attr_reader :string
994
# Takes the first digit of the reply code to determine the status type
989
995
def status_type_char
999
# Determines whether the response received was a Positive Completion
1000
# reply (2xx reply code)
994
1002
status_type_char() == '2'
1005
# Determines whether the response received was a Positive Intermediate
1006
# reply (3xx reply code)
998
1008
status_type_char() == '3'
1011
# The first line of the human readable reply text
1002
1013
@string.lines.first
1016
# Creates a CRAM-MD5 challenge. You can view more information on CRAM-MD5
1017
# on Wikipedia: http://en.wikipedia.org/wiki/CRAM-MD5
1005
1018
def cram_md5_challenge
1006
1019
@string.split(/ /)[1].unpack('m')[0]
1022
# Returns a hash of the human readable reply text in the response if it
1023
# is multiple lines. It does not return the first line. The key of the
1024
# hash is the first word the value of the hash is an array with each word
1025
# thereafter being a value in the array
1009
1026
def capabilities
1010
1027
return {} unless @string[3, 1] == '-'
1012
1029
@string.lines.drop(1).each do |line|
1013
k, *v = line[4..-1].chomp.split(nil)
1030
k, *v = line[4..-1].chomp.split
1036
# Determines whether there was an error and raies the appropriate error
1037
# based on the reply code of the response
1019
1038
def exception_class
1021
1040
when /\A4/ then SMTPServerBusy