1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

Added a new setting to purge messages from sent folder

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@204 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-12-05 10:01:24 +00:00
parent 76bdf71ee9
commit 21ea655d2a
7 changed files with 47 additions and 28 deletions

View File

@ -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");

View File

@ -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<String> reqProps = new Vector<String>();
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 = "<?xml version=\"1.0\"?>\n" +
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
" <d:sql>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\" &lt; '"+dateFormatter.format(cal.getTime())+"'\n" +
" AND \"DAV:getlastmodified\" &lt; '" + dateFormatter.format(cal.getTime()) + "'\n" +
" </d:sql>\n" +
"</d:searchrequest>";
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.

View File

@ -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", " "));
}

View File

@ -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());

View File

@ -50,6 +50,11 @@
<td>Number of days to keep messages in Exchange trash folder before actual deletion</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>90</td>
</tr>
<tr>
<td>Allow remote connections</td>
<td>Allow remote connections to the gateway (server mode)</td>

View File

@ -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=

View File

@ -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=