1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* 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
parent d8c75ddad3
commit 39c0252e04
8 changed files with 156 additions and 133 deletions

View file

@ -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> Thu Dec 13 09:52:59 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
* time.c (time_new_internal): avoid loop to calculate negative * time.c (time_new_internal): avoid loop to calculate negative

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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