summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-07 09:40:16 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-07 09:40:16 +0000
commit9a697aeb959af3549792e0bcc94f370c96163b94 (patch)
tree43a9f31a624933a37aca3cea37049a1182f2c010 /lib
parent15a67d6a2f3c194d9ea3abb9d30a8735fb12556f (diff)
aamine
* lib/net/smtp.rb: SMTP.new requires at least one arg. * lib/net/pop.rb: POP.new requires at least one arg. * lib/net/pop.rb: uses "raise *Error.new" instead of simple raise. * lib/net/http.rb: HTTP.new requires at least one arg. * lib/net/http.rb: changes implicit start algolithm. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http.rb37
-rw-r--r--lib/net/pop.rb64
-rw-r--r--lib/net/protocol.rb15
-rw-r--r--lib/net/smtp.rb21
4 files changed, 64 insertions, 73 deletions
diff --git a/lib/net/http.rb b/lib/net/http.rb
index c32a4ecaa7..e4f5b612ba 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -11,9 +11,8 @@ 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.
-NOTE: You can get Japanese version of this document from
-Ruby Documentation Project (RDP):
-((<URL:http://www.ruby-lang.org/~rubikitch/RDP.cgi>))
+NOTE: You can find Japanese version of this document in
+the doc/net directory of the standard ruby interpreter package.
== What is this module?
@@ -132,12 +131,12 @@ Yes, this is not thread-safe.
=== Class Methods
-: new( address = 'localhost', port = 80, proxy_addr = nil, proxy_port = nil )
+: new( address, port = 80, proxy_addr = nil, proxy_port = nil )
creates a new Net::HTTP object.
If proxy_addr is given, creates an Net::HTTP object with proxy support.
-: start( address = 'localhost', port = 80, proxy_addr = nil, proxy_port = nil )
-: start( address = 'localhost', port = 80, proxy_addr = nil, proxy_port = nil ) {|http| .... }
+: start( address, port = 80, proxy_addr = nil, proxy_port = nil )
+: start( address, port = 80, proxy_addr = nil, proxy_port = nil ) {|http| .... }
is equals to
Net::HTTP.new(address, port, proxy_addr, proxy_port).start(&block)
@@ -410,7 +409,7 @@ module Net
protocol_param :port, '80'
- def initialize( addr = nil, port = nil )
+ def initialize( addr, port = nil )
super
@curr_http_version = HTTPVersion
@@ -445,14 +444,14 @@ module Net
alias orig_new new
- def new( address = nil, port = nil, p_addr = nil, p_port = nil )
+ def new( address, port = nil, p_addr = nil, p_port = nil )
c = p_addr ? self::Proxy(p_addr, p_port) : self
i = c.orig_new( address, port )
setvar i
i
end
- def start( address = nil, port = nil, p_addr = nil, p_port = nil, &block )
+ def start( address, port = nil, p_addr = nil, p_port = nil, &block )
new( address, port, p_addr, p_port ).start( &block )
end
@@ -593,6 +592,13 @@ module Net
define_http_method_interface :Put, false, true
def request( req, body = nil )
+ unless active? then
+ start {
+ req['connection'] = 'close'
+ return request(req, body)
+ }
+ end
+
connecting( req ) {
req.__send__( :exec,
@socket, @curr_http_version, edit_path(req.path), body )
@@ -613,14 +619,7 @@ module Net
def connecting( req )
- unless active? then
- implicit = true
- req['connection'] ||= 'close'
- end
-
- if not @socket then
- start
- elsif @socket.closed? then
+ if @socket.closed? then
re_connect
end
if not req.body_exist? or @seems_1_0_server then
@@ -645,10 +644,6 @@ module Net
D 'Conn close'
@socket.close
end
-
- if implicit then
- finish
- end
end
def keep_alive?( req, res )
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index 78a0b47222..a31276a622 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -10,9 +10,8 @@ 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.
-NOTE: You can get Japanese version of this document from
-Ruby Documentation Project (RDP):
-((<URL:http://www.ruby-lang.org/~rubikitch/RDP.cgi>))
+NOTE: You can find Japanese version of this document in
+the doc/net directory of the standard ruby interpreter package.
== What is This Module?
@@ -116,12 +115,12 @@ net/pop also supports APOP authentication. There's two way to use APOP:
=== Class Methods
-: new( address = 'localhost', port = 110, apop = false )
+: new( address, port = 110, apop = false )
creates a new Net::POP3 object.
This method does not open TCP connection yet.
-: start( address = 'localhost', port = 110, account, password )
-: start( address = 'localhost', port = 110, account, password ) {|pop| .... }
+: start( address, port = 110, account, password )
+: start( address, port = 110, account, password ) {|pop| .... }
equals to Net::POP3.new( address, port ).start( account, password )
Net::POP3.start( addr, port, account, password ) do |pop|
@@ -131,7 +130,7 @@ net/pop also supports APOP authentication. There's two way to use APOP:
end
end
-: foreach( address = 'localhost', port = 110, account, password ) {|mail| .... }
+: foreach( address, port = 110, account, password ) {|mail| .... }
starts POP3 protocol and iterates for each POPMail object.
This method equals to
@@ -148,8 +147,8 @@ net/pop also supports APOP authentication. There's two way to use APOP:
m.delete if $DELETE
end
-: delete_all( address = 'localhost', port = 110, account, password )
-: delete_all( address = 'localhost', port = 110, account, password ) {|mail| .... }
+: delete_all( address, port = 110, account, password )
+: delete_all( address, port = 110, account, password ) {|mail| .... }
starts POP3 session and delete all mails.
If block is given, iterates for each POPMail object before delete.
@@ -158,7 +157,7 @@ net/pop also supports APOP authentication. There's two way to use APOP:
m.pop file
end
-: auth_only( address = 'localhost', port = 110, account, password )
+: auth_only( address, port = 110, account, password )
(just for POP-before-SMTP)
opens POP3 session and does autholize and quit.
This method must not be called while POP3 session is opened.
@@ -288,7 +287,7 @@ A class of mail which exists on POP server.
=end
require 'net/protocol'
-require 'digest/md5'
+require 'md5'
module Net
@@ -303,21 +302,21 @@ module Net
class << self
- def foreach( address = nil, port = nil,
+ def foreach( address, port = nil,
account = nil, password = nil, &block )
start( address, port, account, password ) do |pop|
pop.each_mail( &block )
end
end
- def delete_all( address = nil, port = nil,
+ def delete_all( address, port = nil,
account = nil, password = nil, &block )
start( address, port, account, password ) do |pop|
pop.delete_all( &block )
end
end
- def auth_only( address = nil, port = nil,
+ def auth_only( address, port = nil,
account = nil, password = nil )
new( address, port ).auth_only account, password
end
@@ -325,13 +324,13 @@ module Net
end
- def initialize( addr = nil, port = nil, apop = false )
+ def initialize( addr, port = nil, apop = false )
super addr, port
@mails = nil
@apop = false
end
- def auth_only( account = nil, password = nil )
+ def auth_only( account, password )
begin
connect
@active = true
@@ -422,14 +421,15 @@ module Net
"#<#{type} #{@num}#{@deleted ? ' deleted' : ''}>"
end
- def all( dest = '' )
- if block_given? then
- dest = NetPrivate::ReadAdapter.new( Proc.new )
+ def pop( dest = '', &block )
+ if block then
+ dest = NetPrivate::ReadAdapter.new( block )
end
@command.retr( @num, dest )
end
- alias pop all
- alias mail all
+
+ alias all pop
+ alias mail pop
def top( lines, dest = '' )
@command.top( @num, lines, dest )
@@ -440,7 +440,7 @@ module Net
end
def delete
- @command.dele( @num )
+ @command.dele @num
@deleted = true
end
@@ -470,9 +470,9 @@ module Net
}
end
- def auth( acnt, pass )
+ def auth( account, pass )
critical {
- @socket.writeline 'USER ' + acnt
+ @socket.writeline 'USER ' + account
check_reply_auth
@socket.writeline 'PASS ' + pass
@@ -537,21 +537,19 @@ module Net
def check_reply_auth
begin
- cod = check_reply( SuccessCode )
- rescue ProtocolError
- raise ProtoAuthError, 'Fail to POP authentication'
+ return check_reply( SuccessCode )
+ rescue ProtocolError => err
+ raise ProtoAuthError.new( 'Fail to POP authentication', err.response )
end
-
- return cod
end
def get_reply
str = @socket.readline
if /\A\+/ === str then
- return Response.new( SuccessCode, str[0,3], str[3, str.size - 3].strip )
+ Response.new( SuccessCode, str[0,3], str[3, str.size - 3].strip )
else
- return Response.new( ErrorCode, str[0,4], str[4, str.size - 4].strip )
+ Response.new( ErrorCode, str[0,4], str[4, str.size - 4].strip )
end
end
@@ -564,7 +562,7 @@ module Net
rep = super( sock )
m = /<.+>/.match( rep.msg ) or
- raise ProtoAuthError, "not APOP server: cannot login"
+ raise ProtoAuthError.new( "not APOP server: cannot login", nil )
@stamp = m[0]
end
@@ -572,7 +570,7 @@ module Net
critical {
@socket.writeline sprintf( 'APOP %s %s',
account,
- Digest::MD5.hexdigest(@stamp + pass) )
+ MD5.new(@stamp + pass).hexdigest )
check_reply_auth
}
end
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index b3652decce..9781fb690f 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -10,9 +10,8 @@ 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.
-NOTE: You can get Japanese version of this document from
-Ruby Documentation Project (RDP):
-((<URL:http://www.ruby-lang.org/~rubikitch/RDP.cgi>))
+NOTE: You can find Japanese version of this document in
+the doc/net directory of the standard ruby interpreter package.
=end
@@ -36,7 +35,7 @@ module Net
class << self
- def start( address = 'localhost', port = nil, *args )
+ def start( address, port = nil, *args )
instance = new( address, port )
if block_given? then
@@ -79,8 +78,8 @@ module Net
protocol_param :socket_type, '::Net::NetPrivate::Socket'
- def initialize( addr = nil, port = nil )
- @address = addr || 'localhost'
+ def initialize( addr, port = nil )
+ @address = addr
@port = port || type.port
@command = nil
@@ -213,9 +212,9 @@ module Net
class Response
- def initialize( ctype, cno, msg )
+ def initialize( ctype, code, msg )
@code_type = ctype
- @code = cno
+ @code = code
@message = msg
super()
end
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index dfd7f33d8e..8813d7f835 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -10,9 +10,8 @@ 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.
-NOTE: You can get Japanese version of this document from
-Ruby Documentation Project (RDP):
-((<URL:http://www.ruby-lang.org/~rubikitch/RDP.cgi>))
+NOTE: You can find Japanese version of this document in
+the doc/net directory of the standard ruby interpreter package.
== What is This Module?
@@ -90,11 +89,11 @@ send or reject SMTP session by this data.
=== Class Methods
-: new( address = 'localhost', port = 25 )
+: new( address, port = 25 )
creates a new Net::SMTP object.
-: start( address = 'localhost', port = 25, helo_domain = Socket.gethostname, account = nil, password = nil, authtype = nil )
-: start( address = 'localhost', port = 25, helo_domain = Socket.gethostname, account = nil, password = nil, authtype = nil ) {|smtp| .... }
+: start( address, port = 25, helo_domain = Socket.gethostname, account = nil, password = nil, authtype = nil )
+: start( address, port = 25, helo_domain = Socket.gethostname, account = nil, password = nil, authtype = nil ) {|smtp| .... }
is equal to
Net::SMTP.new(address,port).start(helo_domain,account,password,authtype)
@@ -192,7 +191,7 @@ SMTP objects raise these exceptions:
=end
require 'net/protocol'
-require 'digest/md5'
+require 'md5'
module Net
@@ -204,7 +203,7 @@ module Net
protocol_param :command_type, '::Net::NetPrivate::SMTPCommand'
- def initialize( addr = nil, port = nil )
+ def initialize( addr, port = nil )
super
@esmtp = true
end
@@ -318,7 +317,7 @@ module Net
critical {
rep = getok( 'AUTH CRAM-MD5', ContinueCode )
challenge = rep.msg.split(' ')[1].unpack('m')[0]
- secret = Digest::MD5.digest( secret ) if secret.size > 64
+ secret = MD5.new( secret ).digest if secret.size > 64
isecret = secret + "\0" * (64 - secret.size)
osecret = isecret.dup
@@ -326,8 +325,8 @@ module Net
isecret[i] ^= 0x36
osecret[i] ^= 0x5c
end
- tmp = Digest::MD5.digest( isecret + challenge )
- tmp = Digest::MD5.hexdigest( osecret + tmp )
+ tmp = MD5.new( isecret + challenge ).digest
+ tmp = MD5.new( osecret + tmp ).hexdigest
getok [user + ' ' + tmp].pack('m').chomp
}