o  all:  use "critical" to avoid duplicated command dispatch
o  http.rb:  change get2, post2 usage (HTTPWriter)
o  http.rb:  entity reading algorithm is better
o  http.rb:  more reply code (4xx, 5xx)
o  protocol.rb:  arguments of "connect" can be omitted
o  protocol.rb:  "quit" is not template method (now do_quit is removed)
o  protocol.rb:  ReplyCode.error_type was not work: using module_eval


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2000-03-27 15:52:27 +00:00
parent 0dcf7498b1
commit 9fd5174ef3
4 changed files with 355 additions and 178 deletions

View file

@ -71,8 +71,9 @@ Net::Protocol
def do_start( acnt, pwd )
@command.auth( acnt, pwd )
t = self.type.mail_type
@mails = []
t = type.mail_type
@command.list.each_with_index do |size,idx|
if size then
@mails.push t.new( idx, size, @command )
@ -221,72 +222,83 @@ Net::POP3
def initialize( sock )
super
check_reply SuccessCode
critical {
check_reply SuccessCode
}
end
def auth( acnt, pass )
@socket.writeline 'USER ' + acnt
check_reply_auth
critical {
@socket.writeline 'USER ' + acnt
check_reply_auth
@socket.writeline( 'PASS ' + pass )
ret = check_reply_auth
return ret
@socket.writeline 'PASS ' + pass
check_reply_auth
}
end
def list
getok 'LIST'
arr = []
@socket.read_pendlist do |line|
num, siz = line.split( / +/o )
arr[ num.to_i ] = siz.to_i
end
return arr
critical {
getok 'LIST'
@socket.read_pendlist do |line|
num, siz = line.split( / +/o )
arr[ num.to_i ] = siz.to_i
end
}
arr
end
def rset
getok 'RSET'
critical {
getok 'RSET'
}
end
def top( num, lines = 0, dest = '' )
getok sprintf( 'TOP %d %d', num, lines )
@socket.read_pendstr( dest )
critical {
getok sprintf( 'TOP %d %d', num, lines )
@socket.read_pendstr( dest )
}
end
def retr( num, dest = '', &block )
getok sprintf( 'RETR %d', num )
@socket.read_pendstr( dest, &block )
critical {
getok sprintf( 'RETR %d', num )
@socket.read_pendstr( dest, &block )
}
end
def dele( num )
getok sprintf( 'DELE %d', num )
critical {
getok sprintf( 'DELE %d', num )
}
end
def uidl( num )
rep = getok( sprintf 'UIDL %d', num )
uid = rep.msg.split(' ')[1]
critical {
getok( sprintf 'UIDL %d', num ).msg.split(' ')[1]
}
end
uid
def quit
critical {
getok 'QUIT'
}
end
private
def do_quit
getok 'QUIT'
end
def check_reply_auth
begin
cod = check_reply( SuccessCode )
@ -326,19 +338,17 @@ Net::POP3
def auth( acnt, pass )
@socket.writeline( "APOP #{acnt} #{digest(@stamp + pass)}" )
return check_reply_auth
critical {
@socket.writeline( "APOP #{acnt} #{digest(@stamp + pass)}" )
check_reply_auth
}
end
def digest( str )
temp = MD5.new( str ).digest
ret = ''
temp.each_byte do |i|
ret << sprintf( '%02x', i )
end
return ret
MD5.new( str ).digest.each_byte {|i| ret << sprintf('%02x', i) }
ret
end
end