rgrove-larch 0.0.1.2 → 0.0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/larch/imap.rb +30 -26
- data/lib/larch.rb +2 -8
- metadata +1 -1
data/lib/larch/imap.rb
CHANGED
@@ -86,16 +86,18 @@ class IMAP
|
|
86
86
|
return false if has_message?(message)
|
87
87
|
|
88
88
|
safely do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
@mutex.synchronize do
|
90
|
+
begin
|
91
|
+
@imap.select(mailbox)
|
92
|
+
rescue Net::IMAP::NoResponseError => e
|
93
|
+
if @options[:create_mailbox]
|
94
|
+
info "creating mailbox: #{mailbox}"
|
95
|
+
@imap.create(mailbox)
|
96
|
+
retry
|
97
|
+
end
|
97
98
|
|
98
|
-
|
99
|
+
raise
|
100
|
+
end
|
99
101
|
end
|
100
102
|
|
101
103
|
debug "appending message: #{message.id}"
|
@@ -112,7 +114,6 @@ class IMAP
|
|
112
114
|
return if @imap
|
113
115
|
safely {} # connect, but do nothing else
|
114
116
|
end
|
115
|
-
synchronized :connect
|
116
117
|
|
117
118
|
# Closes the IMAP connection if one is currently open.
|
118
119
|
def disconnect
|
@@ -138,10 +139,8 @@ class IMAP
|
|
138
139
|
|
139
140
|
# Gets a Net::IMAP::Envelope for the specified message id.
|
140
141
|
def envelope(message_id)
|
141
|
-
|
142
|
-
|
143
|
-
@ids[message_id]
|
144
|
-
end
|
142
|
+
scan_mailbox
|
143
|
+
uid = @ids[message_id]
|
145
144
|
|
146
145
|
raise NotFoundError, "message not found: #{message_id}" if uid.nil?
|
147
146
|
|
@@ -152,10 +151,8 @@ class IMAP
|
|
152
151
|
# Fetches a Larch::Message instance representing the message with the
|
153
152
|
# specified Larch message id.
|
154
153
|
def fetch(message_id, peek = false)
|
155
|
-
|
156
|
-
|
157
|
-
@ids[message_id]
|
158
|
-
end
|
154
|
+
scan_mailbox
|
155
|
+
uid = @ids[message_id]
|
159
156
|
|
160
157
|
raise NotFoundError, "message not found: #{message_id}" if uid.nil?
|
161
158
|
|
@@ -170,10 +167,9 @@ class IMAP
|
|
170
167
|
# Returns +true+ if a message with the specified Larch <em>message_id</em>
|
171
168
|
# exists in this mailbox, +false+ otherwise.
|
172
169
|
def has_message?(message_id)
|
173
|
-
|
170
|
+
scan_mailbox
|
174
171
|
@ids.has_key?(message_id)
|
175
172
|
end
|
176
|
-
synchronized :has_message?
|
177
173
|
|
178
174
|
def host
|
179
175
|
@uri.host
|
@@ -181,10 +177,9 @@ class IMAP
|
|
181
177
|
|
182
178
|
# Gets the number of messages in this mailbox.
|
183
179
|
def length
|
184
|
-
|
180
|
+
scan_mailbox
|
185
181
|
@ids.length
|
186
182
|
end
|
187
|
-
synchronized :length
|
188
183
|
alias size length
|
189
184
|
|
190
185
|
# Same as fetch, but doesn't mark the message as seen.
|
@@ -239,9 +234,9 @@ class IMAP
|
|
239
234
|
next
|
240
235
|
end
|
241
236
|
|
242
|
-
if @ids.has_key?(id)
|
237
|
+
if @ids.has_key?(id) && Larch.log.level == :debug
|
243
238
|
envelope = imap_uid_fetch([uid], 'ENVELOPE').first.attr['ENVELOPE']
|
244
|
-
|
239
|
+
debug "duplicate message? #{id} (Subject: #{envelope.subject})"
|
245
240
|
end
|
246
241
|
|
247
242
|
@ids[id] = uid
|
@@ -336,7 +331,6 @@ class IMAP
|
|
336
331
|
|
337
332
|
begin
|
338
333
|
unsafe_connect unless @imap
|
339
|
-
yield
|
340
334
|
rescue *RECOVERABLE_ERRORS => e
|
341
335
|
raise unless (retries += 1) <= 3
|
342
336
|
|
@@ -345,6 +339,17 @@ class IMAP
|
|
345
339
|
retry
|
346
340
|
end
|
347
341
|
|
342
|
+
retries = 0
|
343
|
+
|
344
|
+
begin
|
345
|
+
yield
|
346
|
+
rescue *RECOVERABLE_ERRORS => e
|
347
|
+
raise unless (retries += 1) <= 3
|
348
|
+
|
349
|
+
sleep 2 * retries
|
350
|
+
retry
|
351
|
+
end
|
352
|
+
|
348
353
|
rescue IOError, Net::IMAP::Error, OpenSSL::SSL::SSLError, SocketError, SystemCallError => e
|
349
354
|
raise FatalError, "while communicating with IMAP server (#{e.class.name}): #{e.message}"
|
350
355
|
end
|
@@ -395,7 +400,6 @@ class IMAP
|
|
395
400
|
|
396
401
|
raise exception if exception
|
397
402
|
end
|
398
|
-
|
399
403
|
end
|
400
404
|
|
401
405
|
end
|
data/lib/larch.rb
CHANGED
@@ -25,7 +25,6 @@ module Larch
|
|
25
25
|
|
26
26
|
@copied = 0
|
27
27
|
@failed = 0
|
28
|
-
@untouched = 0
|
29
28
|
@total = 0
|
30
29
|
end
|
31
30
|
|
@@ -39,7 +38,6 @@ module Larch
|
|
39
38
|
|
40
39
|
@copied = 0
|
41
40
|
@failed = 0
|
42
|
-
@untouched = 0
|
43
41
|
@total = 0
|
44
42
|
|
45
43
|
@log.info "copying messages from #{source.uri} to #{dest.uri}"
|
@@ -54,11 +52,7 @@ module Larch
|
|
54
52
|
@total = source.length
|
55
53
|
|
56
54
|
source.each do |id|
|
57
|
-
if dest.has_message?(id)
|
58
|
-
@untouched += 1
|
59
|
-
next
|
60
|
-
end
|
61
|
-
|
55
|
+
next if dest.has_message?(id)
|
62
56
|
msgq << source.peek(id)
|
63
57
|
end
|
64
58
|
|
@@ -101,7 +95,7 @@ module Larch
|
|
101
95
|
end
|
102
96
|
|
103
97
|
def summary
|
104
|
-
@log.info "#{@copied} message(s) copied, #{@failed} failed, #{@
|
98
|
+
@log.info "#{@copied} message(s) copied, #{@failed} failed, #{@total - @copied - @failed} untouched out of #{@total} total"
|
105
99
|
end
|
106
100
|
end
|
107
101
|
|