* lib/net/pop.rb: new method Net::POP3.APOP
* lib/net/http.rb: set default Content-Type to x-www-form-urlencoded (causes warning)
* lib/net/protocol.rb: remove Net::NetPrivate module.
* lib/net/smtp.rb: ditto.
* lib/net/pop.rb: ditto.
* lib/net/http.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2001-12-13 19:15:21 +00:00
Родитель d8c75ddad3
Коммит 39c0252e04
8 изменённых файлов: 156 добавлений и 133 удалений

Просмотреть файл

@ -1,3 +1,18 @@
Fri Dec 14 04:23:36 2001 Minero Aoki <aamine@loveruby.net>
* lib/net/pop.rb: new method Net::POP3.APOP
* lib/net/http.rb: set default Content-Type to
x-www-form-urlencoded (causes warning)
* lib/net/protocol.rb: remove Net::NetPrivate module.
* lib/net/smtp.rb: ditto.
* lib/net/pop.rb: ditto.
* lib/net/http.rb: ditto.
Thu Dec 13 09:52:59 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_new_internal): avoid loop to calculate negative

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/http.rb version 1.2.3
= net/http.rb
== このライブラリについて

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/pop.rb version 1.2.3
= net/pop.rb
== このライブラリについて
@ -120,26 +120,20 @@ POP3#delete_all
=== APOP
APOP 認証を使うには
(1) POP3 クラスのかわりに APOP クラスを使う
(2) POP3.start の第五引数に true を渡す
の二通りの方法があります。
Net::POP3 クラスのかわりに Net::APOP クラスを使うと、認証時に APOP を
使うようになります。また動的にノーマル POP と APOP を選択するには、
以下のように Net::POP3.APOP() メソッドを使うのが便利です。
# (1)
require 'net/pop'
Net::APOP.start( 'apop.server.address', 110,
'YourAccount', 'YourPassword' ) {|pop|
# use APOP authentication if $isapop == true
pop = Net::POP3.APOP($isapop).new( 'apop.server.address', 110 )
pop.start( YourAccount', 'YourPassword' ) {|pop|
# Rest code is same.
}
# (2)
require 'net/pop'
Net::POP3.start( 'apop.server.address', 110,
'YourAccount', 'YourPassword',
true ####
) {|pop|
# Rest code is same.
}
この方法はクラス自体を変えるので、クラスメソッドの start や foreach、
delete_all、auth_only なども APOP とともに使えます。
== Net::POP3 class
@ -162,6 +156,18 @@ APOP ǧ
end
}
: APOP( is_apop )
bool が真なら Net::APOP クラス、偽なら Net::POP3 クラスを返します。
以下の例のように使ってください。
# example 1
pop = Net::POP3::APOP($isapop).new( addr, port )
# example 2
Net::POP3::APOP($isapop).start( addr, port ) {|pop|
....
}
: foreach( address, port = 110, account, password ) {|mail| .... }
POP セッションを開き、サーバ上のすべてのメールに対して繰り返します。
以下と同じです。

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/smtp.rb version 1.2.3
= net/smtp.rb
== このライブラリについて

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/http.rb version 1.2.3
= net/http.rb
Copyright (c) 1999-2001 Yukihiro Matsumoto
@ -14,6 +14,8 @@ Ruby Distribute License or GNU General Public License.
NOTE: You can find Japanese version of this document in
the doc/net directory of the standard ruby interpreter package.
$Id$
== What is this module?
This module provide your program the functions to access WWW
@ -655,9 +657,8 @@ module Net
end
def send_request( name, path, body = nil, header = nil )
r = ::Net::NetPrivate::HTTPGenericRequest.new(
name, (body ? true : false), true,
path, header )
r = HTTPGenericRequest.new( name, (body ? true : false), true,
path, header )
request r, body
end
@ -818,8 +819,6 @@ module Net
### header
###
net_private {
module HTTPHeader
def size
@ -836,10 +835,12 @@ module Net
@header[ key.downcase ] = val
end
def each( &block )
def each_header( &block )
@header.each( &block )
end
alias each each_header
def each_key( &block )
@header.each_key( &block )
end
@ -967,7 +968,7 @@ module Net
class HTTPGenericRequest
include ::Net::NetPrivate::HTTPHeader
include HTTPHeader
def initialize( m, reqbody, resbody, path, uhead = nil )
@method = m
@ -1060,6 +1061,11 @@ module Net
@header['content-length'] = data.size.to_s
@header.delete 'transfer-encoding'
unless @header['content-type'] then
$stderr.puts 'Content-Type did not set; using application/x-www-form-urlencoded' if $VERBOSE
@header['content-type'] = 'application/x-www-form-urlencoded'
end
request sock, ver, path
sock.write data
end
@ -1078,8 +1084,7 @@ module Net
def get_response( sock )
begin
resp = ::Net::NetPrivate::HTTPResponse.new_from_socket(sock,
response_body_permitted?)
resp = HTTPResponse.new_from_socket(sock, response_body_permitted?)
end while ContinueCode === resp
resp
end
@ -1122,30 +1127,28 @@ module Net
end
}
class HTTP
class Get < ::Net::NetPrivate::HTTPRequest
class Get < HTTPRequest
METHOD = 'GET'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = true
end
class Head < ::Net::NetPrivate::HTTPRequest
class Head < HTTPRequest
METHOD = 'HEAD'
REQUEST_HAS_BODY = false
RESPONSE_HAS_BODY = false
end
class Post < ::Net::NetPrivate::HTTPRequest
class Post < HTTPRequest
METHOD = 'POST'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
class Put < ::Net::NetPrivate::HTTPRequest
class Put < HTTPRequest
METHOD = 'PUT'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
@ -1159,11 +1162,9 @@ module Net
### response
###
net_private {
class HTTPResponse < Response
include ::Net::NetPrivate::HTTPHeader
include HTTPHeader
CODE_CLASS_TO_OBJ = {
'1' => HTTPInformationCode,
@ -1373,7 +1374,7 @@ module Net
raise ArgumentError, 'both of arg and block are given for HTTP method'
end
if block then
::Net::NetPrivate::ReadAdapter.new block
ReadAdapter.new block
else
dest || ''
end
@ -1381,10 +1382,15 @@ module Net
end
}
HTTPResponse = NetPrivate::HTTPResponse
HTTPResponseReceiver = NetPrivate::HTTPResponse
# for backward compatibility
module NetPrivate
HTTPResponse = ::Net::HTTPResponse
HTTPGenericRequest = ::Net::HTTPGenericRequest
HTTPRequest = ::Net::HTTPRequest
Accumulator = ::Net::Accumulator
HTTPHeader = ::Net::HTTPHeader
end
HTTPResponceReceiver = HTTPResponse
end # module Net

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/pop.rb version 1.2.3
= net/pop.rb
Copyright (c) 1999-2001 Yukihiro Matsumoto
@ -13,6 +13,8 @@ Ruby Distribute License or GNU General Public License.
NOTE: You can find Japanese version of this document in
the doc/net directory of the standard ruby interpreter package.
$Id$
== What is This Module?
This module provides your program the functions to retrieve
@ -123,25 +125,18 @@ This example does not create such one.
=== Using APOP
net/pop also supports APOP authentication. There's two way to use APOP:
(1) using APOP class instead of POP3
(2) passing true for fifth argument of POP3.start
The net/pop library supports APOP authentication.
To use APOP, use Net::APOP class instead of Net::POP3 class.
You can use utility method, Net::POP3.APOP(). Example:
# (1)
require 'net/pop'
Net::APOP.start( 'apop.server.address', 110,
'YourAccount', 'YourPassword' ) {|pop|
# use APOP authentication if $isapop == true
pop = Net::POP3.APOP($isapop).new( 'apop.server.address', 110 )
pop.start( YourAccount', 'YourPassword' ) {|pop|
# Rest code is same.
}
# (2)
require 'net/pop'
Net::POP3.start( 'apop.server.address', 110,
'YourAccount', 'YourPassword',
true ####
) {|pop|
# Rest code is same.
}
== Net::POP3 class
@ -162,6 +157,19 @@ net/pop also supports APOP authentication. There's two way to use APOP:
end
}
: APOP( is_apop )
returns Net::APOP class object if IS_APOP is true.
returns Net::POP3 class object if false.
Use this method like:
# example 1
pop = Net::POP3::APOP($isapop).new( addr, port )
# example 2
Net::POP3::APOP($isapop).start( addr, port ) {|pop|
....
}
: foreach( address, port = 110, account, password ) {|mail| .... }
starts POP3 protocol and iterates for each POPMail object.
This method equals to
@ -326,14 +334,17 @@ module Net
class POP3 < Protocol
protocol_param :port, '110'
protocol_param :command_type, '::Net::NetPrivate::POP3Command'
protocol_param :apop_command_type, '::Net::NetPrivate::APOPCommand'
protocol_param :mail_type, '::Net::POPMail'
protocol_param :port, '110'
protocol_param :command_type, '::Net::POP3Command'
protocol_param :apop_command_type, '::Net::APOPCommand'
protocol_param :mail_type, '::Net::POPMail'
class << self
def APOP( bool )
bool ? APOP : POP3
end
def foreach( address, port = nil,
account = nil, password = nil, &block )
start( address, port, account, password ) do |pop|
@ -366,7 +377,7 @@ module Net
begin
connect
@active = true
@command.auth address, port
@command.auth address(), port()
@command.quit
ensure
@active = false
@ -431,7 +442,7 @@ module Net
class APOP < POP3
protocol_param :command_type, 'Net::NetPrivate::APOPCommand'
protocol_param :command_type, '::Net::APOPCommand'
end
APOPSession = APOP
@ -455,7 +466,7 @@ module Net
def pop( dest = '', &block )
if block then
dest = NetPrivate::ReadAdapter.new( block )
dest = ReadAdapter.new( block )
end
@command.retr( @num, dest )
end
@ -490,9 +501,6 @@ module Net
module NetPrivate
class POP3Command < Command
def initialize( sock )
@ -609,7 +617,4 @@ module Net
end
end # module Net::NetPrivate
end # module Net

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/protocol.rb version 1.2.3
= net/protocol.rb
Copyright (c) 1999-2001 Yukihiro Matsumoto
@ -13,6 +13,8 @@ Ruby Distribute License or GNU General Public License.
NOTE: You can find Japanese version of this document in
the doc/net directory of the standard ruby interpreter package.
$Id$
=end
require 'socket'
@ -21,17 +23,10 @@ require 'timeout'
module Net
module NetPrivate
end
def self.net_private( &block )
::Net::NetPrivate.module_eval( &block )
end
class Protocol
Version = '1.2.3'
Revision = %q$Revision$.split(/\s+/)[1]
class << self
@ -75,7 +70,7 @@ module Net
protocol_param :port, 'nil'
protocol_param :command_type, 'nil'
protocol_param :socket_type, '::Net::NetPrivate::Socket'
protocol_param :socket_type, '::Net::Socket'
def initialize( addr, port = nil )
@ -208,8 +203,6 @@ module Net
Session = Protocol
net_private {
class Response
def initialize( ctype, code, msg )
@ -227,13 +220,11 @@ module Net
end
def error!
raise code_type.error_type.new( code + ' ' + Net.quote(msg), self )
raise @code_type.error_type.new( code + ' ' + Net.quote(msg), self )
end
end
}
class ProtocolError < StandardError; end
class ProtoSyntaxError < ProtocolError; end
@ -265,16 +256,16 @@ module Net
class Code
def initialize( paren, err )
@parents = paren
@parents = [self] + paren
@err = err
@parents.push self
end
attr_reader :parents
def parents
@parents.dup
end
def inspect
"#<#{type}>"
"#<#{type} #{sprintf '0x%x', __id__}>"
end
def error_type
@ -282,12 +273,12 @@ module Net
end
def ===( response )
response.code_type.parents.reverse_each {|i| return true if i == self }
response.code_type.parents.each {|c| return true if c == self }
false
end
def mkchild( err = nil )
type.new( @parents + [self], err || @err )
type.new( @parents, err || @err )
end
end
@ -306,12 +297,10 @@ module Net
net_private {
class WriteAdapter
def initialize( sock, mid )
@sock = sock
@socket = sock
@mid = mid
end
@ -320,11 +309,11 @@ module Net
end
def write( str )
@sock.__send__ @mid, str
@socket.__send__ @mid, str
end
def <<( str )
@sock.__send__ @mid, str
@socket.__send__ @mid, str
self
end
@ -357,7 +346,7 @@ module Net
ensure
if user_break then
@block = nil
return # stop break
return # stop breaking
end
end
end
@ -457,7 +446,7 @@ module Net
@socket = nil
@sending = ''
@buffer = ''
@rbuf = ''
connect otime
D 'opened'
@ -498,7 +487,7 @@ module Net
D 'close call for already closed socket'
end
@socket = nil
@buffer = ''
@rbuf = ''
end
def closed?
@ -524,7 +513,7 @@ module Net
#
# read
# input
#
public
@ -536,8 +525,8 @@ module Net
rsize = 0
begin
while rsize + @buffer.size < len do
rsize += rbuf_moveto( dest, @buffer.size )
while rsize + @rbuf.size < len do
rsize += rbuf_moveto( dest, @rbuf.size )
rbuf_fill
end
rbuf_moveto dest, len - rsize
@ -555,7 +544,7 @@ module Net
rsize = 0
begin
while true do
rsize += rbuf_moveto( dest, @buffer.size )
rsize += rbuf_moveto( dest, @rbuf.size )
rbuf_fill
end
rescue EOFError
@ -570,14 +559,14 @@ module Net
dest = ''
begin
while true do
idx = @buffer.index( target )
idx = @rbuf.index( target )
break if idx
rbuf_fill
end
rbuf_moveto dest, idx + target.size
rescue EOFError
raise unless igneof
rbuf_moveto dest, @buffer.size
rbuf_moveto dest, @rbuf.size
end
dest
end
@ -617,17 +606,15 @@ module Net
# D_on "read #{i} items"
end
private
READ_SIZE = 1024 * 4
BLOCK_SIZE = 1024 * 2
def rbuf_fill
unless IO.select [@socket], nil, nil, @read_timeout then
on_read_timeout
end
@buffer << @socket.sysread( READ_SIZE )
@rbuf << @socket.sysread(BLOCK_SIZE)
end
def on_read_timeout
@ -635,18 +622,14 @@ module Net
end
def rbuf_moveto( dest, len )
bsi = @buffer.size
s = @buffer[ 0, len ]
dest << s
@buffer = @buffer[ len, bsi - len ]
@debugout << %<read "#{Net.quote s}"\n> if @debugout
dest << (s = @rbuf.slice!(0, len))
@debugout << %Q<read "#{Net.quote s}"\n> if @debugout
len
end
#
# write interfece
# output
#
public
@ -666,7 +649,7 @@ module Net
def write_bin( src, block )
writing {
if block then
block.call ::Net::NetPrivate::WriteAdapter.new( self, :do_write )
block.call WriteAdapter.new(self, :do_write)
else
src.each do |bin|
do_write bin
@ -678,9 +661,9 @@ module Net
def write_pendstr( src, block )
D_off "writing text from #{src.type}"
wsize = use_each_crlf_line {
wsize = using_each_crlf_line {
if block then
block.call ::Net::NetPrivate::WriteAdapter.new( self, :wpend_in )
block.call WriteAdapter.new(self, :wpend_in)
else
wpend_in src
end
@ -690,10 +673,8 @@ module Net
wsize
end
private
def wpend_in( src )
line = nil
pre = @writtensize
@ -705,13 +686,13 @@ module Net
@writtensize - pre
end
def use_each_crlf_line
def using_each_crlf_line
writing {
@wbuf = ''
yield
if not @wbuf.empty? then # un-terminated last line
if not @wbuf.empty? then # unterminated last line
if @wbuf[-1] == ?\r then
@wbuf.chop!
end
@ -824,8 +805,6 @@ module Net
end
}
def Net.quote( str )
str = str.gsub( "\n", '\\n' )
@ -834,4 +813,14 @@ module Net
str
end
# for backward compatibility
module NetPrivate
Response = ::Net::Response
WriteAdapter = ::Net::WriteAdapter
ReadAdapter = ::Net::ReadAdapter
Command = ::Net::Command
Socket = ::Net::Socket
end
end # module Net

Просмотреть файл

@ -1,6 +1,6 @@
=begin
= net/smtp.rb version 1.2.3
= net/smtp.rb
Copyright (c) 1999-2001 Yukihiro Matsumoto
@ -13,6 +13,8 @@ Ruby Distribute License or GNU General Public License.
NOTE: You can find Japanese version of this document in
the doc/net directory of the standard ruby interpreter package.
$Id$
== What is This Module?
This module provides your program the functions to send internet
@ -217,7 +219,7 @@ module Net
class SMTP < Protocol
protocol_param :port, '25'
protocol_param :command_type, '::Net::NetPrivate::SMTPCommand'
protocol_param :command_type, '::Net::SMTPCommand'
def initialize( addr, port = nil )
@ -294,9 +296,6 @@ module Net
module NetPrivate
class SMTPCommand < Command
def initialize( sock )
@ -424,6 +423,9 @@ module Net
end
end # module Net::NetPrivate
# for backward compatibility
module NetPrivate
SMTPCommand = ::Net::SMTPCommand
end
end # module Net