mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/net/pop.rb: do not dispatch LIST when a mailbox is empty.
* lib/net/pop.rb: merge the 'STAT' patch from Frank S.Fejes <frank@oopdreams.com>, with modifications (listed below). * lib/net/pop.rb: new method Net::POP#mail_size. * lib/net/pop.rb: new method Net::POP#bytes. * lib/net/pop.rb: new method Net::POPCommand#stat. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ced8bbee7c
commit
70b55f2018
2 changed files with 110 additions and 74 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Mon Mar 10 01:59:47 2003 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* lib/net/pop.rb: do not dispatch LIST when a mailbox is empty.
|
||||
|
||||
* lib/net/pop.rb: merge the 'STAT' patch from Frank S.Fejes
|
||||
<frank@oopdreams.com>, with modifications (listed below).
|
||||
|
||||
* lib/net/pop.rb: new method Net::POP#mail_size.
|
||||
|
||||
* lib/net/pop.rb: new method Net::POP#bytes.
|
||||
|
||||
* lib/net/pop.rb: new method Net::POPCommand#stat.
|
||||
|
||||
Sun Mar 9 19:30:25 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* lib/fileutils.rb (mkdir, mkdir_p): revert.
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
= net/pop.rb
|
||||
|
||||
Copyright (c) 1999-2002 Yukihiro Matsumoto
|
||||
Copyright (c) 1999-2003 Yukihiro Matsumoto
|
||||
Copyright (c) 1999-2003 Minero Aoki
|
||||
|
||||
written & maintained by Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
|
@ -63,7 +64,7 @@ alternates POP3.new, POP3#start and POP3#finish.
|
|||
|
||||
Net::POP3.start('pop3.server.address', 110)
|
||||
'YourAccount', 'YourPassword')
|
||||
if pop.mails.empty? then
|
||||
if pop.mails.empty?
|
||||
puts 'no mail.'
|
||||
else
|
||||
i = 0
|
||||
|
@ -84,7 +85,7 @@ POP3#delete_all alternates #each_mail and m.delete.
|
|||
|
||||
Net::POP3.start('pop3.server.address', 110,
|
||||
'YourAccount', 'YourPassword') {|pop|
|
||||
if pop.mails.empty? then
|
||||
if pop.mails.empty?
|
||||
puts 'no mail.'
|
||||
else
|
||||
i = 0
|
||||
|
@ -332,6 +333,9 @@ require 'digest/md5'
|
|||
|
||||
module Net
|
||||
|
||||
class BadResponseError < StandardError; end
|
||||
|
||||
|
||||
class POP3 < Protocol
|
||||
|
||||
protocol_param :default_port, '110'
|
||||
|
@ -340,7 +344,6 @@ module Net
|
|||
protocol_param :mail_type, '::Net::POPMail'
|
||||
protocol_param :socket_type, '::Net::InternetMessageIO'
|
||||
|
||||
|
||||
def POP3.APOP( isapop )
|
||||
isapop ? APOP : POP3
|
||||
end
|
||||
|
@ -364,15 +367,13 @@ module Net
|
|||
new(address, port).auth_only account, password
|
||||
end
|
||||
|
||||
|
||||
def auth_only( account, password )
|
||||
raise IOError, 'opening already opened POP session' if active?
|
||||
start(account, password) {
|
||||
# none
|
||||
;
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# connection
|
||||
#
|
||||
|
@ -402,15 +403,31 @@ module Net
|
|||
disconn_socket
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# POP operations
|
||||
#
|
||||
|
||||
public
|
||||
|
||||
def mail_size
|
||||
return @nmails if @nmails
|
||||
@nmails, @bytes = command().stat
|
||||
@nmails
|
||||
end
|
||||
|
||||
def bytes
|
||||
return @bytes if @bytes
|
||||
@nmails, @bytes = command().stat
|
||||
@bytes
|
||||
end
|
||||
|
||||
def mails
|
||||
return @mails if @mails
|
||||
if mail_size() == 0
|
||||
# some popd raises error for LIST on the empty mailbox.
|
||||
@mails = []
|
||||
return @mails
|
||||
end
|
||||
|
||||
mails = []
|
||||
mailclass = self.class.mail_type
|
||||
|
@ -418,6 +435,8 @@ module Net
|
|||
mails.push mailclass.new(idx, size, command()) if size
|
||||
end
|
||||
@mails = mails.freeze
|
||||
|
||||
@mails
|
||||
end
|
||||
|
||||
def each_mail( &block )
|
||||
|
@ -436,19 +455,20 @@ module Net
|
|||
def reset
|
||||
command().rset
|
||||
mails().each do |m|
|
||||
m.instance_eval { @deleted = false }
|
||||
m.instance_eval {
|
||||
@deleted = false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def command
|
||||
io_check
|
||||
super
|
||||
end
|
||||
|
||||
def io_check
|
||||
(not socket() or socket().closed?) and
|
||||
raise IOError, 'POP session is not opened yet'
|
||||
raise IOError, 'POP session is not opened yet'\
|
||||
if not socket() or socket().closed?
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -457,7 +477,6 @@ module Net
|
|||
POPSession = POP3
|
||||
POP3Session = POP3
|
||||
|
||||
|
||||
class APOP < POP3
|
||||
def APOP.command_type
|
||||
APOPCommand
|
||||
|
@ -477,16 +496,14 @@ module Net
|
|||
@deleted = false
|
||||
end
|
||||
|
||||
attr :size
|
||||
attr_reader :size
|
||||
|
||||
def inspect
|
||||
"#<#{self.class} #{@num}#{@deleted ? ' deleted' : ''}>"
|
||||
end
|
||||
|
||||
def pop( dest = '', &block )
|
||||
if block
|
||||
dest = ReadAdapter.new(block)
|
||||
end
|
||||
dest = ReadAdapter.new(block) if block
|
||||
@command.retr @num, dest
|
||||
end
|
||||
|
||||
|
@ -539,16 +556,25 @@ module Net
|
|||
end
|
||||
|
||||
def list
|
||||
arr = []
|
||||
atomic {
|
||||
getok 'LIST'
|
||||
list = []
|
||||
@socket.each_list_item do |line|
|
||||
m = /\A(\d+)[ \t]+(\d+)/.match(line) or
|
||||
raise BadResponse, "illegal response: #{line}"
|
||||
arr[m[1].to_i] = m[2].to_i
|
||||
list[m[1].to_i] = m[2].to_i
|
||||
end
|
||||
return list
|
||||
}
|
||||
end
|
||||
|
||||
def stat
|
||||
atomic {
|
||||
@socket.writeline 'STAT'
|
||||
line = @socket.readline
|
||||
m = /\A\+OK (\d+)[ \t]+(\d+)/.match(line) or
|
||||
raise BadResponseError, "illegal response: #{line}"
|
||||
return [m[1].to_i, m[2].to_i]
|
||||
}
|
||||
arr
|
||||
end
|
||||
|
||||
def rset
|
||||
|
@ -602,7 +628,6 @@ module Net
|
|||
|
||||
def get_reply
|
||||
str = @socket.readline
|
||||
|
||||
if /\A\+/ === str
|
||||
Response.new(SuccessCode, str[0,3], str[3, str.size - 3].strip)
|
||||
else
|
||||
|
@ -616,10 +641,8 @@ module Net
|
|||
class APOPCommand < POP3Command
|
||||
|
||||
def initialize( sock )
|
||||
response = super(sock)
|
||||
m = /<.+>/.match(response.msg) or
|
||||
@stamp = super(sock).message.slice(/<.+>/) or
|
||||
raise ProtoAuthError.new("not APOP server: cannot login", nil)
|
||||
@stamp = m[0]
|
||||
end
|
||||
|
||||
def auth( account, pass )
|
||||
|
|
Loading…
Reference in a new issue