Class: Hermeneutics::Cli::IMAP
Defined Under Namespace
Classes: NotOk, ServerBye, ServerError, UnspecResponse
Constant Summary
collapse
- CRLF =
true
- TAG_PREFIX =
"H"
Instance Attribute Summary collapse
Attributes inherited from Protocol
#timeout
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Protocol
#done?, #read, #trace!, #wait, #write, #writeline
Constructor Details
#initialize(*args) ⇒ IMAP
Returns a new instance of IMAP.
37
38
39
40
41
42
|
# File 'lib/hermeneutics/cli/imap.rb', line 37
def initialize *args
super
@tag = "%s%04d" % [ TAG_PREFIX, 0]
@info = [ get_response]
start_watch
end
|
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
44
45
46
|
# File 'lib/hermeneutics/cli/imap.rb', line 44
def info
@info
end
|
Class Method Details
.open(host, port = nil, timeout: nil, ssl: false) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/hermeneutics/cli/imap.rb', line 26
def open host, port = nil, timeout: nil, ssl: false
port ||= ssl ? PORT_SSL : PORT
super host, port, timeout: timeout, ssl: ssl do |i|
yield i
i.stop_watch
end
end
|
Instance Method Details
#auths(data = nil) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/hermeneutics/cli/imap.rb', line 46
def auths data = nil
a = []
(data||@info.first.data).params.each { |p|
p =~ /\AAUTH=/ and a.push $'.to_s
}
a
end
|
#command(cmd, *args, &block) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/hermeneutics/cli/imap.rb', line 54
def command cmd, *args, &block
c = cmd.new *args
r = write_request c, &block
r.ok? or raise NotOk, r.text
c.responses
end
|
#get_response ⇒ Object
82
83
84
85
86
|
# File 'lib/hermeneutics/cli/imap.rb', line 82
def get_response
r = get_response_plain
r.bye? and raise ServerBye, "Server closed the connection"
r
end
|
#get_response_plain ⇒ Object
78
79
80
|
# File 'lib/hermeneutics/cli/imap.rb', line 78
def get_response_plain
Response.create @tag, self
end
|
#peekline ⇒ Object
67
68
69
|
# File 'lib/hermeneutics/cli/imap.rb', line 67
def peekline
@peek ||= readline!
end
|
#readline ⇒ Object
71
72
73
74
75
|
# File 'lib/hermeneutics/cli/imap.rb', line 71
def readline
@peek or readline!
ensure
@peek = nil
end
|
#start_watch ⇒ Object
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/hermeneutics/cli/imap.rb', line 89
def start_watch
@watch = Thread.new do
Thread.current.abort_on_exception = true
Thread.current.report_on_exception = false
while @socket.wait do
r = get_response
@info.push r
end
end
end
|
#stop_watch ⇒ Object
100
101
102
103
104
105
|
# File 'lib/hermeneutics/cli/imap.rb', line 100
def stop_watch
@watch or return
@watch.kill if @watch.alive?
@watch.value
@watch = nil
end
|
#write_request(cmd) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/hermeneutics/cli/imap.rb', line 107
def write_request cmd
stop_watch
@tag.succ!
r = nil
cmd.stream_lines "#@tag" do |a|
a.each { |l| writeline l.to_s }
r = get_response_plain
r.wait? or break
if block_given? then begin
start_watch
yield
ensure
stop_watch
end
end
r.text
end
until r.done? do
bye ||= r.bye?
cmd.add_response r
r = get_response_plain
r or raise ServerError, cmd.responses.last.to_s
end
bye or start_watch
r
end
|