diff --git a/src/java/davmail/Settings.java b/src/java/davmail/Settings.java index ecb95abb..00648e0a 100644 --- a/src/java/davmail/Settings.java +++ b/src/java/davmail/Settings.java @@ -51,6 +51,7 @@ public class Settings { SETTINGS.put("davmail.smtpPort", "1025"); SETTINGS.put("davmail.caldavPort", "1080"); SETTINGS.put("davmail.keepDelay", "30"); + SETTINGS.put("davmail.sentKeepDelay", "90"); SETTINGS.put("davmail.allowRemote", "false"); SETTINGS.put("davmail.bindAddress", ""); SETTINGS.put("davmail.enableProxy", "false"); diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index de3a69a0..0c3032e9 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -41,8 +41,6 @@ public class ExchangeSession { MESSAGE_REQUEST_PROPERTIES.add("http://schemas.microsoft.com/mapi/proptag/x0e080003"); } - private static final int DEFAULT_KEEP_DELAY = 30; - /** * Date parser from Exchange format */ @@ -53,6 +51,7 @@ public class ExchangeSession { */ private String inboxUrl; private String deleteditemsUrl; + private String sentitemsUrl; private String sendmsgUrl; private String draftsUrl; private String calendarUrl; @@ -303,6 +302,7 @@ public class ExchangeSession { Vector reqProps = new Vector(); reqProps.add("urn:schemas:httpmail:inbox"); reqProps.add("urn:schemas:httpmail:deleteditems"); + reqProps.add("urn:schemas:httpmail:sentitems"); reqProps.add("urn:schemas:httpmail:sendmsg"); reqProps.add("urn:schemas:httpmail:drafts"); reqProps.add("urn:schemas:httpmail:calendar"); @@ -323,20 +323,19 @@ public class ExchangeSession { inboxUrl = URIUtil.decode(inboxProp.getPropertyAsString()); } if ("deleteditems".equals(inboxProp.getLocalName())) { - deleteditemsUrl = URIUtil.decode(inboxProp. - getPropertyAsString()); + deleteditemsUrl = URIUtil.decode(inboxProp.getPropertyAsString()); + } + if ("sentitems".equals(inboxProp.getLocalName())) { + sentitemsUrl = URIUtil.decode(inboxProp.getPropertyAsString()); } if ("sendmsg".equals(inboxProp.getLocalName())) { - sendmsgUrl = URIUtil.decode(inboxProp. - getPropertyAsString()); + sendmsgUrl = URIUtil.decode(inboxProp.getPropertyAsString()); } if ("drafts".equals(inboxProp.getLocalName())) { - draftsUrl = URIUtil.decode(inboxProp. - getPropertyAsString()); + draftsUrl = URIUtil.decode(inboxProp.getPropertyAsString()); } if ("calendar".equals(inboxProp.getLocalName())) { - calendarUrl = URIUtil.decode(inboxProp. - getPropertyAsString()); + calendarUrl = URIUtil.decode(inboxProp.getPropertyAsString()); } } @@ -345,10 +344,9 @@ public class ExchangeSession { LOGGER.debug("Inbox URL : " + inboxUrl); LOGGER.debug("Trash URL : " + deleteditemsUrl); + LOGGER.debug("Sent URL : " + sentitemsUrl); LOGGER.debug("Send URL : " + sendmsgUrl); LOGGER.debug("Drafts URL : " + draftsUrl); - // TODO : sometimes path, sometimes Url ? - deleteditemsUrl = URIUtil.getPath(deleteditemsUrl); wdr.setPath(URIUtil.getPath(inboxUrl)); } catch (Exception exc) { @@ -509,27 +507,35 @@ public class ExchangeSession { * * @throws IOException when unable to purge messages */ - public void purgeOldestTrashMessages() throws IOException { + public void purgeOldestTrashAndSentMessages() throws IOException { int keepDelay = Settings.getIntProperty("davmail.keepDelay"); - if (keepDelay == 0) { - keepDelay = DEFAULT_KEEP_DELAY; + if (keepDelay != 0) { + purgeOldestFolderMessages(deleteditemsUrl, keepDelay); } + // this is a new feature, default is : do nothing + int sentKeepDelay = Settings.getIntProperty("davmail.sentKeepDelay"); + if (sentKeepDelay != 0) { + purgeOldestFolderMessages(sentitemsUrl, sentKeepDelay); + } + } + + public void purgeOldestFolderMessages(String folderUrl, int keepDelay) throws IOException { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -keepDelay); - LOGGER.debug("Delete messages in trash since " + cal.getTime()); + LOGGER.debug("Delete messages in " + folderUrl + " since " + cal.getTime()); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String searchRequest = "\n" + "\n" + " Select \"DAV:uid\"" + - " FROM Scope('SHALLOW TRAVERSAL OF \"" + deleteditemsUrl + "\"')\n" + + " FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" + " WHERE \"DAV:isfolder\" = False\n" + - " AND \"DAV:getlastmodified\" < '"+dateFormatter.format(cal.getTime())+"'\n" + + " AND \"DAV:getlastmodified\" < '" + dateFormatter.format(cal.getTime()) + "'\n" + " \n" + ""; SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(currentFolderUrl), searchRequest); - searchMethod.setDebug(4); + //searchMethod.setDebug(4); try { int status = wdr.retrieveSessionInstance().executeMethod(searchMethod); // Also accept OK sent by buggy servers. diff --git a/src/java/davmail/pop/PopConnection.java b/src/java/davmail/pop/PopConnection.java index 80729894..d5ad2d22 100644 --- a/src/java/davmail/pop/PopConnection.java +++ b/src/java/davmail/pop/PopConnection.java @@ -28,7 +28,7 @@ public class PopConnection extends AbstractConnection { super("PopConnection", clientSocket, null); } - public long getTotalMessagesLength() { + protected long getTotalMessagesLength() { int result = 0; for (ExchangeSession.Message message : messages) { result += message.size; @@ -36,14 +36,14 @@ public class PopConnection extends AbstractConnection { return result; } - public void printCapabilities() throws IOException { + protected void printCapabilities() throws IOException { sendClient("TOP"); sendClient("USER"); sendClient("UIDL"); sendClient("."); } - public void printList() throws IOException { + protected void printList() throws IOException { int i = 1; for (ExchangeSession.Message message : messages) { sendClient(i++ + " " + message.size); @@ -51,7 +51,7 @@ public class PopConnection extends AbstractConnection { sendClient("."); } - public void printUidList() throws IOException { + protected void printUidList() throws IOException { int i = 1; for (ExchangeSession.Message message : messages) { sendClient(i++ + " " + message.uid); @@ -233,11 +233,11 @@ public class PopConnection extends AbstractConnection { DavGatewayTray.resetIcon(); } - public void sendOK(String message) throws IOException { + protected void sendOK(String message) throws IOException { sendClient("+OK ", message); } - public void sendERR(Exception e) throws IOException { + protected void sendERR(Exception e) throws IOException { String message = e.getMessage(); if (message == null) { message = e.toString(); @@ -245,7 +245,7 @@ public class PopConnection extends AbstractConnection { sendERR(message); } - public void sendERR(String message) throws IOException { + protected void sendERR(String message) throws IOException { sendClient("-ERR ", message.replaceAll("\\n", " ")); } diff --git a/src/java/davmail/ui/SettingsFrame.java b/src/java/davmail/ui/SettingsFrame.java index 22208d07..1ceb07d7 100644 --- a/src/java/davmail/ui/SettingsFrame.java +++ b/src/java/davmail/ui/SettingsFrame.java @@ -21,6 +21,7 @@ public class SettingsFrame extends JFrame { protected JTextField smtpPortField; protected JTextField caldavPortField; protected JTextField keepDelayField; + protected JTextField sentKeepDelayField; JCheckBox enableProxyField; JTextField httpProxyField; @@ -57,7 +58,7 @@ public class SettingsFrame extends JFrame { } protected JPanel getSettingsPanel() { - JPanel settingsPanel = new JPanel(new GridLayout(5, 2)); + JPanel settingsPanel = new JPanel(new GridLayout(6, 2)); settingsPanel.setBorder(BorderFactory.createTitledBorder("Gateway")); urlField = new JTextField(Settings.getProperty("davmail.url"), 17); @@ -65,12 +66,14 @@ public class SettingsFrame extends JFrame { smtpPortField = new JTextField(Settings.getProperty("davmail.smtpPort"), 4); caldavPortField = new JTextField(Settings.getProperty("davmail.caldavPort"), 4); keepDelayField = new JTextField(Settings.getProperty("davmail.keepDelay"), 4); + sentKeepDelayField = new JTextField(Settings.getProperty("davmail.sentKeepDelay"), 4); addSettingComponent(settingsPanel, "OWA url: ", urlField, "Base outlook web access URL"); addSettingComponent(settingsPanel, "Local POP port: ", popPortField); addSettingComponent(settingsPanel, "Local SMTP port: ", smtpPortField); addSettingComponent(settingsPanel, "Caldav HTTP port: ", caldavPortField); - addSettingComponent(settingsPanel, "Keep Delay: ", keepDelayField, "Number of days to keep messages in trash"); + addSettingComponent(settingsPanel, "Keep delay: ", keepDelayField, "Number of days to keep messages in trash"); + addSettingComponent(settingsPanel, "Sent keep delay: ", sentKeepDelayField, "Number of days to keep messages in sent folder"); return settingsPanel; } @@ -158,6 +161,7 @@ public class SettingsFrame extends JFrame { smtpPortField.setText(Settings.getProperty("davmail.smtpPort")); caldavPortField.setText(Settings.getProperty("davmail.caldavPort")); keepDelayField.setText(Settings.getProperty("davmail.keepDelay")); + sentKeepDelayField.setText(Settings.getProperty("davmail.sentKeepDelay")); boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy"); enableProxyField.setSelected(enableProxy); httpProxyField.setEnabled(enableProxy); @@ -224,6 +228,7 @@ public class SettingsFrame extends JFrame { Settings.setProperty("davmail.smtpPort", smtpPortField.getText()); Settings.setProperty("davmail.caldavPort", caldavPortField.getText()); Settings.setProperty("davmail.keepDelay", keepDelayField.getText()); + Settings.setProperty("davmail.sentKeepDelay", sentKeepDelayField.getText()); Settings.setProperty("davmail.enableProxy", String.valueOf(enableProxyField.isSelected())); Settings.setProperty("davmail.proxyHost", httpProxyField.getText()); Settings.setProperty("davmail.proxyPort", httpProxyPortField.getText()); diff --git a/src/site/xdoc/gettingstarted.xml b/src/site/xdoc/gettingstarted.xml index 1f81405e..e7b53b8c 100644 --- a/src/site/xdoc/gettingstarted.xml +++ b/src/site/xdoc/gettingstarted.xml @@ -50,6 +50,11 @@ Number of days to keep messages in Exchange trash folder before actual deletion 30 + + Sent Keep Delay + Number of days to keep sent messages in Exchange sent folder + 90 + Allow remote connections Allow remote connections to the gateway (server mode) diff --git a/src/site/xdoc/serversetup.xml b/src/site/xdoc/serversetup.xml index 44952bdf..48d06fb5 100644 --- a/src/site/xdoc/serversetup.xml +++ b/src/site/xdoc/serversetup.xml @@ -32,6 +32,7 @@ davmail.url=http://exchangeServer/exchange/ davmail.popPort=1110 davmail.smtpPort=1025 davmail.keepDelay=30 +davmail.sentKeepDelay=90 davmail.enableProxy=false davmail.proxyHost= davmail.proxyPort= diff --git a/src/web/WEB-INF/classes/davmail.properties b/src/web/WEB-INF/classes/davmail.properties index 31f03143..7c323122 100644 --- a/src/web/WEB-INF/classes/davmail.properties +++ b/src/web/WEB-INF/classes/davmail.properties @@ -2,6 +2,7 @@ davmail.url=http://exchangeServer/exchange/ davmail.popPort=1110 davmail.smtpPort=1025 davmail.keepDelay=30 +davmail.sentKeepDelay=90 davmail.enableProxy=false davmail.proxyHost=