mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 19:52:21 -05:00
IMAP: use permanenturl instead of href to avoid url encoding issues
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@829 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
5ef1595c6f
commit
8c5358b931
@ -675,6 +675,7 @@ public class ExchangeSession {
|
|||||||
message.messageUrl = URIUtil.decode(responseEntity.getHref());
|
message.messageUrl = URIUtil.decode(responseEntity.getHref());
|
||||||
DavPropertySet properties = responseEntity.getProperties(HttpStatus.SC_OK);
|
DavPropertySet properties = responseEntity.getProperties(HttpStatus.SC_OK);
|
||||||
|
|
||||||
|
message.permanentUrl = getPropertyIfExists(properties, "permanenturl", SCHEMAS_EXCHANGE);
|
||||||
message.size = getIntPropertyIfExists(properties, "x0e080003", SCHEMAS_MAPI_PROPTAG);
|
message.size = getIntPropertyIfExists(properties, "x0e080003", SCHEMAS_MAPI_PROPTAG);
|
||||||
message.uid = getPropertyIfExists(properties, "uid", Namespace.getNamespace("DAV:"));
|
message.uid = getPropertyIfExists(properties, "uid", Namespace.getNamespace("DAV:"));
|
||||||
message.imapUid = getLongPropertyIfExists(properties, "x0e230003", SCHEMAS_MAPI_PROPTAG);
|
message.imapUid = getLongPropertyIfExists(properties, "x0e230003", SCHEMAS_MAPI_PROPTAG);
|
||||||
@ -735,9 +736,7 @@ public class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public void updateMessage(Message message, Map<String, String> properties) throws IOException {
|
public void updateMessage(Message message, Map<String, String> properties) throws IOException {
|
||||||
String encodedMessageUrl = message.getEncodedMessageUrl();
|
PropPatchMethod patchMethod = new PropPatchMethod(message.permanentUrl, buildProperties(properties)) {
|
||||||
LOGGER.debug("Updating message at "+encodedMessageUrl);
|
|
||||||
PropPatchMethod patchMethod = new PropPatchMethod(encodedMessageUrl, buildProperties(properties)) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
||||||
// ignore response body, sometimes invalid with exchange mapi properties
|
// ignore response body, sometimes invalid with exchange mapi properties
|
||||||
@ -795,9 +794,9 @@ public class ExchangeSession {
|
|||||||
String folderUrl = getFolderPath(folderName);
|
String folderUrl = getFolderPath(folderName);
|
||||||
MessageList messages = new MessageList();
|
MessageList messages = new MessageList();
|
||||||
StringBuilder searchRequest = new StringBuilder();
|
StringBuilder searchRequest = new StringBuilder();
|
||||||
searchRequest.append("Select ");
|
searchRequest.append("Select \"http://schemas.microsoft.com/exchange/permanenturl\"");
|
||||||
if (attributes != null && attributes.length() > 0) {
|
if (attributes != null && attributes.length() > 0) {
|
||||||
searchRequest.append(attributes);
|
searchRequest.append(',').append(attributes);
|
||||||
}
|
}
|
||||||
searchRequest.append(" FROM Scope('SHALLOW TRAVERSAL OF \"").append(folderUrl).append("\"')\n")
|
searchRequest.append(" FROM Scope('SHALLOW TRAVERSAL OF \"").append(folderUrl).append("\"')\n")
|
||||||
.append(" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n");
|
.append(" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n");
|
||||||
@ -1158,8 +1157,8 @@ public class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public void copyMessage(Message message, String targetFolder) throws IOException {
|
public void copyMessage(Message message, String targetFolder) throws IOException {
|
||||||
String targetPath = URIUtil.encodePath(getFolderPath(targetFolder)) + '/' + message.getEncodedMessageName();
|
String targetPath = URIUtil.encodePath(getFolderPath(targetFolder)) + '/' + UUID.randomUUID().toString();
|
||||||
CopyMethod method = new CopyMethod(message.getEncodedMessageUrl(), targetPath, false);
|
CopyMethod method = new CopyMethod(message.permanentUrl, targetPath, false);
|
||||||
// allow rename if a message with the same name exists
|
// allow rename if a message with the same name exists
|
||||||
method.addRequestHeader("Allow-Rename", "t");
|
method.addRequestHeader("Allow-Rename", "t");
|
||||||
try {
|
try {
|
||||||
@ -1198,17 +1197,9 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void moveToTrash(String encodedMessageUrl) throws IOException {
|
protected void moveToTrash(String encodedMessageUrl) throws IOException {
|
||||||
int index = encodedMessageUrl.lastIndexOf('/');
|
String destination = URIUtil.encodePath(deleteditemsUrl) + '/' + UUID.randomUUID().toString();
|
||||||
if (index < 0) {
|
LOGGER.debug("Deleting : " + encodedMessageUrl + " to " + destination);
|
||||||
throw new DavMailException("EXCEPTION_INVALID_MESSAGE_URL", encodedMessageUrl);
|
MoveMethod method = new MoveMethod(encodedMessageUrl, destination, false);
|
||||||
}
|
|
||||||
String encodedPath = encodedMessageUrl.substring(0, index);
|
|
||||||
String encodedMessageName = encodedMessageUrl.substring(index + 1);
|
|
||||||
|
|
||||||
String source = encodedPath + '/' + encodedMessageName;
|
|
||||||
String destination = URIUtil.encodePath(deleteditemsUrl) + '/' + encodedMessageName;
|
|
||||||
LOGGER.debug("Deleting : " + source + " to " + destination);
|
|
||||||
MoveMethod method = new MoveMethod(source, destination, false);
|
|
||||||
method.addRequestHeader("Allow-rename", "t");
|
method.addRequestHeader("Allow-rename", "t");
|
||||||
|
|
||||||
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method);
|
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method);
|
||||||
@ -1324,6 +1315,8 @@ public class ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
public class Message implements Comparable<Message> {
|
public class Message implements Comparable<Message> {
|
||||||
protected String messageUrl;
|
protected String messageUrl;
|
||||||
|
|
||||||
|
protected String permanentUrl;
|
||||||
/**
|
/**
|
||||||
* Message uid.
|
* Message uid.
|
||||||
*/
|
*/
|
||||||
@ -1458,9 +1451,7 @@ public class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public void write(OutputStream os) throws IOException {
|
public void write(OutputStream os) throws IOException {
|
||||||
String encodedMessageUrl = getEncodedMessageUrl();
|
GetMethod method = new GetMethod(permanentUrl);
|
||||||
LOGGER.debug("Getting message content at "+encodedMessageUrl);
|
|
||||||
GetMethod method = new GetMethod(encodedMessageUrl);
|
|
||||||
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
|
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
|
||||||
method.setRequestHeader("Translate", "f");
|
method.setRequestHeader("Translate", "f");
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
@ -1536,7 +1527,7 @@ public class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public void delete() throws IOException {
|
public void delete() throws IOException {
|
||||||
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, getEncodedMessageUrl());
|
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, permanentUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1550,7 +1541,7 @@ public class ExchangeSession {
|
|||||||
properties.put("read", "1");
|
properties.put("read", "1");
|
||||||
updateMessage(this, properties);
|
updateMessage(this, properties);
|
||||||
|
|
||||||
ExchangeSession.this.moveToTrash(getEncodedMessageUrl());
|
ExchangeSession.this.moveToTrash(permanentUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user