Class: Net::POP3Command
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/net/pop.rb |
Overview
internal use only
Class Method Summary
- .new(sock) ⇒ POP3Command constructor
Instance Attribute Summary
- #socket readonly
Instance Method Summary
- #apop(account, password)
- #auth(account, password)
- #dele(num)
- #inspect
- #list
- #quit
- #retr(num, &block)
- #rset
- #stat
- #top(num, lines = 0, &block)
- #uidl(num = nil)
- #check_response(res) private
- #check_response_auth(res) private
- #critical private
- #get_response(fmt, *fargs) private
- #getok(fmt, *fargs) private
- #recv_response private
Constructor Details
.new(sock) ⇒ POP3Command
# File 'lib/net/pop.rb', line 894
def initialize(sock) @socket = sock @error_occurred = false res = check_response(critical { recv_response() }) @apop_stamp = res.slice(/<[!-~]@[!-~]>/) end
Instance Attribute Details
#socket (readonly)
[ GitHub ]# File 'lib/net/pop.rb', line 901
attr_reader :socket
Instance Method Details
#apop(account, password)
# File 'lib/net/pop.rb', line 914
def apop(account, password) raise POPAuthenticationError, 'not APOP server; cannot login' \ unless @apop_stamp check_response_auth(critical { get_response('APOP %s %s', account, Digest::MD5.hexdigest(@apop_stamp + password)) }) end
#auth(account, password)
[ GitHub ]# File 'lib/net/pop.rb', line 907
def auth(account, password) check_response_auth(critical { check_response_auth(get_response('USER %s', account)) get_response('PASS %s', password) }) end
#check_response(res) (private)
# File 'lib/net/pop.rb', line 1003
def check_response(res) raise POPError, res unless /\A\+OK/i =~ res res end
#check_response_auth(res) (private)
# File 'lib/net/pop.rb', line 1008
def check_response_auth(res) raise POPAuthenticationError, res unless /\A\+OK/i =~ res res end
#critical (private)
[ GitHub ]# File 'lib/net/pop.rb', line 1013
def critical return '+OK dummy ok response' if @error_occurred begin return yield() rescue Exception @error_occurred = true raise end end
#dele(num)
[ GitHub ]# File 'lib/net/pop.rb', line 962
def dele(num) check_response(critical { get_response('DELE %d', num) }) end
#get_response(fmt, *fargs) (private)
[ GitHub ]# File 'lib/net/pop.rb', line 994
def get_response(fmt, *fargs) @socket.writeline sprintf(fmt, *fargs) recv_response() end
#getok(fmt, *fargs) (private)
[ GitHub ]# File 'lib/net/pop.rb', line 989
def getok(fmt, *fargs) @socket.writeline sprintf(fmt, *fargs) check_response(recv_response()) end
#inspect
[ GitHub ]# File 'lib/net/pop.rb', line 903
def inspect +"#<#{self.class} socket=#{@socket}>" end
#list
[ GitHub ]# File 'lib/net/pop.rb', line 924
def list critical { getok 'LIST' list = [] @socket.each_list_item do |line| m = /\A(\d+)[ \t](\d)/.match(line) or raise POPBadResponse, "bad response: #{line}" list.push [m[1].to_i, m[2].to_i] end return list } end
#quit
[ GitHub ]# File 'lib/net/pop.rb', line 983
def quit check_response(critical { get_response('QUIT') }) end
#recv_response (private)
[ GitHub ]# File 'lib/net/pop.rb', line 999
def recv_response @socket.readline end
#retr(num, &block)
[ GitHub ]#rset
[ GitHub ]# File 'lib/net/pop.rb', line 944
def rset check_response(critical { get_response('RSET') }) end
#stat
[ GitHub ]# File 'lib/net/pop.rb', line 937
def stat res = check_response(critical { get_response('STAT') }) m = /\A\OK\s(\d)\s(\d+)/.match(res) or raise POPBadResponse, "wrong response format: #{res}" [m[1].to_i, m[2].to_i] end
#top(num, lines = 0, &block)
[ GitHub ]#uidl(num = nil)
[ GitHub ]# File 'lib/net/pop.rb', line 966
def uidl(num = nil) if num res = check_response(critical { get_response('UIDL %d', num) }) return res.split(/ /)[1] else critical { getok('UIDL') table = {} @socket.each_list_item do |line| num, uid = line.split(' ') table[num.to_i] = uid end return table } end end