em-imap 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of em-imap might be problematic. Click here for more details.
data/lib/em-imap/connection.rb
CHANGED
@@ -20,7 +20,7 @@ module EventMachine
|
|
20
20
|
# first response was BYE.
|
21
21
|
#
|
22
22
|
def self.connect(host, port, ssl=false)
|
23
|
-
|
23
|
+
EventMachine.connect(host, port, self).tap do |conn|
|
24
24
|
conn.start_tls if ssl
|
25
25
|
end
|
26
26
|
end
|
@@ -97,12 +97,17 @@ module EventMachine
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# Called when the connection is closed.
|
100
|
-
# If there are any listeners left, we fail them.
|
101
|
-
# (TODO: Should we actually succeed them if the connection was
|
102
|
-
# explicitly closed by us?)
|
103
100
|
# TODO: Figure out how to send a useful error...
|
104
101
|
def unbind
|
105
|
-
|
102
|
+
fail_all EOFError.new("Connection to IMAP server was unbound"), true
|
103
|
+
end
|
104
|
+
|
105
|
+
def fail_all(error, closed=false)
|
106
|
+
# NOTE: Take a shallow clone of the listeners here so that we get guaranteed
|
107
|
+
# behaviour. We want to fail any listeners that may be added by the errbacks
|
108
|
+
# of other listeners.
|
109
|
+
@listeners.clone.each{ |listener| listener.fail error } while @listeners.size > 0
|
110
|
+
close_connection unless closed
|
106
111
|
end
|
107
112
|
|
108
113
|
def add_to_listener_pool(listener)
|
@@ -113,7 +118,9 @@ module EventMachine
|
|
113
118
|
# EM::IMAP::ResponseParser. Each response is a Net::IMAP response
|
114
119
|
# object. (FIXME)
|
115
120
|
def receive_response(response)
|
116
|
-
|
121
|
+
# NOTE: Take a shallow clone of the listeners so that if receiving an
|
122
|
+
# event causes a new listener to be added, it won't receive this response!
|
123
|
+
@listeners.clone.each{ |listener| listener.receive_event response }
|
117
124
|
end
|
118
125
|
|
119
126
|
# Await the response that marks the completion of this command,
|
@@ -59,8 +59,12 @@ module EventMachine
|
|
59
59
|
# continuation responses onto the currently awaiting block.
|
60
60
|
def listen_for_continuation
|
61
61
|
add_response_handler do |response|
|
62
|
-
if
|
63
|
-
|
62
|
+
if response.is_a?(Net::IMAP::ContinuationRequest)
|
63
|
+
if awaiting_continuation?
|
64
|
+
@awaiting_continuation.receive_event response
|
65
|
+
else
|
66
|
+
fail_all Net::IMAP::ResponseError.new("Unexpected continuation response from server")
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/em-imap/listener.rb
CHANGED
@@ -92,12 +92,15 @@ module EventMachine
|
|
92
92
|
# Register a block to be called when receive_event is called.
|
93
93
|
def listen(&block)
|
94
94
|
listeners << block
|
95
|
+
stopback{ |*args| listeners.delete block }
|
95
96
|
self
|
96
97
|
end
|
97
98
|
|
98
99
|
# Pass arguments onto any blocks registered with listen.
|
99
100
|
def receive_event(*args, &block)
|
100
|
-
|
101
|
+
# NOTE: Take a clone of listeners, so any listeners added by listen
|
102
|
+
# blocks won't receive these events.
|
103
|
+
listeners.clone.each{ |l| l.call *args, &block }
|
101
104
|
end
|
102
105
|
|
103
106
|
# Register a block to be called when the ListeningDeferrable is stopped.
|
@@ -39,10 +39,15 @@ module EventMachine
|
|
39
39
|
# Callback used by receive data.
|
40
40
|
def receive_response(response); end
|
41
41
|
|
42
|
+
# Callback used if something goes wrong.
|
43
|
+
def fail_all(error); end
|
44
|
+
|
42
45
|
private
|
43
46
|
|
44
47
|
def parse(line)
|
45
48
|
@parser.parse(line)
|
49
|
+
rescue Net::IMAP::ResponseParseError => e
|
50
|
+
fail_all e
|
46
51
|
end
|
47
52
|
end
|
48
53
|
end
|
metadata
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-imap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
9
11
|
platform: ruby
|
10
12
|
authors:
|
11
13
|
- Conrad Irwin
|
@@ -13,16 +15,18 @@ autorequire:
|
|
13
15
|
bindir: bin
|
14
16
|
cert_chain: []
|
15
17
|
|
16
|
-
date: 2011-
|
18
|
+
date: 2011-07-02 00:00:00 -07:00
|
17
19
|
default_executable:
|
18
20
|
dependencies:
|
19
21
|
- !ruby/object:Gem::Dependency
|
20
22
|
name: eventmachine
|
21
23
|
prerelease: false
|
22
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
26
30
|
segments:
|
27
31
|
- 0
|
28
32
|
version: "0"
|
@@ -32,9 +36,11 @@ dependencies:
|
|
32
36
|
name: deferrable_gratification
|
33
37
|
prerelease: false
|
34
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
35
40
|
requirements:
|
36
41
|
- - ">="
|
37
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
38
44
|
segments:
|
39
45
|
- 0
|
40
46
|
version: "0"
|
@@ -44,9 +50,11 @@ dependencies:
|
|
44
50
|
name: rspec
|
45
51
|
prerelease: false
|
46
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
47
54
|
requirements:
|
48
55
|
- - ">="
|
49
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
50
58
|
segments:
|
51
59
|
- 0
|
52
60
|
version: "0"
|
@@ -64,12 +72,12 @@ extra_rdoc_files: []
|
|
64
72
|
files:
|
65
73
|
- lib/em-imap.rb
|
66
74
|
- lib/em-imap/listener.rb
|
67
|
-
- lib/em-imap/client.rb
|
68
|
-
- lib/em-imap/continuation_synchronisation.rb
|
69
|
-
- lib/em-imap/response_parser.rb
|
70
|
-
- lib/em-imap/connection.rb
|
71
75
|
- lib/em-imap/command_sender.rb
|
72
76
|
- lib/em-imap/authenticators.rb
|
77
|
+
- lib/em-imap/connection.rb
|
78
|
+
- lib/em-imap/continuation_synchronisation.rb
|
79
|
+
- lib/em-imap/client.rb
|
80
|
+
- lib/em-imap/response_parser.rb
|
73
81
|
- LICENSE.MIT
|
74
82
|
- README.md
|
75
83
|
has_rdoc: true
|
@@ -82,25 +90,29 @@ rdoc_options: []
|
|
82
90
|
require_paths:
|
83
91
|
- lib
|
84
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
85
94
|
requirements:
|
86
95
|
- - ">="
|
87
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 57
|
88
98
|
segments:
|
89
99
|
- 1
|
90
100
|
- 8
|
91
101
|
- 7
|
92
102
|
version: 1.8.7
|
93
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
94
105
|
requirements:
|
95
106
|
- - ">="
|
96
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
97
109
|
segments:
|
98
110
|
- 0
|
99
111
|
version: "0"
|
100
112
|
requirements: []
|
101
113
|
|
102
114
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.6.2
|
104
116
|
signing_key:
|
105
117
|
specification_version: 3
|
106
118
|
summary: An EventMachine based IMAP client.
|