IMAP: try to avoid timeout on folder SELECT with a KeepAlive space character

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2096 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2013-04-23 08:36:07 +00:00
parent ac2dc9c4da
commit c62a982be2
1 changed files with 48 additions and 7 deletions

View File

@ -56,6 +56,28 @@ public class ImapConnection extends AbstractConnection {
protected String baseMailboxPath;
ExchangeSession.Folder currentFolder;
class FolderLoadThread extends Thread {
boolean isComplete = false;
ExchangeSession.Folder folder;
IOException exception;
FolderLoadThread(String threadName, ExchangeSession.Folder folder) {
super(threadName+"-Load");
setDaemon(true);
this.folder = folder;
}
public void run() {
try {
folder.loadMessages();
} catch (IOException e) {
exception = e;
} finally {
isComplete = true;
}
}
}
/**
* Initialize the streams and start the thread.
*
@ -115,11 +137,11 @@ public class ImapConnection extends AbstractConnection {
state = State.AUTHENTICATED;
} catch (Exception e) {
DavGatewayTray.error(e);
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
sendClient(commandId + " NO LOGIN Kerberos authentication failed");
} else {
sendClient(commandId + " NO LOGIN failed");
}
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
sendClient(commandId + " NO LOGIN Kerberos authentication failed");
} else {
sendClient(commandId + " NO LOGIN failed");
}
state = State.INITIAL;
}
} else if ("AUTHENTICATE".equalsIgnoreCase(command)) {
@ -222,8 +244,27 @@ public class ImapConnection extends AbstractConnection {
}
try {
currentFolder = session.getFolder(folderName);
currentFolder.loadMessages();
sendClient("* " + currentFolder.count() + " EXISTS");
if (currentFolder.count() <= 500) {
// simple folder load
currentFolder.loadMessages();
sendClient("* " + currentFolder.count() + " EXISTS");
} else {
// load folder in a separate thread
FolderLoadThread folderLoadThread = new FolderLoadThread(currentThread().getName(), currentFolder);
folderLoadThread.start();
os.write('*');
while (!folderLoadThread.isComplete) {
folderLoadThread.join(10000);
LOGGER.debug("Still loading "+currentFolder.folderPath);
os.write(' ');
os.flush();
}
sendClient(" " + currentFolder.count() + " EXISTS");
if (folderLoadThread.exception != null) {
throw folderLoadThread.exception;
}
}
sendClient("* " + currentFolder.recent + " RECENT");
sendClient("* OK [UIDVALIDITY 1]");
if (currentFolder.count() == 0) {