From dd1cfea37931215b945b4f84054a86e564b15199 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 7 Apr 2014 21:20:25 +0000 Subject: [PATCH] IMAP: implement separate thread folder load on STATUS request to avoid client timeouts git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2285 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/imap/ImapConnection.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index e73c5f56..0d65e304 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -569,7 +569,18 @@ public class ImapConnection extends AbstractConnection { String folderName = BASE64MailboxDecoder.decode(encodedFolderName); ExchangeSession.Folder folder = session.getFolder(folderName); // must retrieve messages - folder.loadMessages(); + + // use folder.loadMessages() for small folders only + LOGGER.debug("*"); + os.write('*'); + if (folder.count() <= 500) { + // simple folder load + folder.loadMessages(); + } else { + // load folder in a separate thread + FolderLoadThread.loadFolder(folder, os); + } + String parameters = tokens.nextToken(); StringBuilder answer = new StringBuilder(); StringTokenizer parametersTokens = new StringTokenizer(parameters); @@ -600,7 +611,7 @@ public class ImapConnection extends AbstractConnection { answer.append("UNSEEN ").append(folder.unreadCount).append(' '); } } - sendClient("* STATUS \"" + encodedFolderName + "\" (" + answer.toString().trim() + ')'); + sendClient(" STATUS \"" + encodedFolderName + "\" (" + answer.toString().trim() + ')'); sendClient(commandId + " OK " + command + " completed"); } catch (HttpException e) { sendClient(commandId + " NO folder not found");