From c0ef8f93572c1a104a25034aa95ba817b8321ec6 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 15 Feb 2012 21:41:03 +0000 Subject: [PATCH] POP: add a new setting to mark messages read after RETR git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1910 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/Settings.java | 1 + src/java/davmail/exchange/ExchangeSession.java | 16 ++++++++++++---- src/java/davmail/pop/PopConnection.java | 7 ++++++- src/java/davmail/ui/SettingsFrame.java | 9 ++++++++- src/java/davmailmessages.properties | 4 +++- src/java/davmailmessages_fr.properties | 2 ++ src/site/xdoc/advanced.xml | 5 +++++ 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/java/davmail/Settings.java b/src/java/davmail/Settings.java index 98c00d6e..1b5a6c7e 100644 --- a/src/java/davmail/Settings.java +++ b/src/java/davmail/Settings.java @@ -157,6 +157,7 @@ public final class Settings { SETTINGS.put("davmail.showStartupBanner", Boolean.TRUE.toString()); SETTINGS.put("davmail.disableGuiNotifications", Boolean.FALSE.toString()); SETTINGS.put("davmail.imapAutoExpunge", Boolean.TRUE.toString()); + SETTINGS.put("davmail.popMarkReadOnRetr", Boolean.FALSE.toString()); SETTINGS.put("davmail.smtpSaveInSent", Boolean.TRUE.toString()); SETTINGS.put("davmail.ssl.keystoreType", ""); SETTINGS.put("davmail.ssl.keystoreFile", ""); diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index b885150b..5006a24b 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1850,12 +1850,20 @@ public abstract class ExchangeSession { * @throws IOException on error */ public void moveToTrash() throws IOException { - // mark message as read + markRead(); + + ExchangeSession.this.moveToTrash(this); + } + + /** + * Mark message as read. + * + * @throws IOException on error + */ + public void markRead() throws IOException { HashMap properties = new HashMap(); properties.put("read", "1"); updateMessage(this, properties); - - ExchangeSession.this.moveToTrash(this); } /** @@ -2590,7 +2598,7 @@ public abstract class ExchangeSession { } return andCondition; } catch (ParseException e) { - throw new IOException(e); + throw new IOException(e+" "+e.getMessage()); } } diff --git a/src/java/davmail/pop/PopConnection.java b/src/java/davmail/pop/PopConnection.java index f6212552..27926940 100644 --- a/src/java/davmail/pop/PopConnection.java +++ b/src/java/davmail/pop/PopConnection.java @@ -21,6 +21,7 @@ package davmail.pop; import davmail.AbstractConnection; import davmail.BundleMessage; import davmail.DavGateway; +import davmail.Settings; import davmail.exchange.DoubleDotOutputStream; import davmail.exchange.ExchangeSession; import davmail.exchange.ExchangeSessionFactory; @@ -202,8 +203,12 @@ public class PopConnection extends AbstractConnection { int messageNumber = Integer.valueOf(tokens.nextToken()) - 1; sendOK(""); DoubleDotOutputStream doubleDotOutputStream = new DoubleDotOutputStream(os); - IOUtil.write(messages.get(messageNumber).getRawInputStream(), doubleDotOutputStream); + ExchangeSession.Message message = messages.get(messageNumber); + IOUtil.write(message.getRawInputStream(), doubleDotOutputStream); doubleDotOutputStream.close(); + if (Settings.getBooleanProperty("davmail.popMarkReadOnRetr")) { + message.markRead(); + } } catch (SocketException e) { // can not send error to client after a socket exception LOGGER.warn(BundleMessage.formatLog("LOG_CLIENT_CLOSED_CONNECTION")); diff --git a/src/java/davmail/ui/SettingsFrame.java b/src/java/davmail/ui/SettingsFrame.java index 791ee8a7..90f47e7b 100644 --- a/src/java/davmail/ui/SettingsFrame.java +++ b/src/java/davmail/ui/SettingsFrame.java @@ -99,6 +99,7 @@ public class SettingsFrame extends JFrame { JCheckBox showStartupBannerCheckBox; JCheckBox disableGuiNotificationsCheckBox; JCheckBox imapAutoExpungeCheckBox; + JCheckBox popMarkReadOnRetrCheckBox; JComboBox enableEwsComboBox; JCheckBox smtpSaveInSentCheckBox; @@ -411,7 +412,7 @@ public class SettingsFrame extends JFrame { } protected JPanel getOtherSettingsPanel() { - JPanel otherSettingsPanel = new JPanel(new GridLayout(10, 2)); + JPanel otherSettingsPanel = new JPanel(new GridLayout(11, 2)); otherSettingsPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_OTHER"))); enableEwsComboBox = new JComboBox(new String[]{WEBDAV, EWS, AUTO}); @@ -428,6 +429,8 @@ public class SettingsFrame extends JFrame { disableGuiNotificationsCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableGuiNotifications", false)); imapAutoExpungeCheckBox = new JCheckBox(); imapAutoExpungeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAutoExpunge", true)); + popMarkReadOnRetrCheckBox = new JCheckBox(); + popMarkReadOnRetrCheckBox.setSelected(Settings.getBooleanProperty("davmail.popMarkReadOnRetr", false)); smtpSaveInSentCheckBox = new JCheckBox(); smtpSaveInSentCheckBox.setSelected(Settings.getBooleanProperty("davmail.smtpSaveInSent", true)); disableUpdateCheck = new JCheckBox(); @@ -449,6 +452,8 @@ public class SettingsFrame extends JFrame { BundleMessage.format("UI_DISABLE_GUI_NOTIFICATIONS_HELP")); addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_IMAP_AUTO_EXPUNGE"), imapAutoExpungeCheckBox, BundleMessage.format("UI_IMAP_AUTO_EXPUNGE_HELP")); + addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_POP_MARK_READ"), popMarkReadOnRetrCheckBox, + BundleMessage.format("UI_POP_MARK_READ_HELP")); addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_SAVE_IN_SENT"), smtpSaveInSentCheckBox, BundleMessage.format("UI_SAVE_IN_SENT_HELP")); addSettingComponent(otherSettingsPanel, BundleMessage.format("UI_DISABLE_UPDATE_CHECK"), disableUpdateCheck, @@ -568,6 +573,7 @@ public class SettingsFrame extends JFrame { showStartupBannerCheckBox.setSelected(Settings.getBooleanProperty("davmail.showStartupBanner", true)); disableGuiNotificationsCheckBox.setSelected(Settings.getBooleanProperty("davmail.disableGuiNotifications", false)); imapAutoExpungeCheckBox.setSelected(Settings.getBooleanProperty("davmail.imapAutoExpunge", true)); + popMarkReadOnRetrCheckBox.setSelected(Settings.getBooleanProperty("davmail.popMarkReadOnRetrCheckBox", false)); setEwsModeSelectedItem(Settings.getProperty("davmail.enableEws", "auto")); smtpSaveInSentCheckBox.setSelected(Settings.getBooleanProperty("davmail.smtpSaveInSent", true)); @@ -712,6 +718,7 @@ public class SettingsFrame extends JFrame { Settings.setProperty("davmail.showStartupBanner", String.valueOf(showStartupBannerCheckBox.isSelected())); Settings.setProperty("davmail.disableGuiNotifications", String.valueOf(disableGuiNotificationsCheckBox.isSelected())); Settings.setProperty("davmail.imapAutoExpunge", String.valueOf(imapAutoExpungeCheckBox.isSelected())); + Settings.setProperty("davmail.popMarkReadOnRetr", String.valueOf(popMarkReadOnRetrCheckBox.isSelected())); String selectedEwsMode = (String) enableEwsComboBox.getSelectedItem(); String enableEws; if (EWS.equals(selectedEwsMode)) { diff --git a/src/java/davmailmessages.properties b/src/java/davmailmessages.properties index ee26d944..04c8a3e8 100644 --- a/src/java/davmailmessages.properties +++ b/src/java/davmailmessages.properties @@ -14,7 +14,7 @@ EXCEPTION_INVALID_CREDENTIALS=Invalid credentials EXCEPTION_INVALID_DATE=Invalid date: {0} EXCEPTION_INVALID_DATES=Invalid dates: {0} EXCEPTION_INVALID_FOLDER_URL=Invalid folder URL: {0} -EXCEPTION_INVALID_HEADER=Invalid header, HTTPS connection to an HTTP listener ? +EXCEPTION_INVALID_HEADER=Invalid header, HTTPS connection to an HTTP listener ? EXCEPTION_INVALID_KEEPALIVE=Invalid Keep-Alive: {0} EXCEPTION_INVALID_MAIL_PATH=Invalid mail path: {0} EXCEPTION_INVALID_MESSAGE_CONTENT=Invalid message content: {0} @@ -261,6 +261,8 @@ UI_DISABLE_GUI_NOTIFICATIONS=Disable balloon notifications UI_DISABLE_GUI_NOTIFICATIONS_HELP=Disable all graphical notifications UI_IMAP_AUTO_EXPUNGE=IMAP auto expunge: UI_IMAP_AUTO_EXPUNGE_HELP=Delete messages immediately on the server over IMAP +UI_POP_MARK_READ=POP mark read: +UI_POP_MARK_READ_HELP=Mark messages read on server immediately after retrieval 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 EXCEPTION_EWS_NOT_AVAILABLE=EWS end point not available diff --git a/src/java/davmailmessages_fr.properties b/src/java/davmailmessages_fr.properties index f9098fb5..b72aaab2 100644 --- a/src/java/davmailmessages_fr.properties +++ b/src/java/davmailmessages_fr.properties @@ -264,6 +264,8 @@ UI_IMAP_IDLE_DELAY=D UI_IMAP_IDLE_DELAY_HELP=Délai de surveillance du dossier IMAP en minutes, laisser vide pour désactiver le support IDLE UI_IMAP_AUTO_EXPUNGE=IMAP suppression immédiate : UI_IMAP_AUTO_EXPUNGE_HELP=Supprimer immédiatement les messages du serveur via IMAP +UI_POP_MARK_READ=POP marquer lu : +UI_POP_MARK_READ_HELP=Marquer les messages lus sur le serveur immédiatement après chargement EXCEPTION_EWS_NOT_AVAILABLE=Point d''accès EWS non disponible EXCEPTION_FOLDER_NOT_FOUND=Dossier {0} non trouvé UNKNOWN_ATTRIBUTE=Attribut inconnu: {0} diff --git a/src/site/xdoc/advanced.xml b/src/site/xdoc/advanced.xml index 76193835..0e0fb8a0 100644 --- a/src/site/xdoc/advanced.xml +++ b/src/site/xdoc/advanced.xml @@ -162,6 +162,11 @@ 90 + + POP mark read + Mark messages read on server immediately after retrieval + true +