IMAP: make keepalive spaces optional with new davmail.imapEnableKeepalive setting
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2143 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
badbdc5bc6
commit
53819c01e8
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||||
|
* Copyright (C) 2013 Mickael Guessant
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
package davmail.exchange;
|
||||||
|
|
||||||
|
import davmail.Settings;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.SocketException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load folder messages in a separate thread.
|
||||||
|
*/
|
||||||
|
public class FolderLoadThread extends Thread {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(FolderLoadThread.class);
|
||||||
|
|
||||||
|
boolean isComplete = false;
|
||||||
|
ExchangeSession.Folder folder;
|
||||||
|
IOException exception;
|
||||||
|
|
||||||
|
FolderLoadThread(String threadName, ExchangeSession.Folder folder) {
|
||||||
|
super(threadName + "-LoadFolder");
|
||||||
|
setDaemon(true);
|
||||||
|
this.folder = folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
folder.loadMessages();
|
||||||
|
} catch (IOException e) {
|
||||||
|
exception = e;
|
||||||
|
} finally {
|
||||||
|
isComplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load folder in a separate thread.
|
||||||
|
*
|
||||||
|
* @param folder current folder
|
||||||
|
* @param outputStream client connection
|
||||||
|
* @throws InterruptedException on error
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
|
public static void loadFolder(ExchangeSession.Folder folder, OutputStream outputStream) throws InterruptedException, IOException {
|
||||||
|
FolderLoadThread folderLoadThread = new FolderLoadThread(currentThread().getName(), folder);
|
||||||
|
folderLoadThread.start();
|
||||||
|
while (!folderLoadThread.isComplete) {
|
||||||
|
folderLoadThread.join(20000);
|
||||||
|
LOGGER.debug("Still loading " + folder.folderPath + " (" + folder.count() + " messages)");
|
||||||
|
if (Settings.getBooleanProperty("davmail.imapEnableKeepalive", false)) {
|
||||||
|
try {
|
||||||
|
outputStream.write(' ');
|
||||||
|
outputStream.flush();
|
||||||
|
} catch (SocketException e) {
|
||||||
|
folderLoadThread.interrupt();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (folderLoadThread.exception != null) {
|
||||||
|
throw folderLoadThread.exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package davmail.exchange;
|
package davmail.exchange;
|
||||||
|
|
||||||
|
import davmail.Settings;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
@ -57,14 +58,16 @@ public class MessageLoadThread extends Thread {
|
||||||
while (!messageLoadThread.isComplete) {
|
while (!messageLoadThread.isComplete) {
|
||||||
messageLoadThread.join(10000);
|
messageLoadThread.join(10000);
|
||||||
LOGGER.debug("Still loading uid " + message.getUid() + " imapUid " + message.getImapUid());
|
LOGGER.debug("Still loading uid " + message.getUid() + " imapUid " + message.getImapUid());
|
||||||
try {
|
if (Settings.getBooleanProperty("davmail.imapEnableKeepalive", false)) {
|
||||||
outputStream.write(' ');
|
try {
|
||||||
outputStream.flush();
|
outputStream.write(' ');
|
||||||
} catch (SocketException e) {
|
outputStream.flush();
|
||||||
// client closed connection, stop thread
|
} catch (SocketException e) {
|
||||||
message.dropMimeMessage();
|
// client closed connection, stop thread
|
||||||
messageLoadThread.interrupt();
|
message.dropMimeMessage();
|
||||||
throw e;
|
messageLoadThread.interrupt();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (messageLoadThread.ioException != null) {
|
if (messageLoadThread.ioException != null) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import davmail.exception.HttpNotFoundException;
|
||||||
import davmail.exception.InsufficientStorageException;
|
import davmail.exception.InsufficientStorageException;
|
||||||
import davmail.exchange.ExchangeSession;
|
import davmail.exchange.ExchangeSession;
|
||||||
import davmail.exchange.ExchangeSessionFactory;
|
import davmail.exchange.ExchangeSessionFactory;
|
||||||
|
import davmail.exchange.FolderLoadThread;
|
||||||
import davmail.exchange.MessageLoadThread;
|
import davmail.exchange.MessageLoadThread;
|
||||||
import davmail.ui.tray.DavGatewayTray;
|
import davmail.ui.tray.DavGatewayTray;
|
||||||
import davmail.util.IOUtil;
|
import davmail.util.IOUtil;
|
||||||
|
@ -57,28 +58,6 @@ 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 + "-LoadFolder");
|
|
||||||
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.
|
||||||
*
|
*
|
||||||
|
@ -251,25 +230,10 @@ public class ImapConnection extends AbstractConnection {
|
||||||
sendClient("* " + currentFolder.count() + " EXISTS");
|
sendClient("* " + currentFolder.count() + " EXISTS");
|
||||||
} else {
|
} else {
|
||||||
// load folder in a separate thread
|
// load folder in a separate thread
|
||||||
FolderLoadThread folderLoadThread = new FolderLoadThread(currentThread().getName(), currentFolder);
|
|
||||||
folderLoadThread.start();
|
|
||||||
LOGGER.debug("*");
|
LOGGER.debug("*");
|
||||||
os.write('*');
|
os.write('*');
|
||||||
while (!folderLoadThread.isComplete) {
|
FolderLoadThread.loadFolder(currentFolder, os);
|
||||||
folderLoadThread.join(20000);
|
|
||||||
LOGGER.debug("Still loading " + currentFolder.folderPath+" ("+currentFolder.count()+" messages)");
|
|
||||||
try {
|
|
||||||
os.write(' ');
|
|
||||||
os.flush();
|
|
||||||
} catch (SocketException e) {
|
|
||||||
folderLoadThread.interrupt();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendClient(" " + currentFolder.count() + " EXISTS");
|
sendClient(" " + currentFolder.count() + " EXISTS");
|
||||||
if (folderLoadThread.exception != null) {
|
|
||||||
throw folderLoadThread.exception;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendClient("* " + currentFolder.recent + " RECENT");
|
sendClient("* " + currentFolder.recent + " RECENT");
|
||||||
|
|
Loading…
Reference in New Issue