mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12:22 -05:00
implement message purge after a delay
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@24 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
f471e40dc3
commit
de81d3d7b8
@ -443,6 +443,55 @@ public class ExchangeSession {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete oldest messages in trash.
|
||||||
|
*
|
||||||
|
* @param keepDelay number of days to keep messages in trash before delete
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void purgeOldestTrashMessages(int keepDelay) throws IOException {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.add(Calendar.DAY_OF_MONTH, -keepDelay);
|
||||||
|
logger.debug("Keep message not before " + cal.getTime());
|
||||||
|
long keepTimestamp = cal.getTimeInMillis();
|
||||||
|
|
||||||
|
Vector<String> deleteRequestProperties = new Vector<String>();
|
||||||
|
deleteRequestProperties.add("DAV:getlastmodified");
|
||||||
|
deleteRequestProperties.add("urn:schemas:mailheader:content-class");
|
||||||
|
|
||||||
|
Enumeration folderEnum = wdr.propfindMethod(deleteditemsUrl, 1, deleteRequestProperties);
|
||||||
|
while (folderEnum.hasMoreElements()) {
|
||||||
|
ResponseEntity entity = (ResponseEntity) folderEnum.nextElement();
|
||||||
|
String messageUrl = URIUtil.decode(entity.getHref());
|
||||||
|
String lastModifiedString = null;
|
||||||
|
String contentClass = null;
|
||||||
|
Enumeration propertiesEnum = entity.getProperties();
|
||||||
|
while (propertiesEnum.hasMoreElements()) {
|
||||||
|
Property prop = (Property) propertiesEnum.nextElement();
|
||||||
|
String localName = prop.getLocalName();
|
||||||
|
if ("getlastmodified".equals(localName)) {
|
||||||
|
lastModifiedString = prop.getPropertyAsString();
|
||||||
|
} else if ("content-class".equals(prop.getLocalName())) {
|
||||||
|
contentClass = prop.getPropertyAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ("urn:content-classes:message".equals(contentClass) &&
|
||||||
|
lastModifiedString != null && lastModifiedString.length() > 0) {
|
||||||
|
Date parsedDate;
|
||||||
|
try {
|
||||||
|
parsedDate = dateParser.parse(lastModifiedString);
|
||||||
|
if (parsedDate.getTime() < keepTimestamp) {
|
||||||
|
logger.debug("Delete " + messageUrl + " last modified " + parsedDate);
|
||||||
|
wdr.deleteMethod(messageUrl);
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.warn("Invalid message modified date " + lastModifiedString + " on " + messageUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void sendMessage(BufferedReader reader) throws IOException {
|
public void sendMessage(BufferedReader reader) throws IOException {
|
||||||
String subject = "davmailtemp";
|
String subject = "davmailtemp";
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
@ -680,7 +729,7 @@ public class ExchangeSession {
|
|||||||
if (mstnefDetected) {
|
if (mstnefDetected) {
|
||||||
fullHeaders = result.toString();
|
fullHeaders = result.toString();
|
||||||
// also fix invalid body characters
|
// also fix invalid body characters
|
||||||
htmlBody = htmlBody.replaceAll("’","'");
|
htmlBody = htmlBody.replaceAll("’", "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -26,6 +26,8 @@ public class TestExchangeSession {
|
|||||||
messageTest.write(System.out);
|
messageTest.write(System.out);
|
||||||
System.out.println("Elapsed time " + (System.currentTimeMillis()-startTime) + " ms");
|
System.out.println("Elapsed time " + (System.currentTimeMillis()-startTime) + " ms");
|
||||||
|
|
||||||
|
session.purgeOldestTrashMessages(22);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user