1999-10-13 03:29:15 -04:00
|
|
|
=begin
|
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
= net/smtp.rb
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
Copyright (c) 1999-2002 Yukihiro Matsumoto
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
written & maintained by Minero Aoki <aamine@loveruby.net>
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
This program is free software. You can re-distribute and/or
|
|
|
|
modify this program under the same terms as Ruby itself,
|
|
|
|
Ruby Distribute License or GNU General Public License.
|
2001-02-23 23:53:50 -05:00
|
|
|
|
2001-12-07 05:04:25 -05:00
|
|
|
NOTE: You can find Japanese version of this document in
|
|
|
|
the doc/net directory of the standard ruby interpreter package.
|
2000-09-21 02:58:01 -04:00
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
$Id$
|
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
== What is This Module?
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
This module provides your program the functions to send internet
|
|
|
|
mail via SMTP, Simple Mail Transfer Protocol. For details of
|
|
|
|
SMTP itself, refer [RFC2821] ((<URL:http://www.ietf.org/rfc/rfc2821.txt>)).
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
== What This Module is NOT?
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
This module does NOT provide the functions to compose internet
|
|
|
|
mail. You must create it by yourself. For details of internet mail
|
|
|
|
format, see [RFC2822] ((<URL:http://www.ietf.org/rfc/rfc2822.txt>)).
|
|
|
|
|
|
|
|
== Examples
|
|
|
|
|
|
|
|
=== Sending Mail
|
|
|
|
|
|
|
|
You must open connection to SMTP server before sending mails.
|
|
|
|
First argument is the address of SMTP server, and second argument
|
|
|
|
is port number. Using SMTP.start with block is the most simple way
|
|
|
|
to do it. SMTP Connection is closed automatically after block is
|
|
|
|
executed.
|
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
require 'net/smtp'
|
|
|
|
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
|
2001-12-09 03:58:30 -05:00
|
|
|
# use smtp object only in this block
|
2001-06-26 20:59:08 -04:00
|
|
|
}
|
2001-06-26 19:49:21 -04:00
|
|
|
|
|
|
|
Replace 'your.smtp.server' by your SMTP server. Normally
|
|
|
|
your system manager or internet provider is supplying a server
|
|
|
|
for you.
|
|
|
|
|
|
|
|
Then you can send mail.
|
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
require 'net/smtp'
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
|
2001-12-09 03:58:30 -05:00
|
|
|
smtp.send_mail <<EndOfMail, 'your@mail.address', 'to@some.domain'
|
2001-06-26 20:59:08 -04:00
|
|
|
From: Your Name <your@mail.address>
|
|
|
|
To: Dest Address <to@some.domain>
|
|
|
|
Subject: test mail
|
|
|
|
Date: Sat, 23 Jun 2001 16:26:43 +0900
|
|
|
|
Message-Id: <unique.message.id.string@some.domain>
|
|
|
|
|
|
|
|
This is test mail.
|
|
|
|
EndOfMail
|
|
|
|
}
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-12-09 03:58:30 -05:00
|
|
|
=== Closing Session
|
|
|
|
|
|
|
|
You MUST close SMTP session after sending mails, by calling #finish
|
|
|
|
method. You can also use block form of SMTP.start/SMTP#start, which
|
|
|
|
closes session automatically. I strongly recommend later one. It is
|
|
|
|
more beautiful and simple.
|
|
|
|
|
|
|
|
# using SMTP#finish
|
|
|
|
smtp = Net::SMTP.start( 'your.smtp.server', 25 )
|
|
|
|
smtp.send_mail mail_string, 'from@address', 'to@address'
|
|
|
|
smtp.finish
|
|
|
|
|
|
|
|
# using block form of SMTP.start
|
|
|
|
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
|
|
|
|
smtp.send_mail mail_string, 'from@address', 'to@address'
|
|
|
|
}
|
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
=== Sending Mails from Any Sources
|
|
|
|
|
|
|
|
In an example above I sent mail from String (here document literal).
|
|
|
|
SMTP#send_mail accepts any objects which has "each" method
|
|
|
|
like File and Array.
|
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
require 'net/smtp'
|
|
|
|
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
|
2001-12-09 03:58:30 -05:00
|
|
|
File.open( 'Mail/draft/1' ) {|f|
|
|
|
|
smtp.send_mail f, 'your@mail.address', 'to@some.domain'
|
|
|
|
}
|
2001-06-26 19:49:21 -04:00
|
|
|
}
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
=== HELO domain
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
In almost all situation, you must designate the third argument
|
|
|
|
of SMTP.start/SMTP#start. It is the domain name which you are on
|
|
|
|
(the host to send mail from). It is called "HELO domain".
|
|
|
|
SMTP server will judge if he/she should send or reject
|
|
|
|
the SMTP session by inspecting HELO domain.
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
Net::SMTP.start( 'your.smtp.server', 25,
|
|
|
|
'mail.from.domain' ) {|smtp|
|
2001-06-26 19:49:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
== class Net::SMTP
|
1999-10-13 03:29:15 -04:00
|
|
|
|
|
|
|
=== Class Methods
|
|
|
|
|
2001-08-16 23:08:45 -04:00
|
|
|
: new( address, port = 25 )
|
2001-06-26 20:59:08 -04:00
|
|
|
creates a new Net::SMTP object.
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
: start( address, port = 25, helo_domain = 'localhost.localdomain', account = nil, password = nil, authtype = nil )
|
|
|
|
: start( address, port = 25, helo_domain = 'localhost.localdomain', account = nil, password = nil, authtype = nil ) {|smtp| .... }
|
2001-06-26 20:59:08 -04:00
|
|
|
is equal to
|
|
|
|
Net::SMTP.new(address,port).start(helo_domain,account,password,authtype)
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
# example
|
|
|
|
Net::SMTP.start( 'your.smtp.server' ) {
|
2001-12-09 03:58:30 -05:00
|
|
|
smtp.send_mail mail_string, 'from@mail.address', 'dest@mail.address'
|
2001-06-26 20:59:08 -04:00
|
|
|
}
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
=== Instance Methods
|
|
|
|
|
|
|
|
: start( helo_domain = <local host name>, account = nil, password = nil, authtype = nil )
|
|
|
|
: start( helo_domain = <local host name>, account = nil, password = nil, authtype = nil ) {|smtp| .... }
|
2001-06-26 20:59:08 -04:00
|
|
|
opens TCP connection and starts SMTP session.
|
|
|
|
HELO_DOMAIN is a domain that you'll dispatch mails from.
|
2001-07-03 15:03:16 -04:00
|
|
|
If protocol had been started, raises IOError.
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
When this methods is called with block, give a SMTP object to block and
|
|
|
|
close session after block call finished.
|
2000-05-18 04:57:37 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
If both of account and password are given, is trying to get
|
|
|
|
authentication by using AUTH command. :plain or :cram_md5 is
|
|
|
|
allowed for AUTHTYPE.
|
2000-04-25 05:23:21 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: active?
|
|
|
|
true if SMTP session is started.
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: address
|
|
|
|
the address to connect
|
2000-07-01 14:28:24 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: port
|
|
|
|
the port number to connect
|
1999-10-13 03:29:15 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: open_timeout
|
|
|
|
: open_timeout=(n)
|
|
|
|
seconds to wait until connection is opened.
|
|
|
|
If SMTP object cannot open a conection in this seconds,
|
|
|
|
it raises TimeoutError exception.
|
2000-08-16 15:26:07 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: read_timeout
|
|
|
|
: read_timeout=(n)
|
|
|
|
seconds to wait until reading one block (by one read(1) call).
|
|
|
|
If SMTP object cannot open a conection in this seconds,
|
|
|
|
it raises TimeoutError exception.
|
2000-08-16 15:26:07 -04:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: finish
|
|
|
|
finishes SMTP session.
|
2001-07-03 15:03:16 -04:00
|
|
|
If SMTP session had not started, raises an IOError.
|
2000-02-21 10:25:37 -05:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
: send_mail( mailsrc, from_addr, *to_addrs )
|
2001-06-26 20:59:08 -04:00
|
|
|
This method sends MAILSRC as mail. A SMTP object read strings
|
|
|
|
from MAILSRC by calling "each" iterator, with converting them
|
|
|
|
into CRLF ("\r\n") terminated string when write.
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
FROM_ADDR must be a String, representing source mail address.
|
|
|
|
TO_ADDRS must be Strings or an Array of Strings, representing
|
|
|
|
destination mail addresses.
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
# example
|
|
|
|
Net::SMTP.start( 'your.smtp.server' ) {|smtp|
|
2001-12-09 03:58:30 -05:00
|
|
|
smtp.send_mail mail_string,
|
|
|
|
'from@mail.address',
|
|
|
|
'dest@mail.address' 'dest2@mail.address'
|
2001-06-26 20:59:08 -04:00
|
|
|
}
|
2001-06-26 19:49:21 -04:00
|
|
|
|
2001-06-26 20:59:08 -04:00
|
|
|
: ready( from_addr, *to_addrs ) {|adapter| .... }
|
|
|
|
This method stands by the SMTP object for sending mail and
|
2001-12-30 14:18:45 -05:00
|
|
|
gives adapter object to the block. ADAPTER has these 5 methods:
|
|
|
|
|
|
|
|
puts print printf write <<
|
2001-06-26 20:59:08 -04:00
|
|
|
|
|
|
|
FROM_ADDR must be a String, representing source mail address.
|
|
|
|
TO_ADDRS must be Strings or an Array of Strings, representing
|
|
|
|
destination mail addresses.
|
|
|
|
|
|
|
|
# example
|
|
|
|
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
|
2001-12-30 14:18:45 -05:00
|
|
|
smtp.ready( 'from@mail.addr', 'dest@mail.addr' ) {|f|
|
|
|
|
f.puts 'From: aamine@loveruby.net'
|
|
|
|
f.puts 'To: someone@somedomain.org'
|
|
|
|
f.puts 'Subject: test mail'
|
|
|
|
f.puts
|
|
|
|
f.puts 'This is test mail.'
|
|
|
|
}
|
2001-06-26 20:59:08 -04:00
|
|
|
}
|
2000-02-21 10:25:37 -05:00
|
|
|
|
2001-06-26 19:49:21 -04:00
|
|
|
== Exceptions
|
|
|
|
|
|
|
|
SMTP objects raise these exceptions:
|
|
|
|
: Net::ProtoSyntaxError
|
|
|
|
syntax error (errno.500)
|
|
|
|
: Net::ProtoFatalError
|
|
|
|
fatal error (errno.550)
|
|
|
|
: Net::ProtoUnknownError
|
|
|
|
unknown error. (is probably bug)
|
|
|
|
: Net::ProtoServerBusy
|
|
|
|
temporary error (errno.420/450)
|
1999-10-13 03:29:15 -04:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2000-06-12 12:42:46 -04:00
|
|
|
require 'net/protocol'
|
2001-12-01 09:07:01 -05:00
|
|
|
require 'digest/md5'
|
2000-06-12 12:42:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
module Net
|
|
|
|
|
1999-12-29 06:14:04 -05:00
|
|
|
class SMTP < Protocol
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
protocol_param :default_port, '25'
|
2001-12-13 14:15:21 -05:00
|
|
|
protocol_param :command_type, '::Net::SMTPCommand'
|
2002-02-19 07:33:52 -05:00
|
|
|
protocol_param :socket_type, '::Net::InternetMessageIO'
|
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
|
2001-08-16 23:08:45 -04:00
|
|
|
def initialize( addr, port = nil )
|
2000-04-18 05:39:02 -04:00
|
|
|
super
|
|
|
|
@esmtp = true
|
|
|
|
end
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
def esmtp?
|
|
|
|
@esmtp
|
|
|
|
end
|
|
|
|
|
|
|
|
def esmtp=( bool )
|
|
|
|
@esmtp = bool
|
|
|
|
end
|
|
|
|
|
|
|
|
alias esmtp esmtp?
|
2000-04-18 05:39:02 -04:00
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
private
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def do_start( helo = 'localhost.localdomain',
|
2000-04-25 05:23:21 -04:00
|
|
|
user = nil, secret = nil, authtype = nil )
|
2001-12-30 14:18:45 -05:00
|
|
|
conn_socket
|
|
|
|
conn_command
|
2000-02-21 10:25:37 -05:00
|
|
|
|
|
|
|
begin
|
2000-04-18 05:39:02 -04:00
|
|
|
if @esmtp then
|
2001-12-30 14:18:45 -05:00
|
|
|
command().ehlo helo
|
2000-04-18 05:39:02 -04:00
|
|
|
else
|
2001-12-30 14:18:45 -05:00
|
|
|
command().helo helo
|
2000-04-18 05:39:02 -04:00
|
|
|
end
|
2000-02-21 10:25:37 -05:00
|
|
|
rescue ProtocolError
|
2000-04-18 05:39:02 -04:00
|
|
|
if @esmtp then
|
|
|
|
@esmtp = false
|
2001-12-30 14:18:45 -05:00
|
|
|
command().error_ok
|
2000-04-18 05:39:02 -04:00
|
|
|
retry
|
|
|
|
else
|
|
|
|
raise
|
|
|
|
end
|
2000-02-21 10:25:37 -05:00
|
|
|
end
|
2000-04-25 05:23:21 -04:00
|
|
|
|
2001-03-13 00:48:58 -05:00
|
|
|
if user or secret then
|
|
|
|
(user and secret) or
|
2001-06-26 19:49:21 -04:00
|
|
|
raise ArgumentError, 'both of account and password are required'
|
2001-03-13 00:48:58 -05:00
|
|
|
|
2000-06-01 09:43:43 -04:00
|
|
|
mid = 'auth_' + (authtype || 'cram_md5').to_s
|
2001-12-30 14:18:45 -05:00
|
|
|
command().respond_to? mid or
|
2001-03-13 00:48:58 -05:00
|
|
|
raise ArgumentError, "wrong auth type #{authtype.to_s}"
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
command().__send__ mid, user, secret
|
2000-04-25 05:23:21 -04:00
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def do_finish
|
|
|
|
disconn_command
|
|
|
|
disconn_socket
|
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
#
|
|
|
|
# SMTP operations
|
|
|
|
#
|
|
|
|
|
|
|
|
public
|
|
|
|
|
|
|
|
def send_mail( mailsrc, from_addr, *to_addrs )
|
|
|
|
do_ready from_addr, to_addrs.flatten
|
2002-02-19 07:33:52 -05:00
|
|
|
command().write_mail mailsrc
|
2001-12-30 14:18:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
alias sendmail send_mail
|
|
|
|
|
|
|
|
def ready( from_addr, *to_addrs, &block )
|
|
|
|
do_ready from_addr, to_addrs.flatten
|
2002-02-19 07:33:52 -05:00
|
|
|
command().through_mail &block
|
2001-12-30 14:18:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def do_ready( from_addr, to_addrs )
|
2002-02-19 07:33:52 -05:00
|
|
|
raise ArgumentError, 'mail destination does not given' if to_addrs.empty?
|
2001-12-30 14:18:45 -05:00
|
|
|
command().mailfrom from_addr
|
|
|
|
command().rcpt to_addrs
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
SMTPSession = SMTP
|
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
|
|
|
|
class SMTPCommand < Command
|
|
|
|
|
1999-12-17 10:00:13 -05:00
|
|
|
def initialize( sock )
|
|
|
|
super
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
check_reply SuccessCode
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
1999-12-17 10:00:13 -05:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def helo( domain )
|
|
|
|
atomic {
|
|
|
|
getok sprintf('HELO %s', domain)
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2001-12-30 14:18:45 -05:00
|
|
|
def ehlo( domain )
|
|
|
|
atomic {
|
|
|
|
getok sprintf('EHLO %s', domain)
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
2000-02-21 10:25:37 -05:00
|
|
|
end
|
|
|
|
|
2000-04-25 05:23:21 -04:00
|
|
|
# "PLAIN" authentication [RFC2554]
|
|
|
|
def auth_plain( user, secret )
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
getok sprintf('AUTH PLAIN %s',
|
|
|
|
["\0#{user}\0#{secret}"].pack('m').chomp)
|
2000-04-25 05:23:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# "CRAM-MD5" authentication [RFC2195]
|
|
|
|
def auth_cram_md5( user, secret )
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
rep = getok( 'AUTH CRAM-MD5', ContinueCode )
|
|
|
|
challenge = rep.msg.split(' ')[1].unpack('m')[0]
|
|
|
|
secret = Digest::MD5.digest(secret) if secret.size > 64
|
|
|
|
|
|
|
|
isecret = secret + "\0" * (64 - secret.size)
|
|
|
|
osecret = isecret.dup
|
|
|
|
0.upto( 63 ) do |i|
|
|
|
|
isecret[i] ^= 0x36
|
|
|
|
osecret[i] ^= 0x5c
|
|
|
|
end
|
|
|
|
tmp = Digest::MD5.digest( isecret + challenge )
|
|
|
|
tmp = Digest::MD5.hexdigest( osecret + tmp )
|
|
|
|
|
|
|
|
getok [user + ' ' + tmp].pack('m').chomp
|
2000-04-25 05:23:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
1999-09-22 03:32:33 -04:00
|
|
|
def mailfrom( fromaddr )
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
getok sprintf('MAIL FROM:<%s>', fromaddr)
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def rcpt( toaddrs )
|
|
|
|
toaddrs.each do |i|
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
getok sprintf('RCPT TO:<%s>', i)
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
def write_mail( src )
|
|
|
|
atomic {
|
|
|
|
getok 'DATA', ContinueCode
|
|
|
|
@socket.write_message src
|
|
|
|
check_reply SuccessCode
|
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2002-02-19 07:33:52 -05:00
|
|
|
def through_mail( &block )
|
|
|
|
atomic {
|
|
|
|
getok 'DATA', ContinueCode
|
|
|
|
@socket.through_message(&block)
|
|
|
|
check_reply SuccessCode
|
|
|
|
}
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
2000-03-27 10:52:27 -05:00
|
|
|
def quit
|
2001-12-30 14:18:45 -05:00
|
|
|
atomic {
|
|
|
|
getok 'QUIT'
|
2000-03-27 10:52:27 -05:00
|
|
|
}
|
|
|
|
end
|
1999-09-22 03:32:33 -04:00
|
|
|
|
2000-03-27 10:52:27 -05:00
|
|
|
private
|
1999-09-22 03:32:33 -04:00
|
|
|
|
|
|
|
def get_reply
|
|
|
|
arr = read_reply
|
|
|
|
stat = arr[0][0,3]
|
|
|
|
|
1999-12-29 06:14:04 -05:00
|
|
|
klass = case stat[0]
|
|
|
|
when ?2 then SuccessCode
|
|
|
|
when ?3 then ContinueCode
|
2000-03-31 08:02:40 -05:00
|
|
|
when ?4 then ServerErrorCode
|
1999-12-29 06:14:04 -05:00
|
|
|
when ?5 then
|
|
|
|
case stat[1]
|
|
|
|
when ?0 then SyntaxErrorCode
|
2000-04-25 05:23:21 -04:00
|
|
|
when ?3 then AuthErrorCode
|
1999-12-29 06:14:04 -05:00
|
|
|
when ?5 then FatalErrorCode
|
|
|
|
end
|
|
|
|
end
|
2000-04-25 05:23:21 -04:00
|
|
|
klass ||= UnknownCode
|
1999-12-29 06:14:04 -05:00
|
|
|
|
2000-03-31 08:02:40 -05:00
|
|
|
Response.new( klass, stat, arr.join('') )
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def read_reply
|
|
|
|
arr = []
|
2000-04-25 05:23:21 -04:00
|
|
|
while true do
|
|
|
|
str = @socket.readline
|
|
|
|
break unless str[3] == ?- # ex: "210-..."
|
1999-09-22 03:32:33 -04:00
|
|
|
arr.push str
|
|
|
|
end
|
|
|
|
arr.push str
|
|
|
|
|
2000-08-16 15:26:07 -04:00
|
|
|
arr
|
1999-09-22 03:32:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26.
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb:
add module Net::NetPrivate and its inner classes
{Read,Write}Adapter, Command, Socket,
SMTPCommand, POP3Command, APOPCommand, HTTPCommand
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2000-07-12 02:04:40 -04:00
|
|
|
|
2001-12-13 14:15:21 -05:00
|
|
|
# for backward compatibility
|
|
|
|
module NetPrivate
|
|
|
|
SMTPCommand = ::Net::SMTPCommand
|
|
|
|
end
|
aamine
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb: 1.1.26.
* lib/net/protocol.rb, smtp.rb, pop.rb, http.rb:
add module Net::NetPrivate and its inner classes
{Read,Write}Adapter, Command, Socket,
SMTPCommand, POP3Command, APOPCommand, HTTPCommand
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2000-07-12 02:04:40 -04:00
|
|
|
|
|
|
|
end # module Net
|