IMAP: add a new setting to enable/disable IDLE

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1019 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-04-23 14:43:04 +00:00
parent 97bb065a9b
commit ec76698bcc
7 changed files with 64 additions and 28 deletions

View File

@ -137,6 +137,7 @@ public final class Settings {
SETTINGS.put("davmail.keepDelay", "30");
SETTINGS.put("davmail.sentKeepDelay", "90");
SETTINGS.put("davmail.caldavPastDelay", "90");
SETTINGS.put("davmail.imapIdleDelay", "");
SETTINGS.put("davmail.allowRemote", Boolean.FALSE.toString());
SETTINGS.put("davmail.bindAddress", "");
SETTINGS.put("davmail.useSystemProxies", Boolean.TRUE.toString());

View File

@ -22,6 +22,7 @@ import com.sun.mail.imap.protocol.BASE64MailboxDecoder;
import com.sun.mail.imap.protocol.BASE64MailboxEncoder;
import davmail.AbstractConnection;
import davmail.BundleMessage;
import davmail.Settings;
import davmail.exception.DavMailException;
import davmail.exception.HttpForbiddenException;
import davmail.exception.HttpNotFoundException;
@ -61,12 +62,20 @@ public class ImapConnection extends AbstractConnection {
@Override
public void run() {
final String capabilities;
int imapIdleDelay = Settings.getIntProperty("davmail.imapIdleDelay") * 60;
if (imapIdleDelay > 0) {
capabilities = "CAPABILITY IMAP4REV1 AUTH=LOGIN IDLE";
} else {
capabilities = "CAPABILITY IMAP4REV1 AUTH=LOGIN";
}
String line;
String commandId = null;
IMAPTokenizer tokens;
try {
ExchangeSessionFactory.checkConfig();
sendClient("* OK [CAPABILITY IMAP4REV1 AUTH=LOGIN IDLE] IMAP4rev1 DavMail server ready");
sendClient("* OK ["+capabilities+"] IMAP4rev1 DavMail server ready");
for (; ;) {
line = readClient();
// unable to read line, connection closed ?
@ -85,7 +94,7 @@ public class ImapConnection extends AbstractConnection {
break;
}
if ("capability".equalsIgnoreCase(command)) {
sendClient("* CAPABILITY IMAP4REV1 AUTH=LOGIN IDLE");
sendClient("* "+capabilities);
sendClient(commandId + " OK CAPABILITY completed");
} else if ("login".equalsIgnoreCase(command)) {
parseCredentials(tokens);
@ -417,14 +426,14 @@ public class ImapConnection extends AbstractConnection {
String messageName = UUID.randomUUID().toString();
session.createMessage(folderName, messageName, properties, new String(buffer));
sendClient(commandId + " OK APPEND completed");
} else if ("idle".equalsIgnoreCase(command)) {
} else if ("idle".equalsIgnoreCase(command) && imapIdleDelay > 0) {
sendClient("+ idling ");
// clear cache before going to idle mode
currentFolder.clearCache();
DavGatewayTray.resetIcon();
int count = 0;
while (!in.ready()) {
if (++count >= 30) {
if (++count >= imapIdleDelay) {
count = 0;
List<Long> previousImapUidList = currentFolder.getImapUidList();
if (session.refreshFolder(currentFolder)) {
@ -432,7 +441,7 @@ public class ImapConnection extends AbstractConnection {
}
}
// sleep 1 second
Thread.sleep(1000);
Thread.sleep(1000);
}
// read DONE line
line = readClient();
@ -539,8 +548,9 @@ public class ImapConnection extends AbstractConnection {
/**
* Send expunge untagged response for removed IMAP message uids.
*
* @param previousImapUidList uid list before refresh
* @param imapUidList uid list after refresh
* @param imapUidList uid list after refresh
* @throws IOException on error
*/
private void handleRefresh(List<Long> previousImapUidList, List<Long> imapUidList) throws IOException {
@ -621,11 +631,11 @@ public class ImapConnection extends AbstractConnection {
} else if ("RFC822.HEADER".equals(param) || partIndexString.startsWith("HEADER")) {
// write headers only
partOutputStream = new PartOutputStream(baos, true, false, startIndex, maxSize);
partInputStream = message.getRawInputStream();
partInputStream = message.getRawInputStream();
} else {
MimePart bodyPart = mimeMessage;
String[] partIndexStrings = partIndexString.split("\\.");
for (String subPartIndexString:partIndexStrings) {
for (String subPartIndexString : partIndexStrings) {
int subPartIndex;
// try to parse part index
try {
@ -650,9 +660,9 @@ public class ImapConnection extends AbstractConnection {
// write selected part, without headers
partOutputStream = new PartialOutputStream(baos, startIndex, maxSize);
if (bodyPart instanceof MimeMessage) {
partInputStream = ((MimeMessage)bodyPart).getRawInputStream();
partInputStream = ((MimeMessage) bodyPart).getRawInputStream();
} else {
partInputStream = ((MimeBodyPart)bodyPart).getRawInputStream();
partInputStream = ((MimeBodyPart) bodyPart).getRawInputStream();
}
}

View File

@ -52,6 +52,7 @@ public class SettingsFrame extends JFrame {
protected JTextField keepDelayField;
protected JTextField sentKeepDelayField;
protected JTextField caldavPastDelayField;
protected JTextField imapIdleDelayField;
JCheckBox useSystemProxiesField;
JCheckBox enableProxyField;
@ -194,12 +195,13 @@ public class SettingsFrame extends JFrame {
}
protected JPanel getDelaysPanel() {
JPanel delaysPanel = new JPanel(new GridLayout(3, 2));
JPanel delaysPanel = new JPanel(new GridLayout(4, 2));
delaysPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_DELAYS")));
keepDelayField = new JTextField(Settings.getProperty("davmail.keepDelay"), 4);
sentKeepDelayField = new JTextField(Settings.getProperty("davmail.sentKeepDelay"), 4);
caldavPastDelayField = new JTextField(Settings.getProperty("davmail.caldavPastDelay"), 4);
imapIdleDelayField = new JTextField(Settings.getProperty("davmail.imapIdleDelay"), 4);
addSettingComponent(delaysPanel, BundleMessage.format("UI_KEEP_DELAY"), keepDelayField,
BundleMessage.format("UI_KEEP_DELAY_HELP"));
@ -207,6 +209,8 @@ public class SettingsFrame extends JFrame {
BundleMessage.format("UI_SENT_KEEP_DELAY_HELP"));
addSettingComponent(delaysPanel, BundleMessage.format("UI_CALENDAR_PAST_EVENTS"), caldavPastDelayField,
BundleMessage.format("UI_CALENDAR_PAST_EVENTS_HELP"));
addSettingComponent(delaysPanel, BundleMessage.format("UI_IMAP_IDLE_DELAY"), imapIdleDelayField,
BundleMessage.format("UI_IMAP_IDLE_DELAY_HELP"));
return delaysPanel;
}
@ -451,6 +455,7 @@ public class SettingsFrame extends JFrame {
keepDelayField.setText(Settings.getProperty("davmail.keepDelay"));
sentKeepDelayField.setText(Settings.getProperty("davmail.sentKeepDelay"));
caldavPastDelayField.setText(Settings.getProperty("davmail.caldavPastDelay"));
imapIdleDelayField.setText(Settings.getProperty("davmail.imapIdleDelay"));
boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies");
useSystemProxiesField.setSelected(useSystemProxies);
boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy");
@ -568,6 +573,7 @@ public class SettingsFrame extends JFrame {
Settings.setProperty("davmail.keepDelay", keepDelayField.getText());
Settings.setProperty("davmail.sentKeepDelay", sentKeepDelayField.getText());
Settings.setProperty("davmail.caldavPastDelay", caldavPastDelayField.getText());
Settings.setProperty("davmail.imapIdleDelay", imapIdleDelayField.getText());
Settings.setProperty("davmail.useSystemProxies", String.valueOf(useSystemProxiesField.isSelected()));
Settings.setProperty("davmail.enableProxy", String.valueOf(enableProxyField.isSelected()));
Settings.setProperty("davmail.proxyHost", httpProxyField.getText());

View File

@ -155,7 +155,7 @@ UI_BUTTON_OK=OK
UI_BUTTON_SAVE=Save
UI_CALDAV_PORT=Caldav HTTP port:
UI_CALDAV_PORT_HELP=Local Caldav server port to configure in Caldav (calendar) client
UI_CALENDAR_PAST_EVENTS=Calendar past events:
UI_CALENDAR_PAST_EVENTS=Calendar past events (Caldav):
UI_CALENDAR_PAST_EVENTS_HELP=Get events in the past not older than specified days count, leave empty for no limits
UI_CURRENT_VERSION=Current version: {0}<br>
UI_DAVMAIL_GATEWAY=DavMail Gateway
@ -173,7 +173,7 @@ UI_IMAP_PORT=Local IMAP port:
UI_IMAP_PORT_HELP=Local IMAP server port to configure in mail client
UI_ISSUED_BY=Issued by
UI_ISSUED_TO=Issued to
UI_KEEP_DELAY=Trash keep delay:
UI_KEEP_DELAY=Trash keep delay (POP):
UI_KEEP_DELAY_HELP=Number of days to keep messages in trash
UI_KEY_PASSWORD=Key password:
UI_KEY_PASSWORD_HELP=SSL key password inside key store
@ -216,7 +216,7 @@ UI_PROXY_PASSWORD=Proxy password:
UI_PROXY_PORT=Proxy port:
UI_PROXY_SERVER=Proxy server:
UI_PROXY_USER=Proxy user:
UI_SENT_KEEP_DELAY=Sent keep delay:
UI_SENT_KEEP_DELAY=POP Sent keep delay:
UI_SENT_KEEP_DELAY_HELP=Number of days to keep messages in sent folder
UI_SERIAL=Serial
UI_SERVER_CERTIFICATE=Server Certificate (Client to DavMail)
@ -252,3 +252,5 @@ UI_DEFAULT_DOMAIN_HELP=Default windows domain name
UI_USE_SYSTEM_PROXIES=Use system proxy settings :
UI_SHOW_STARTUP_BANNER=Display startup banner
UI_SHOW_STARTUP_BANNER_HELP=Whether to show the initial startup notification window or not
UI_IMAP_IDLE_DELAY=IDLE folder monitor delay (IMAP):
UI_IMAP_IDLE_DELAY_HELP=IMAP folder idle monitor delay in minutes, leave empty to disable IDLE support

View File

@ -144,7 +144,7 @@ UI_BUTTON_OK=OK
UI_BUTTON_SAVE=Enregistrer
UI_CALDAV_PORT=Port HTTP Caldav :
UI_CALDAV_PORT_HELP=Port local Caldav à configurer dans le client Caldav (agenda)
UI_CALENDAR_PAST_EVENTS=Jours passés du calendrier :
UI_CALENDAR_PAST_EVENTS=Jours passés du calendrier (Caldav) :
UI_CALENDAR_PAST_EVENTS_HELP=Limiter les évènements remontés
UI_CURRENT_VERSION=Version actuelle : {0}<br>
UI_DAVMAIL_GATEWAY=Passerelle DavMail
@ -162,7 +162,7 @@ UI_IMAP_PORT=Port IMAP local :
UI_IMAP_PORT_HELP=Port IMAP local à configurer dans le client de messagerie
UI_ISSUED_BY=Emis par
UI_ISSUED_TO=Emis pour
UI_KEEP_DELAY=Délai de rétention corbeille :
UI_KEEP_DELAY=Délai de rétention corbeille (POP) :
UI_KEEP_DELAY_HELP=Nombre de jours de conservation des messages dans la corbeille
UI_KEY_PASSWORD=Mot de passe clé :
UI_KEY_PASSWORD_HELP=Mot de passe clé SSL contenue dans le fichier des clés
@ -193,7 +193,7 @@ UI_PROXY_PASSWORD=Mot de passe proxy :
UI_PROXY_PORT=Port du serveur proxy :
UI_PROXY_SERVER=Serveur proxy :
UI_PROXY_USER=Identifiant proxy :
UI_SENT_KEEP_DELAY=Délai de rétention envoyés :
UI_SENT_KEEP_DELAY=POP Délai de rétention envoyés :
UI_SENT_KEEP_DELAY_HELP=Nombre de jours de conservation des messages dans le dossier des messages envoyés
UI_SERIAL=Numéro de série
UI_SERVER_CERTIFICATE=Certificat Serveur (Client vers DavMail)
@ -251,4 +251,6 @@ EXCEPTION_INVALID_PARAMETER=Param
UI_USE_SYSTEM_PROXIES=Utiliser la configuration système :
UI_SHOW_STARTUP_BANNER=Notification au lancement
UI_SHOW_STARTUP_BANNER_HELP=Afficher ou non la fenêtre de notification au démarrage
LOG_READ_CLIENT_AUTH_LOGIN=< AUTH LOGIN ********
LOG_READ_CLIENT_AUTH_LOGIN=< AUTH LOGIN ********
UI_IMAP_IDLE_DELAY=Délai de surveillance dossier (IMAP) :
UI_IMAP_IDLE_DELAY_HELP=Délai de surveillance du dossier IMAP en minutes, laisser vide pour désactiver le support IDLE

View File

@ -27,8 +27,10 @@
</tr>
<tr>
<td>OWA url</td>
<td>Outlook Web Access URL to access the exchange server, i.e. the base webmail URL<br/>
Note: use /owa/ path for Exchange 2007, /exchange/ for older versions</td>
<td>Outlook Web Access URL to access the exchange server, i.e. the base webmail URL
<br/>
Note: use /owa/ path for Exchange 2007, /exchange/ for older versions
</td>
<td>http://exchangeServer/owa/</td>
</tr>
<tr>
@ -57,20 +59,28 @@
<td>389</td>
</tr>
<tr>
<td>Keep Delay</td>
<td>Number of days to keep messages in Exchange trash folder before actual deletion</td>
<td>Keep Delay (POP)</td>
<td>Number of days to keep messages in Exchange trash folder before actual deletion,
only for POP service
</td>
<td>30</td>
</tr>
<tr>
<td>Sent Keep Delay</td>
<td>Number of days to keep sent messages in Exchange sent folder</td>
<td>Sent Keep Delay (POP)</td>
<td>Number of days to keep sent messages in Exchange sent folder,
only for POP service</td>
<td>90</td>
</tr>
<tr>
<td>Calendar past events</td>
<td>Calendar past events (Caldav)</td>
<td>Get events in the past not older than specified days count, leave empty for no limits</td>
<td>90</td>
</tr>
<tr>
<td>IDLE folder monitor delay (IMAP):</td>
<td>IMAP folder idle monitor delay in minutes, leave empty to disable IDLE support</td>
<td>1</td>
</tr>
<tr>
<td>Allow remote connections</td>
<td>Allow remote connections to the gateway (server mode)</td>
@ -88,7 +98,9 @@
</tr>
<tr>
<td>Caldav alarm sound</td>
<td>Convert Caldav alarm to sound alarm supported by iCal, e.g. Basso. Leave empty for no conversion</td>
<td>Convert Caldav alarm to sound alarm supported by iCal, e.g. Basso. Leave empty for no
conversion
</td>
<td>Basso</td>
</tr>
<tr>
@ -99,7 +111,8 @@
<tr>
<td>Key store type</td>
<td>To encrypt communication between client and DavMail, create a server certificate,
choose key store type and set key store path</td>
choose key store type and set key store path
</td>
<td>JKS</td>
</tr>
<tr>
@ -121,7 +134,8 @@
<td>Client key store type</td>
<td>When the Exchange server requires mutual authentication,
choose client certificate key store type, PKCS11 for smartcard,
PKCS12 or JKS for certificate file</td>
PKCS12 or JKS for certificate file
</td>
<td>PKCS11</td>
</tr>
<tr>

View File

@ -38,6 +38,7 @@
davmail.keepDelay=30
davmail.sentKeepDelay=90
davmail.caldavPastDelay=90
davmail.imapIdleDelay=
davmail.useSystemProxies=false
davmail.enableProxy=false
davmail.proxyHost=