rgrove-larch 1.0.0.3 → 1.0.0.4

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.
Files changed (4) hide show
  1. data/HISTORY +1 -0
  2. data/lib/larch/imap.rb +13 -55
  3. data/lib/larch/version.rb +1 -1
  4. metadata +1 -1
data/HISTORY CHANGED
@@ -4,6 +4,7 @@ Larch History
4
4
  Version 1.0.1 (?)
5
5
  * Much more robust handling of unexpected server disconnects and dropped
6
6
  connections.
7
+ * Fix excessive post-scan processing times for very large mailboxes.
7
8
  * Fetch message headers in blocks of up to 1024 at a time rather than all at
8
9
  once, to prevent potential problems with certain servers when a mailbox
9
10
  contains a huge number of messages.
data/lib/larch/imap.rb CHANGED
@@ -63,7 +63,6 @@ class IMAP
63
63
  @imap = nil
64
64
  @last_id = 0
65
65
  @last_scan = nil
66
- @message_ids = nil
67
66
 
68
67
  # Create private convenience methods (debug, info, warn, etc.) to make
69
68
  # logging easier.
@@ -284,76 +283,35 @@ class IMAP
284
283
  # Fetches the specified _fields_ for the specified message sequence id(s) from
285
284
  # the IMAP server.
286
285
  def imap_fetch(ids, fields)
287
- ids = ids.to_a
288
-
289
- data = safely do
290
- pos = 0
291
- results = []
286
+ ids = ids.to_a
287
+ data = []
288
+ pos = 0
292
289
 
290
+ safely do
293
291
  while pos < ids.length
294
- results += @imap.fetch(ids[pos, MAX_FETCH_COUNT], fields)
295
- pos += MAX_FETCH_COUNT
292
+ data += @imap.fetch(ids[pos, MAX_FETCH_COUNT], fields)
293
+ pos += MAX_FETCH_COUNT
296
294
  end
297
-
298
- results
299
295
  end
300
296
 
301
- # If fields isn't an array, make it one.
302
- fields = REGEX_FIELDS.match(fields).captures unless fields.is_a?(Array)
303
-
304
- # Translate BODY.PEEK to BODY in fields, since that's how it'll come back in
305
- # the response.
306
- fields.map! {|f| f.sub(/^BODY\.PEEK\[/, 'BODY[') }
307
-
308
- good_results = ids.respond_to?(:member?) ?
309
- data.find_all {|i| ids.member?(i.seqno) && fields.all? {|f| i.attr.member?(f) }} :
310
- data.find_all {|i| ids == i.seqno && fields.all? {|f| i.attr.member?(f) }}
311
-
312
- if good_results.empty?
313
- raise FatalError, "0 out of #{data.length} items in IMAP response for message(s) #{ids} contained all requested fields: #{fields.join(', ')}"
314
- elsif good_results.length < data.length
315
- error "IMAP server sent #{good_results.length} results in response to a request for #{data.length} messages"
316
- end
317
-
318
- good_results
297
+ data
319
298
  end
320
299
 
321
300
  # Fetches the specified _fields_ for the specified UID(s) from the IMAP
322
301
  # server.
323
302
  def imap_uid_fetch(uids, fields)
324
303
  uids = uids.to_a
304
+ data = []
305
+ pos = 0
325
306
 
326
- data = safely do
327
- pos = 0
328
- results = []
329
-
307
+ safely do
330
308
  while pos < uids.length
331
- results += @imap.uid_fetch(uids[pos, MAX_FETCH_COUNT], fields)
332
- pos += MAX_FETCH_COUNT
309
+ data += @imap.uid_fetch(uids[pos, MAX_FETCH_COUNT], fields)
310
+ pos += MAX_FETCH_COUNT
333
311
  end
334
-
335
- results
336
- end
337
-
338
- # If fields isn't an array, make it one.
339
- fields = REGEX_FIELDS.match(fields).captures unless fields.is_a?(Array)
340
-
341
- # Translate BODY.PEEK to BODY in fields, since that's how it'll come back in
342
- # the response.
343
- fields.map! {|f| f.sub(/^BODY\.PEEK\[/, 'BODY[') }
344
-
345
- good_results = data.find_all do |i|
346
- i.attr.member?('UID') && uids.member?(i.attr['UID']) &&
347
- fields.all? {|f| i.attr.member?(f) }
348
- end
349
-
350
- if good_results.empty?
351
- raise FatalError, "0 out of #{data.length} items in IMAP response for message UID(s) #{uids.join(', ')} contained all requested fields: #{fields.join(', ')}"
352
- elsif good_results.length < data.length
353
- error "IMAP server sent #{good_results.length} results in response to a request for #{data.length} messages"
354
312
  end
355
313
 
356
- good_results
314
+ data
357
315
  end
358
316
 
359
317
  def safe_connect
data/lib/larch/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Larch
2
2
  APP_NAME = 'Larch'
3
- APP_VERSION = '1.0.0.3'
3
+ APP_VERSION = '1.0.0.4'
4
4
  APP_AUTHOR = 'Ryan Grove'
5
5
  APP_EMAIL = 'ryan@wonko.com'
6
6
  APP_URL = 'http://github.com/rgrove/larch/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgrove-larch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.3
4
+ version: 1.0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Grove