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:
parent
ac2dc9c4da
commit
c62a982be2
|
@ -56,6 +56,28 @@ public class ImapConnection extends AbstractConnection {
|
||||||
protected String baseMailboxPath;
|
protected String baseMailboxPath;
|
||||||
ExchangeSession.Folder currentFolder;
|
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.
|
* Initialize the streams and start the thread.
|
||||||
*
|
*
|
||||||
|
@ -115,11 +137,11 @@ public class ImapConnection extends AbstractConnection {
|
||||||
state = State.AUTHENTICATED;
|
state = State.AUTHENTICATED;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
DavGatewayTray.error(e);
|
DavGatewayTray.error(e);
|
||||||
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
|
if (Settings.getBooleanProperty("davmail.enableKerberos")) {
|
||||||
sendClient(commandId + " NO LOGIN Kerberos authentication failed");
|
sendClient(commandId + " NO LOGIN Kerberos authentication failed");
|
||||||
} else {
|
} else {
|
||||||
sendClient(commandId + " NO LOGIN failed");
|
sendClient(commandId + " NO LOGIN failed");
|
||||||
}
|
}
|
||||||
state = State.INITIAL;
|
state = State.INITIAL;
|
||||||
}
|
}
|
||||||
} else if ("AUTHENTICATE".equalsIgnoreCase(command)) {
|
} else if ("AUTHENTICATE".equalsIgnoreCase(command)) {
|
||||||
|
@ -222,8 +244,27 @@ public class ImapConnection extends AbstractConnection {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
currentFolder = session.getFolder(folderName);
|
currentFolder = session.getFolder(folderName);
|
||||||
currentFolder.loadMessages();
|
if (currentFolder.count() <= 500) {
|
||||||
sendClient("* " + currentFolder.count() + " EXISTS");
|
// 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("* " + currentFolder.recent + " RECENT");
|
||||||
sendClient("* OK [UIDVALIDITY 1]");
|
sendClient("* OK [UIDVALIDITY 1]");
|
||||||
if (currentFolder.count() == 0) {
|
if (currentFolder.count() == 0) {
|
||||||
|
|
Loading…
Reference in New Issue