From 6fa000b55a24edff43cdd95c7c2dcc4d7d99e8a0 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 3 Feb 2009 21:02:33 +0000 Subject: [PATCH] Refactor message delete methods git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@323 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 22 +++++++++---------- src/java/davmail/imap/ImapConnection.java | 2 +- src/java/davmail/pop/PopConnection.java | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 19e537d4..53e91057 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -452,16 +452,6 @@ public class ExchangeSession { ); } - /** - * Replace invalid url chars - * - * @param subject - * @return - */ - protected String encodeSubject(String subject) { - return subject.replaceAll("/", "_xF8FF_").replaceAll("\\?", ""); - } - /** * Create message in specified folder. * Will overwrite an existing message with same subject in the same folder @@ -474,7 +464,7 @@ public class ExchangeSession { * @throws java.io.IOException when unable to create message */ public void createMessage(String folderUrl, String messageName, String bcc, String messageBody, boolean allowOverwrite) throws IOException { - String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + encodeSubject(messageName) + ".EML"); + String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + messageName + ".EML"); // create the message first as draft PropPatchMethod patchMethod = new PropPatchMethod(messageUrl); @@ -1031,6 +1021,16 @@ public class ExchangeSession { } public void delete() throws IOException { + wdr.deleteMethod(messageUrl); + if (wdr.getStatusCode() != HttpStatus.SC_OK) { + HttpException ex = new HttpException(); + ex.setReasonCode(wdr.getStatusCode()); + ex.setReason(wdr.getStatusMessage()); + throw ex; + } + } + + public void moveToTrash() throws IOException { String destination = deleteditemsUrl + messageUrl.substring(messageUrl.lastIndexOf("/")); LOGGER.debug("Deleting : " + messageUrl + " to " + destination); diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index 733501ed..88af84d1 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -466,7 +466,7 @@ public class ImapConnection extends AbstractConnection { for (ExchangeSession.Message message : messages) { index++; if (message.deleted) { - session.deleteMessage(message.messageUrl); + message.delete(); sendClient("* " + index + " EXPUNGE"); } } diff --git a/src/java/davmail/pop/PopConnection.java b/src/java/davmail/pop/PopConnection.java index 82dd85bb..2238a1ca 100644 --- a/src/java/davmail/pop/PopConnection.java +++ b/src/java/davmail/pop/PopConnection.java @@ -184,7 +184,7 @@ public class PopConnection extends AbstractConnection { try { int messageNumber = Integer.valueOf(tokens. nextToken()) - 1; - messages.get(messageNumber).delete(); + messages.get(messageNumber).moveToTrash(); sendOK("DELETE"); } catch (SocketException e) { // can not send error to client after a socket exception