From 3f4dc31a1a60807d604dd6dd09ed328f1db61574 Mon Sep 17 00:00:00 2001 From: Emilio Blanco Date: Fri, 1 Apr 2011 13:26:21 -0300 Subject: [PATCH] Using chunks to get large email lists --- lib/webmail/imapmailbox.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/webmail/imapmailbox.rb b/lib/webmail/imapmailbox.rb index 8b5949f..4303a3d 100644 --- a/lib/webmail/imapmailbox.rb +++ b/lib/webmail/imapmailbox.rb @@ -422,8 +422,18 @@ class IMAPFolder # fetch and store not cached messages unless uids_to_be_fetched.empty? - imapres = @mailbox.imap.uid_fetch(uids_to_be_fetched, @@fetch_attr) - imapres.each { |cache| + logger.debug("About to fetch #{uids_to_be_fetched.join(",")}") + uids_to_be_fetched.each_slice(20) do |slice| + fetch_uids(slice) + end + end + @mcached = true + logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.") + end + + def fetch_uids(uids) + imapres = @mailbox.imap.uid_fetch(uids, @@fetch_attr) + uids.each { |cache| envelope = cache.attr['ENVELOPE']; message = ImapMessage.create( :folder_name => @name, :username => @username, @@ -437,9 +447,6 @@ class IMAPFolder :unread => !(cache.attr['FLAGS'].member? :Seen), :size => cache.attr['RFC822.SIZE']) } - end - @mcached = true - logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.") end def messages(offset = 0, limit = 10, sort = 'date desc')