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: def m( arg ) -> def m(arg).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2004-03-28 05:23:13 +00:00
parent 0cf429ce82
commit b81df5d837
2 changed files with 47 additions and 44 deletions

View file

@ -1,3 +1,7 @@
Sun Mar 28 14:23:02 2004 Minero Aoki <aamine@loveruby.net>
* lib/net/pop.rb: def m( arg ) -> def m(arg).
Sun Mar 28 14:09:13 2004 Minero Aoki <aamine@loveruby.net> Sun Mar 28 14:09:13 2004 Minero Aoki <aamine@loveruby.net>
* lib/net/pop.rb (auth): failed when account/password include "%". * lib/net/pop.rb (auth): failed when account/password include "%".

View file

@ -151,7 +151,7 @@
# you can grab only selected mails from the POP server. # you can grab only selected mails from the POP server.
# e.g. # e.g.
# #
# def need_pop?( id ) # def need_pop?(id)
# # determine if we need pop this mail... # # determine if we need pop this mail...
# end # end
# #
@ -220,7 +220,7 @@ module Net
# .... # ....
# } # }
# #
def POP3.APOP( isapop ) def POP3.APOP(isapop)
isapop ? APOP : POP3 isapop ? APOP : POP3
end end
@ -243,9 +243,9 @@ module Net
# m.delete if $DELETE # m.delete if $DELETE
# end # end
# #
def POP3.foreach( address, port = nil, def POP3.foreach(address, port = nil,
account = nil, password = nil, account = nil, password = nil,
isapop = false, &block ) # :yields: message isapop = false, &block) # :yields: message
start(address, port, account, password, isapop) {|pop| start(address, port, account, password, isapop) {|pop|
pop.each_mail(&block) pop.each_mail(&block)
} }
@ -263,9 +263,9 @@ module Net
# file.write m.pop # file.write m.pop
# end # end
# #
def POP3.delete_all( address, port = nil, def POP3.delete_all(address, port = nil,
account = nil, password = nil, account = nil, password = nil,
isapop = false, &block ) isapop = false, &block)
start(address, port, account, password, isapop) {|pop| start(address, port, account, password, isapop) {|pop|
pop.delete_all(&block) pop.delete_all(&block)
} }
@ -283,16 +283,16 @@ module Net
# Net::POP3.auth_only('pop.example.com', 110, # Net::POP3.auth_only('pop.example.com', 110,
# 'YourAccount', 'YourPassword', true) # 'YourAccount', 'YourPassword', true)
# #
def POP3.auth_only( address, port = nil, def POP3.auth_only(address, port = nil,
account = nil, password = nil, account = nil, password = nil,
isapop = false ) isapop = false)
new(address, port, isapop).auth_only account, password new(address, port, isapop).auth_only account, password
end end
# Starts a pop3 session, attempts authentication, and quits. # Starts a pop3 session, attempts authentication, and quits.
# This method must not be called while POP3 session is opened. # This method must not be called while POP3 session is opened.
# This method raises POPAuthenticationError if authentication fails. # This method raises POPAuthenticationError if authentication fails.
def auth_only( account, password ) def auth_only(account, password)
raise IOError, 'opening already opened POP session' if started? raise IOError, 'opening already opened POP session' if started?
start(account, password) { start(account, password) {
; ;
@ -318,9 +318,9 @@ module Net
# end # end
# } # }
# #
def POP3.start( address, port = nil, def POP3.start(address, port = nil,
account = nil, password = nil, account = nil, password = nil,
isapop = false, &block ) # :yield: pop isapop = false, &block) # :yield: pop
new(address, port, isapop).start(account, password, &block) new(address, port, isapop).start(account, password, &block)
end end
@ -330,7 +330,7 @@ module Net
# The optional +isapop+ specifies whether this connection is going # The optional +isapop+ specifies whether this connection is going
# to use APOP authentication; it defaults to +false+. # to use APOP authentication; it defaults to +false+.
# This method does *not* open the TCP connection. # This method does *not* open the TCP connection.
def initialize( addr, port = nil, isapop = false ) def initialize(addr, port = nil, isapop = false)
@address = addr @address = addr
@port = port || self.class.default_port @port = port || self.class.default_port
@apop = isapop @apop = isapop
@ -369,7 +369,7 @@ module Net
# .... # ....
# } # }
# #
def set_debug_output( arg ) def set_debug_output(arg)
@debug_output = arg @debug_output = arg
end end
@ -390,7 +390,7 @@ module Net
attr_reader :read_timeout attr_reader :read_timeout
# Set the read timeout. # Set the read timeout.
def read_timeout=( sec ) def read_timeout=(sec)
@command.socket.read_timeout = sec if @command @command.socket.read_timeout = sec if @command
@read_timeout = sec @read_timeout = sec
end end
@ -408,9 +408,8 @@ module Net
# closes the session after block call finishes. # closes the session after block call finishes.
# #
# This method raises a POPAuthenticationError if authentication fails. # This method raises a POPAuthenticationError if authentication fails.
def start( account, password ) # :yield: pop def start(account, password) # :yield: pop
raise IOError, 'POP session already started' if @started raise IOError, 'POP session already started' if @started
if block_given? if block_given?
begin begin
do_start account, password do_start account, password
@ -424,7 +423,7 @@ module Net
end end
end end
def do_start( account, password ) def do_start(account, password)
@socket = InternetMessageIO.new(timeout(@open_timeout) { @socket = InternetMessageIO.new(timeout(@open_timeout) {
TCPSocket.open(@address, @port) TCPSocket.open(@address, @port)
}) })
@ -518,7 +517,7 @@ module Net
# end # end
# #
# This method raises a POPError if an error occurs. # This method raises a POPError if an error occurs.
def each_mail( &block ) # :yield: message def each_mail(&block) # :yield: message
mails().each(&block) mails().each(&block)
end end
@ -538,7 +537,7 @@ module Net
# end # end
# #
# This method raises a POPError if an error occurs. # This method raises a POPError if an error occurs.
def delete_all # :yield: message def delete_all # :yield: message
mails().each do |m| mails().each do |m|
yield m if block_given? yield m if block_given?
m.delete unless m.deleted? m.delete unless m.deleted?
@ -594,7 +593,7 @@ module Net
# #
class POPMail class POPMail
def initialize( num, len, pop, cmd ) #:nodoc: def initialize(num, len, pop, cmd) #:nodoc:
@number = num @number = num
@length = len @length = len
@pop = pop @pop = pop
@ -621,6 +620,8 @@ module Net
# +dest+ argument will be prepended to the returned String; this # +dest+ argument will be prepended to the returned String; this
# argument is essentially obsolete. # argument is essentially obsolete.
# #
# This method raises a POPError if an error occurs.
#
# # Example without block # # Example without block
# POP3.start('pop.example.com', 110, # POP3.start('pop.example.com', 110,
# 'YourAccount, 'YourPassword') {|pop| # 'YourAccount, 'YourPassword') {|pop|
@ -648,8 +649,7 @@ module Net
# end # end
# } # }
# #
# This method raises a POPError if an error occurs. def pop(dest = '', &block) # :yield: message_chunk
def pop( dest = '', &block ) # :yield: message_chunk
if block_given? if block_given?
@command.retr(@number, &block) @command.retr(@number, &block)
nil nil
@ -668,7 +668,7 @@ module Net
# The optional +dest+ argument is obsolete. # The optional +dest+ argument is obsolete.
# #
# This method raises a POPError if an error occurs. # This method raises a POPError if an error occurs.
def top( lines, dest = '' ) def top(lines, dest = '')
@command.top(@number, lines) do |chunk| @command.top(@number, lines) do |chunk|
dest << chunk dest << chunk
end end
@ -679,7 +679,7 @@ module Net
# The optional +dest+ argument is obsolete. # The optional +dest+ argument is obsolete.
# #
# This method raises a POPError if an error occurs. # This method raises a POPError if an error occurs.
def header( dest = '' ) def header(dest = '')
top(0, dest) top(0, dest)
end end
@ -726,7 +726,7 @@ module Net
alias uidl unique_id alias uidl unique_id
def uid=( uid ) #:nodoc: internal use only (used from POP3#set_all_uids) def uid=(uid) #:nodoc: internal use only
@uid = uid @uid = uid
end end
@ -735,7 +735,7 @@ module Net
class POP3Command #:nodoc: internal use only class POP3Command #:nodoc: internal use only
def initialize( sock ) def initialize(sock)
@socket = sock @socket = sock
@error_occured = false @error_occured = false
res = check_response(critical { recv_response() }) res = check_response(critical { recv_response() })
@ -746,14 +746,14 @@ module Net
"#<#{self.class} socket=#{@socket}>" "#<#{self.class} socket=#{@socket}>"
end end
def auth( account, password ) def auth(account, password)
check_response_auth(critical { check_response_auth(critical {
check_response_auth(get_response('USER %s', account)) check_response_auth(get_response('USER %s', account))
get_response('PASS %s', password) get_response('PASS %s', password)
}) })
end end
def apop( account, password ) def apop(account, password)
raise POPAuthenticationError, 'not APOP server; cannot login' \ raise POPAuthenticationError, 'not APOP server; cannot login' \
unless @apop_stamp unless @apop_stamp
check_response_auth(critical { check_response_auth(critical {
@ -784,28 +784,28 @@ module Net
end end
def rset def rset
check_response(critical { get_response 'RSET' }) check_response(critical { get_response('RSET') })
end end
def top( num, lines = 0, &block ) def top(num, lines = 0, &block)
critical { critical {
getok('TOP %d %d', num, lines) getok('TOP %d %d', num, lines)
@socket.each_message_chunk(&block) @socket.each_message_chunk(&block)
} }
end end
def retr( num, &block ) def retr(num, &block)
critical { critical {
getok('RETR %d', num) getok('RETR %d', num)
@socket.each_message_chunk(&block) @socket.each_message_chunk(&block)
} }
end end
def dele( num ) def dele(num)
check_response(critical { get_response('DELE %d', num) }) check_response(critical { get_response('DELE %d', num) })
end end
def uidl( num = nil ) def uidl(num = nil)
if num if num
res = check_response(critical { get_response('UIDL %d', num) }) res = check_response(critical { get_response('UIDL %d', num) })
return res.split(/ /)[1] return res.split(/ /)[1]
@ -828,12 +828,12 @@ module Net
private private
def getok( fmt, *fargs ) def getok(fmt, *fargs)
@socket.writeline sprintf(fmt, *fargs) @socket.writeline sprintf(fmt, *fargs)
check_response(recv_response()) check_response(recv_response())
end end
def get_response( fmt, *fargs ) def get_response(fmt, *fargs)
@socket.writeline sprintf(fmt, *fargs) @socket.writeline sprintf(fmt, *fargs)
recv_response() recv_response()
end end
@ -842,13 +842,13 @@ module Net
@socket.readline @socket.readline
end end
def check_response( res ) def check_response(res)
raise POPError, res unless /\A\+OK/i === res raise POPError, res unless /\A\+OK/i =~ res
res res
end end
def check_response_auth( res ) def check_response_auth(res)
raise POPAuthenticationError, res unless /\A\+OK/i === res raise POPAuthenticationError, res unless /\A\+OK/i =~ res
res res
end end
@ -865,4 +865,3 @@ module Net
end # class POP3Command end # class POP3Command
end # module Net end # module Net