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

Caldav: basic move item implementation

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1427 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-09-07 21:09:53 +00:00
parent 39079d3719
commit 146790a237
7 changed files with 32 additions and 5 deletions

View File

@ -43,6 +43,7 @@ import java.io.*;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
@ -313,6 +314,10 @@ public class CaldavConnection extends AbstractConnection {
//properties.put("displayname", request.getProperty("displayname"));
int status = session.createCalendarFolder(request.getFolderPath(), properties);
sendHttpResponse(status, null);
} else if (request.isMove()) {
String destinationUrl = request.getHeader("destination");
session.moveItem(request.path, new URL(destinationUrl).getPath());
sendHttpResponse(HttpStatus.SC_CREATED, null);
} else {
sendUnsupported(request);
}
@ -1271,6 +1276,10 @@ public class CaldavConnection extends AbstractConnection {
return "MKCALENDAR".equals(command);
}
public boolean isMove() {
return "MOVE".equals(command);
}
/**
* Check if this request is a folder request.
*

View File

@ -1198,6 +1198,8 @@ public abstract class ExchangeSession {
*/
public abstract void moveFolder(String folderName, String targetName) throws IOException;
public abstract void moveItem(String sourcePath, String targetPath) throws IOException;
protected abstract void moveToTrash(Message message) throws IOException;
/**

View File

@ -1560,14 +1560,18 @@ public class DavExchangeSession extends ExchangeSession {
}
}
protected void moveMessage(String sourcePath, String targetPath) throws IOException {
/**
* @inheritDoc
*/
@Override
public void moveItem(String sourcePath, String targetPath) throws IOException {
MoveMethod method = new MoveMethod(URIUtil.encodePath(getFolderPath(sourcePath)),
URIUtil.encodePath(getFolderPath(targetPath)), false);
try {
int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
throw new DavMailException("EXCEPTION_UNABLE_TO_MOVE_FOLDER");
} else if (statusCode != HttpStatus.SC_OK) {
throw new DavMailException("EXCEPTION_UNABLE_TO_MOVE_ITEM");
} else if (statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_OK) {
throw DavGatewayHttpClientFacade.buildHttpException(method);
}
} finally {
@ -2196,7 +2200,7 @@ public class DavExchangeSession extends ExchangeSession {
HashMap<String, String> properties = new HashMap<String, String>();
properties.put("draft", "9");
createMessage(DRAFTS, itemName, properties, mimeMessage);
moveMessage(DRAFTS + '/' + itemName, SENDMSG);
moveItem(DRAFTS + '/' + itemName, SENDMSG);
}
protected boolean isGzipEncoded(HttpMethod method) {

View File

@ -134,7 +134,7 @@ public class Field {
// unused: force message encoding
createField("messageFormat", 0x5909, PropertyType.Integer);//PR_MSG_EDITOR_FORMAT EDITOR_FORMAT_PLAINTEXT = 1 EDITOR_FORMAT_HTML = 2
createField("mailOverrideFormat", 0x5909, PropertyType.Integer);//PR_INETMAIL_OVERRIDE_FORMAT ENCODING_PREFERENCE = 2 BODY_ENCODING_TEXT_AND_HTML = 1 ENCODING_MIME = 4
createField("mailOverrideFormat", 0x5902, PropertyType.Integer);//PR_INETMAIL_OVERRIDE_FORMAT ENCODING_PREFERENCE = 2 BODY_ENCODING_TEXT_AND_HTML = 1 ENCODING_MIME = 4
// IMAP search

View File

@ -840,6 +840,16 @@ public class EwsExchangeSession extends ExchangeSession {
}
}
@Override
public void moveItem(String sourcePath, String targetPath) throws IOException {
FolderPath sourceFolderPath = new FolderPath(sourcePath);
Item item = getItem(sourceFolderPath.parentPath, sourceFolderPath.folderName);
FolderPath targetFolderPath = new FolderPath(targetPath);
FolderId toFolderId = getFolderId(targetFolderPath.parentPath);
MoveItemMethod moveItemMethod = new MoveItemMethod(((Event)item).itemId, toFolderId);
executeMethod(moveItemMethod);
}
/**
* @inheritDoc
*/

View File

@ -29,6 +29,7 @@ EXCEPTION_UNABLE_TO_CREATE_MESSAGE=Unable to create message {0}: {1}{2}{3}
EXCEPTION_UNABLE_TO_GET_FOLDER=Unable to get folder at {0}
EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER=Unable to get mail folder at {0}, Webdav not available on Exchange server
EXCEPTION_UNABLE_TO_MOVE_FOLDER=Unable to move folder, target already exists
EXCEPTION_UNABLE_TO_MOVE_MESSAGE=Unable to move message, target already exists
EXCEPTION_UNABLE_TO_COPY_MESSAGE=Unable to copy message, target already exists
EXCEPTION_UNABLE_TO_PATCH_MESSAGE=Unable to patch message {0}: {1}{2}{3}
EXCEPTION_UNABLE_TO_UPDATE_MESSAGE=Unable to update message properties

View File

@ -26,6 +26,7 @@ EXCEPTION_UNABLE_TO_CREATE_MESSAGE=Impossible de cr
EXCEPTION_UNABLE_TO_GET_FOLDER=Impossible d''obtenir le dossier {0}
EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER=Impossible d''obtenir le dossier de messagerie à l''adresse {0}, Webdav non disponible sur le serveur Exchange
EXCEPTION_UNABLE_TO_MOVE_FOLDER=Impossible de déplacer le dossier, la cible existe
EXCEPTION_UNABLE_TO_MOVE_MESSAGE=Impossible de déplacer le message, la cible existe
EXCEPTION_UNABLE_TO_COPY_MESSAGE=Impossible de copier le message, la cible existe
EXCEPTION_UNABLE_TO_PATCH_MESSAGE=Impossible de mettre ) jour le message {0} : {1}{2}{3}
EXCEPTION_UNABLE_TO_UPDATE_MESSAGE=Impossible de mettre à jour les propriétés du message