EWS: various flag handling fixes, implement message delete
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1127 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
fd419ae661
commit
72dff67421
|
@ -1069,7 +1069,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
message.read = "1".equals(getPropertyIfExists(properties, "read"));
|
||||
message.junk = "1".equals(getPropertyIfExists(properties, "junk"));
|
||||
message.flagged = "2".equals(getPropertyIfExists(properties, "flagStatus"));
|
||||
message.draft = "9".equals(getPropertyIfExists(properties, "messageFlags"));
|
||||
message.draft = "9".equals(getPropertyIfExists(properties, "messageFlags")) || "8".equals(getPropertyIfExists(properties, "messageFlags"));
|
||||
String lastVerbExecuted = getPropertyIfExists(properties, "lastVerbExecuted");
|
||||
message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
|
||||
message.forwarded = "104".equals(lastVerbExecuted);
|
||||
|
@ -1424,9 +1424,14 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
public void createMessage(String folderPath, String messageName, HashMap<String, String> properties, String messageBody) throws IOException {
|
||||
String messageUrl = URIUtil.encodePathQuery(getFolderPath(folderPath) + '/' + messageName + ".EML");
|
||||
PropPatchMethod patchMethod;
|
||||
List<DavConstants> davProperties = buildProperties(properties);
|
||||
if (!properties.containsKey("read")) {
|
||||
// force unread
|
||||
davProperties.add(Field.createDavProperty("read", "0"));
|
||||
}
|
||||
// create the message first as draft
|
||||
if (properties.containsKey("draft")) {
|
||||
patchMethod = new PropPatchMethod(messageUrl, buildProperties(properties));
|
||||
patchMethod = new PropPatchMethod(messageUrl, davProperties);
|
||||
try {
|
||||
// update message with blind carbon copy and other flags
|
||||
int statusCode = httpClient.executeMethod(patchMethod);
|
||||
|
@ -1454,8 +1459,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
}
|
||||
|
||||
// add bcc and other properties
|
||||
if (!properties.isEmpty()) {
|
||||
patchMethod = new PropPatchMethod(messageUrl, buildProperties(properties));
|
||||
if (!davProperties.isEmpty()) {
|
||||
patchMethod = new PropPatchMethod(messageUrl, davProperties);
|
||||
try {
|
||||
// update message with blind carbon copy and other flags
|
||||
int statusCode = httpClient.executeMethod(patchMethod);
|
||||
|
@ -1539,10 +1544,15 @@ public class DavExchangeSession extends ExchangeSession {
|
|||
try {
|
||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(baos);
|
||||
String line;
|
||||
boolean first = true;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
outputStreamWriter.write((char) 13);
|
||||
outputStreamWriter.write((char) 10);
|
||||
}
|
||||
outputStreamWriter.write(line);
|
||||
outputStreamWriter.write((char) 13);
|
||||
outputStreamWriter.write((char) 10);
|
||||
}
|
||||
outputStreamWriter.flush();
|
||||
} finally {
|
||||
|
|
|
@ -22,9 +22,10 @@ package davmail.exchange.ews;
|
|||
* Create Item method.
|
||||
*/
|
||||
public class CreateItemMethod extends EWSMethod {
|
||||
public CreateItemMethod(FolderId savedItemFolderId, EWSMethod.Item item) {
|
||||
public CreateItemMethod(MessageDisposition messageDisposition, FolderId savedItemFolderId, EWSMethod.Item item) {
|
||||
super("Item", "CreateItem");
|
||||
this.savedItemFolderId = savedItemFolderId;
|
||||
this.item = item;
|
||||
addMethodOption(messageDisposition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ package davmail.exchange.ews;
|
|||
* Delete Item method.
|
||||
*/
|
||||
public class DeleteItemMethod extends EWSMethod {
|
||||
public DeleteItemMethod(FolderId folderId, ItemId itemId) {
|
||||
public DeleteItemMethod(ItemId itemId, DeleteType deleteType) {
|
||||
super("Item", "DeleteItem");
|
||||
this.folderId = folderId;
|
||||
addMethodOption(deleteType);
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||
* Copyright (C) 2010 Mickael Guessant
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package davmail.exchange.ews;
|
||||
|
||||
/**
|
||||
* DeleteItem disposal type.
|
||||
*/
|
||||
public class DeleteType extends AttributeOption {
|
||||
private DeleteType(String value) {
|
||||
super("DeleteType", value);
|
||||
}
|
||||
|
||||
public static final DeleteType HardDelete = new DeleteType("HardDelete");
|
||||
public static final DeleteType SoftDelete = new DeleteType("SoftDelete");
|
||||
public static final DeleteType MoveToDeletedItems = new DeleteType("MoveToDeletedItems");
|
||||
}
|
|
@ -49,8 +49,7 @@ public abstract class EWSMethod extends PostMethod {
|
|||
protected ItemId itemId;
|
||||
protected Set<FieldURI> additionalProperties;
|
||||
protected Disposal deleteType;
|
||||
protected MessageDisposition messageDisposition;
|
||||
protected ConflictResolution conflictResolution;
|
||||
protected Set<AttributeOption> methodOptions;
|
||||
|
||||
protected Set<FieldUpdate> updates;
|
||||
|
||||
|
@ -113,6 +112,13 @@ public abstract class EWSMethod extends PostMethod {
|
|||
additionalProperties.add(additionalProperty);
|
||||
}
|
||||
|
||||
protected void addMethodOption(AttributeOption attributeOption) {
|
||||
if (methodOptions == null) {
|
||||
methodOptions = new HashSet<AttributeOption>();
|
||||
}
|
||||
methodOptions.add(attributeOption);
|
||||
}
|
||||
|
||||
protected void setSearchExpression(SearchExpression searchExpression) {
|
||||
this.searchExpression = searchExpression;
|
||||
}
|
||||
|
@ -271,11 +277,10 @@ public abstract class EWSMethod extends PostMethod {
|
|||
if (deleteType != null) {
|
||||
deleteType.write(writer);
|
||||
}
|
||||
if (messageDisposition != null) {
|
||||
messageDisposition.write(writer);
|
||||
}
|
||||
if (conflictResolution != null) {
|
||||
conflictResolution.write(writer);
|
||||
if (methodOptions != null) {
|
||||
for (AttributeOption attributeOption : methodOptions) {
|
||||
attributeOption.write(writer);
|
||||
}
|
||||
}
|
||||
writer.write(">");
|
||||
writeSoapBody(writer);
|
||||
|
|
|
@ -18,21 +18,16 @@
|
|||
*/
|
||||
package davmail.exchange.ews;
|
||||
|
||||
import davmail.Settings;
|
||||
import davmail.exception.DavMailAuthenticationException;
|
||||
import davmail.exception.DavMailException;
|
||||
import davmail.exception.HttpNotFoundException;
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.http.DavGatewayHttpClientFacade;
|
||||
import davmail.util.StringUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.HeadMethod;
|
||||
import org.apache.commons.httpclient.util.URIUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -41,7 +36,6 @@ import java.io.InputStreamReader;
|
|||
import java.net.NoRouteToHostException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* EWS Exchange adapter.
|
||||
|
@ -170,26 +164,28 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||
Set<FieldUpdate> fieldUpdates = buildProperties(properties);
|
||||
if (!properties.containsKey("draft")) {
|
||||
// need to force draft flag to false
|
||||
fieldUpdates.add(Field.createFieldUpdate("messageFlags", "0"));
|
||||
if (properties.containsKey("read")) {
|
||||
fieldUpdates.add(Field.createFieldUpdate("messageFlags", "1"));
|
||||
} else {
|
||||
fieldUpdates.add(Field.createFieldUpdate("messageFlags", "0"));
|
||||
}
|
||||
}
|
||||
item.setFieldUpdates(fieldUpdates);
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(getFolderId(folderPath), item);
|
||||
createItemMethod.messageDisposition = MessageDisposition.SaveOnly;
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, getFolderId(folderPath), item);
|
||||
executeMethod(createItemMethod);
|
||||
// TODO: do we need to update message after to force some properties ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMessage(ExchangeSession.Message message, Map<String, String> properties) throws IOException {
|
||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(ConflictResolution.AlwaysOverwrite, ((EwsExchangeSession.Message) message).itemId, buildProperties(properties));
|
||||
updateItemMethod.messageDisposition = MessageDisposition.SaveOnly;
|
||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly, ConflictResolution.AlwaysOverwrite, ((EwsExchangeSession.Message) message).itemId, buildProperties(properties));
|
||||
executeMethod(updateItemMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(ExchangeSession.Message message) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
DeleteItemMethod deleteItemMethod = new DeleteItemMethod(((EwsExchangeSession.Message) message).itemId, DeleteType.HardDelete);
|
||||
executeMethod(deleteItemMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -229,7 +225,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||
message.read = response.getBoolean(Field.get("read").getResponseName());
|
||||
message.junk = response.getBoolean(Field.get("junk").getResponseName());
|
||||
message.flagged = "2".equals(response.get(Field.get("flagStatus").getResponseName()));
|
||||
message.draft = "9".equals(response.get(Field.get("messageFlags").getResponseName()));
|
||||
message.draft = "9".equals(response.get(Field.get("messageFlags").getResponseName())) || "8".equals(response.get(Field.get("messageFlags").getResponseName()));
|
||||
String lastVerbExecuted = response.get(Field.get("lastVerbExecuted").getResponseName());
|
||||
message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
|
||||
message.forwarded = "104".equals(lastVerbExecuted);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Field {
|
|||
FIELD_MAP.put("flagStatus", new ExtendedFieldURI(0x1090, ExtendedFieldURI.PropertyType.Integer));
|
||||
FIELD_MAP.put("lastVerbExecuted", new ExtendedFieldURI(0x1081, ExtendedFieldURI.PropertyType.Integer));
|
||||
FIELD_MAP.put("read", new ExtendedFieldURI(0x0e69, ExtendedFieldURI.PropertyType.Boolean));
|
||||
FIELD_MAP.put("messageSize", new ExtendedFieldURI(0x0e08, ExtendedFieldURI.PropertyType.Long));
|
||||
FIELD_MAP.put("messageSize", new ExtendedFieldURI(0x0e08, ExtendedFieldURI.PropertyType.Integer));
|
||||
FIELD_MAP.put("date", new ExtendedFieldURI(0x0e06, ExtendedFieldURI.PropertyType.SystemTime));
|
||||
FIELD_MAP.put("deleted", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Common, 0x8570, ExtendedFieldURI.PropertyType.String));
|
||||
FIELD_MAP.put("junk", new ExtendedFieldURI(0x1083, ExtendedFieldURI.PropertyType.Long));
|
||||
|
|
|
@ -24,10 +24,11 @@ import java.util.Set;
|
|||
* Uµpdate Item method.
|
||||
*/
|
||||
public class UpdateItemMethod extends EWSMethod {
|
||||
public UpdateItemMethod(ConflictResolution conflictResolution, ItemId itemId, Set<FieldUpdate> updates) {
|
||||
public UpdateItemMethod(MessageDisposition messageDisposition, ConflictResolution conflictResolution, ItemId itemId, Set<FieldUpdate> updates) {
|
||||
super("Item", "UpdateItem");
|
||||
this.itemId = itemId;
|
||||
this.updates = updates;
|
||||
this.conflictResolution = conflictResolution;
|
||||
addMethodOption(messageDisposition);
|
||||
addMethodOption(conflictResolution);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue