Class: Net::POP3Command
- Inherits:
-
Object
- Object
- Net::POP3Command
- Defined in:
- lib/net/pop.rb
Overview
:nodoc: internal use only
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #apop(account, password) ⇒ Object
- #auth(account, password) ⇒ Object
- #dele(num) ⇒ Object
-
#initialize(sock) ⇒ POP3Command
constructor
A new instance of POP3Command.
- #inspect ⇒ Object
- #list ⇒ Object
- #quit ⇒ Object
- #retr(num, &block) ⇒ Object
- #rset ⇒ Object
- #stat ⇒ Object
- #top(num, lines = 0, &block) ⇒ Object
- #uidl(num = nil) ⇒ Object
Constructor Details
#initialize(sock) ⇒ POP3Command
Returns a new instance of POP3Command.
894 895 896 897 898 899 |
# 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 ⇒ Object (readonly)
Returns the value of attribute socket.
901 902 903 |
# File 'lib/net/pop.rb', line 901 def socket @socket end |
Instance Method Details
#apop(account, password) ⇒ Object
914 915 916 917 918 919 920 921 922 |
# 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) ⇒ Object
907 908 909 910 911 912 |
# 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 |
#dele(num) ⇒ Object
962 963 964 |
# File 'lib/net/pop.rb', line 962 def dele(num) check_response(critical { get_response('DELE %d', num) }) end |
#inspect ⇒ Object
903 904 905 |
# File 'lib/net/pop.rb', line 903 def inspect +"#<#{self.class} socket=#{@socket}>" end |
#list ⇒ Object
924 925 926 927 928 929 930 931 932 933 934 935 |
# 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 ⇒ Object
983 984 985 |
# File 'lib/net/pop.rb', line 983 def quit check_response(critical { get_response('QUIT') }) end |
#retr(num, &block) ⇒ Object
955 956 957 958 959 960 |
# File 'lib/net/pop.rb', line 955 def retr(num, &block) critical { getok('RETR %d', num) @socket.(&block) } end |
#rset ⇒ Object
944 945 946 |
# File 'lib/net/pop.rb', line 944 def rset check_response(critical { get_response('RSET') }) end |
#stat ⇒ Object
937 938 939 940 941 942 |
# 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) ⇒ Object
948 949 950 951 952 953 |
# File 'lib/net/pop.rb', line 948 def top(num, lines = 0, &block) critical { getok('TOP %d %d', num, lines) @socket.(&block) } end |
#uidl(num = nil) ⇒ Object
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 |
# 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 |