Class: Hermeneutics::Cli::POP3
Defined Under Namespace
Classes: AuthFail, Check, Error, UnspecError, Unused
Constant Summary
collapse
- CRLF =
true
Instance Attribute Summary collapse
Attributes inherited from Protocol
#timeout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Protocol
#done?, #read, #readline, #trace!, #write, #writeline
Constructor Details
#initialize(*args) ⇒ POP3
Returns a new instance of POP3.
33
34
35
36
|
# File 'lib/hermeneutics/cli/pop3.rb', line 33
def initialize *args
super
@stamp = get_response.slice /<[!-~]+@[!-~]+>/
end
|
Instance Attribute Details
#last_response ⇒ Object
Returns the value of attribute last_response.
31
32
33
|
# File 'lib/hermeneutics/cli/pop3.rb', line 31
def last_response
@last_response
end
|
Class Method Details
.open(host, port = nil, timeout: nil, ssl: false) ⇒ Object
25
26
27
28
|
# File 'lib/hermeneutics/cli/pop3.rb', line 25
def open host, port = nil, timeout: nil, ssl: false
port ||= ssl ? PORT_SSL : PORT
super host, port, timeout: timeout, ssl: ssl
end
|
Instance Method Details
#apop(name, pwd) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/hermeneutics/cli/pop3.rb', line 57
def apop name, pwd
require "digest/md5"
hash = Digest::MD5.hexdigest "#@stamp#{pwd}"
writeline "APOP #{name} #{hash}"
get_response_auth
end
|
#authenticate(name, pwd) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/hermeneutics/cli/pop3.rb', line 38
def authenticate name, pwd
if @stamp then
apop name, pwd
else
user name
pass pwd
end
end
|
#capa ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/hermeneutics/cli/pop3.rb', line 64
def capa
if block_given? then
writeline "CAPA"
get_response do |_|
get_data { |l|
c, *rest = l.split
yield c, rest
}
end
else
r = Hash.new do |h,k| h[k] = [] end
capa do |c,v|
if v.notempty? then
r[c].concat v
else
r[c] = true
end
end
r
end
end
|
#dele(n) ⇒ Object
173
174
175
176
|
# File 'lib/hermeneutics/cli/pop3.rb', line 173
def dele n
writeline "DELE #{n}"
get_response
end
|
#list(n = nil) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/hermeneutics/cli/pop3.rb', line 96
def list n = nil
n = n.to_i.nonzero?
if block_given? then
cmd = "LIST"
cmd << " #{n}" if n
writeline cmd
if n then
n_, len = split_num_len get_response
n == n_ or raise Check, "Wrong LIST response: #{n} <-> #{n_}"
yield n, len
else
get_response do |_|
get_data do |l|
n_, len = split_num_len l
yield n_, len
end
end
end
else
if n then
list n do |*a| a end
else
h = {}
list n do |n_,len|
h[ n_] = len
end
h
end
end
end
|
#noop ⇒ Object
183
184
185
186
|
# File 'lib/hermeneutics/cli/pop3.rb', line 183
def noop
writeline "NOOP"
get_response
end
|
#pass(pwd) ⇒ Object
52
53
54
55
|
# File 'lib/hermeneutics/cli/pop3.rb', line 52
def pass pwd
writeline "PASS #{pwd}"
get_response_auth
end
|
#quit ⇒ Object
188
189
190
191
|
# File 'lib/hermeneutics/cli/pop3.rb', line 188
def quit
writeline "QUIT"
get_response
end
|
#retr(n, &block) ⇒ Object
158
159
160
161
162
163
|
# File 'lib/hermeneutics/cli/pop3.rb', line 158
def retr n, &block
writeline "RETR #{n}"
get_response do |_|
get_data_str &block
end
end
|
#rset ⇒ Object
178
179
180
181
|
# File 'lib/hermeneutics/cli/pop3.rb', line 178
def rset
writeline "RSET"
get_response
end
|
#stat ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/hermeneutics/cli/pop3.rb', line 86
def stat
if block_given? then
writeline "STAT"
n, r = split_num_len get_response
yield n, r
else
stat do |*a| a end
end
end
|
#top(n, x, &block) ⇒ Object
165
166
167
168
169
170
|
# File 'lib/hermeneutics/cli/pop3.rb', line 165
def top n, x, &block
writeline "TOP #{n} #{x}"
get_response do |_|
get_data_str &block
end
end
|
#uidl(n = nil) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/hermeneutics/cli/pop3.rb', line 127
def uidl n = nil
n = n.to_i.nonzero?
if block_given? then
cmd = "UIDL"
cmd << " #{n}" if n
writeline cmd
if n then
n_, id = split_num get_response
n == n_ or raise Check, "Wrong UIDL response: #{n} <-> #{n_}"
yield n, id
else
get_response do |_|
get_data do |l|
n_, id = split_num l
yield n_, id
end
end
end
else
if n then
uidl n do |*a| a end
else
h = {}
uidl n do |n_,id|
h[ n_] = id
end
h
end
end
end
|
#user(name) ⇒ Object
47
48
49
50
|
# File 'lib/hermeneutics/cli/pop3.rb', line 47
def user name
writeline "USER #{name}"
get_response
end
|