mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-13 06:28:19 -05:00
EWS: implement create and update message
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1124 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
c3430975c4
commit
d80f60a44b
@ -1399,6 +1399,7 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
} else if ("bcc".equals(entry.getKey())) {
|
||||
list.add(Field.createDavProperty("bcc", entry.getValue()));
|
||||
} else if ("draft".equals(entry.getKey())) {
|
||||
// note: draft is readonly after create
|
||||
list.add(Field.createDavProperty("messageFlags", entry.getValue()));
|
||||
} else if ("deleted".equals(entry.getKey())) {
|
||||
list.add(Field.createDavProperty("writedeleted", entry.getValue()));
|
||||
|
32
src/java/davmail/exchange/ews/ConflictResolution.java
Normal file
32
src/java/davmail/exchange/ews/ConflictResolution.java
Normal file
@ -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;
|
||||
|
||||
/**
|
||||
* Item update conflict resolution
|
||||
*/
|
||||
public class ConflictResolution extends AttributeOption {
|
||||
private ConflictResolution(String value) {
|
||||
super("ConflictResolution", value);
|
||||
}
|
||||
|
||||
public static final ConflictResolution NeverOverwrite = new ConflictResolution("NeverOverwrite");
|
||||
public static final ConflictResolution AutoResolve = new ConflictResolution("AutoResolve");
|
||||
public static final ConflictResolution AlwaysOverwrite = new ConflictResolution("AlwaysOverwrite");
|
||||
}
|
@ -22,9 +22,9 @@ package davmail.exchange.ews;
|
||||
* Create Item method.
|
||||
*/
|
||||
public class CreateItemMethod extends EWSMethod {
|
||||
public CreateItemMethod(FolderId parentFolderId, EWSMethod.Item item) {
|
||||
super("Folder", "CreateFolder");
|
||||
this.parentFolderId = parentFolderId;
|
||||
public CreateItemMethod(FolderId savedItemFolderId, EWSMethod.Item item) {
|
||||
super("Item", "CreateItem");
|
||||
this.savedItemFolderId = savedItemFolderId;
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package davmail.exchange.ews;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HttpConnection;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.HttpState;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||
@ -44,11 +43,14 @@ public abstract class EWSMethod extends PostMethod {
|
||||
protected BaseShape baseShape;
|
||||
protected boolean includeMimeContent;
|
||||
protected FolderId folderId;
|
||||
protected FolderId savedItemFolderId;
|
||||
protected FolderId toFolderId;
|
||||
protected FolderId parentFolderId;
|
||||
protected ItemId itemId;
|
||||
protected Set<FieldURI> additionalProperties;
|
||||
protected Disposal deleteType;
|
||||
protected MessageDisposition messageDisposition;
|
||||
protected ConflictResolution conflictResolution;
|
||||
|
||||
protected Set<FieldUpdate> updates;
|
||||
|
||||
@ -56,7 +58,6 @@ public abstract class EWSMethod extends PostMethod {
|
||||
protected final String methodName;
|
||||
protected final String responseCollectionName;
|
||||
|
||||
protected byte[] mimeContent;
|
||||
protected List<Item> responseItems;
|
||||
protected String errorDetail;
|
||||
protected Item item;
|
||||
@ -105,18 +106,6 @@ public abstract class EWSMethod extends PostMethod {
|
||||
return "POST";
|
||||
}
|
||||
|
||||
protected void setBaseShape(BaseShape baseShape) {
|
||||
this.baseShape = baseShape;
|
||||
}
|
||||
|
||||
protected void setFolderId(FolderId folderId) {
|
||||
this.folderId = folderId;
|
||||
}
|
||||
|
||||
protected void setParentFolderId(FolderId folderId) {
|
||||
this.parentFolderId = folderId;
|
||||
}
|
||||
|
||||
protected void addAdditionalProperty(FieldURI additionalProperty) {
|
||||
if (additionalProperties == null) {
|
||||
additionalProperties = new HashSet<FieldURI>();
|
||||
@ -124,10 +113,6 @@ public abstract class EWSMethod extends PostMethod {
|
||||
additionalProperties.add(additionalProperty);
|
||||
}
|
||||
|
||||
protected void setAdditionalProperties(Set<FieldURI> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
protected void setSearchExpression(SearchExpression searchExpression) {
|
||||
this.searchExpression = searchExpression;
|
||||
}
|
||||
@ -158,9 +143,13 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
protected void writeItemId(Writer writer) throws IOException {
|
||||
if (itemId != null) {
|
||||
writer.write("<m:ItemIds>");
|
||||
if (updates == null) {
|
||||
writer.write("<m:ItemIds>");
|
||||
}
|
||||
itemId.write(writer);
|
||||
writer.write("</m:ItemIds>");
|
||||
if (updates == null) {
|
||||
writer.write("</m:ItemIds>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,6 +165,14 @@ public abstract class EWSMethod extends PostMethod {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeSavedItemFolderId(Writer writer) throws IOException {
|
||||
if (savedItemFolderId != null) {
|
||||
writer.write("<m:SavedItemFolderId>");
|
||||
savedItemFolderId.write(writer);
|
||||
writer.write("</m:SavedItemFolderId>");
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeToFolderId(Writer writer) throws IOException {
|
||||
if (toFolderId != null) {
|
||||
writer.write("<m:ToFolderId>");
|
||||
@ -237,15 +234,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
if (updates != null) {
|
||||
writer.write("<t:Updates>");
|
||||
for (FieldUpdate fieldUpdate : updates) {
|
||||
writer.write("<t:Set");
|
||||
writer.write(itemType);
|
||||
writer.write("Field>");
|
||||
|
||||
fieldUpdate.write(itemType, writer);
|
||||
|
||||
writer.write("</t:Set");
|
||||
writer.write(itemType);
|
||||
writer.write("Field>");
|
||||
}
|
||||
writer.write("</t:Updates>");
|
||||
}
|
||||
@ -282,6 +271,12 @@ public abstract class EWSMethod extends PostMethod {
|
||||
if (deleteType != null) {
|
||||
deleteType.write(writer);
|
||||
}
|
||||
if (messageDisposition != null) {
|
||||
messageDisposition.write(writer);
|
||||
}
|
||||
if (conflictResolution != null) {
|
||||
conflictResolution.write(writer);
|
||||
}
|
||||
writer.write(">");
|
||||
writeSoapBody(writer);
|
||||
writer.write("</m:");
|
||||
@ -304,6 +299,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
writeParentFolderId(writer);
|
||||
writeToFolderId(writer);
|
||||
writeFolderId(writer);
|
||||
writeSavedItemFolderId(writer);
|
||||
writeItem(writer);
|
||||
writeUpdates(writer);
|
||||
endChanges(writer);
|
||||
@ -323,6 +319,8 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
public static class Item extends HashMap<String, String> {
|
||||
public String type;
|
||||
protected byte[] mimeContent;
|
||||
protected Set<FieldUpdate> fieldUpdates;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -348,11 +346,25 @@ public abstract class EWSMethod extends PostMethod {
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(">");
|
||||
}
|
||||
if (mimeContent != null) {
|
||||
writer.write("<t:MimeContent>");
|
||||
writer.write(new String(mimeContent));
|
||||
writer.write("</t:MimeContent>");
|
||||
}
|
||||
if (fieldUpdates != null) {
|
||||
for (FieldUpdate fieldUpdate : fieldUpdates) {
|
||||
fieldUpdate.write(null, writer);
|
||||
}
|
||||
}
|
||||
writer.write("</t:");
|
||||
writer.write(type);
|
||||
writer.write(">");
|
||||
}
|
||||
|
||||
public void setFieldUpdates(Set<FieldUpdate> fieldUpdates) {
|
||||
this.fieldUpdates = fieldUpdates;
|
||||
}
|
||||
|
||||
public int getInt(String key) {
|
||||
int result = 0;
|
||||
String value = get(key);
|
||||
@ -385,7 +397,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
public void checkSuccess() throws EWSException {
|
||||
if (errorDetail != null) {
|
||||
throw new EWSException(errorDetail);
|
||||
throw new EWSException(errorDetail + "\n request: " + new String(generateSoapEnvelope()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,7 +417,12 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
public byte[] getMimeContent() throws EWSException {
|
||||
checkSuccess();
|
||||
return mimeContent;
|
||||
Item responseItem = getResponseItem();
|
||||
if (responseItem != null) {
|
||||
return responseItem.mimeContent;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String handleTag(XMLStreamReader reader, String localName) throws XMLStreamException {
|
||||
@ -446,38 +463,38 @@ public abstract class EWSMethod extends PostMethod {
|
||||
}
|
||||
|
||||
protected Item handleItem(XMLStreamReader reader) throws XMLStreamException {
|
||||
Item item = new Item();
|
||||
item.type = reader.getLocalName();
|
||||
while (reader.hasNext() && !isEndTag(reader, item.type)) {
|
||||
Item responseItem = new Item();
|
||||
responseItem.type = reader.getLocalName();
|
||||
while (reader.hasNext() && !isEndTag(reader, responseItem.type)) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String tagLocalName = reader.getLocalName();
|
||||
String value = null;
|
||||
if ("ExtendedProperty".equals(tagLocalName)) {
|
||||
addExtendedPropertyValue(reader, item);
|
||||
addExtendedPropertyValue(reader, responseItem);
|
||||
} else if (tagLocalName.endsWith("MimeContent")) {
|
||||
handleMimeContent(reader);
|
||||
handleMimeContent(reader, responseItem);
|
||||
} else {
|
||||
if (tagLocalName.endsWith("Id")) {
|
||||
value = getAttributeValue(reader, "Id");
|
||||
// get change key
|
||||
item.put("ChangeKey", getAttributeValue(reader, "ChangeKey"));
|
||||
responseItem.put("ChangeKey", getAttributeValue(reader, "ChangeKey"));
|
||||
}
|
||||
if (value == null) {
|
||||
value = getTagContent(reader);
|
||||
}
|
||||
if (value != null) {
|
||||
item.put(tagLocalName, value);
|
||||
responseItem.put(tagLocalName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return item;
|
||||
return responseItem;
|
||||
}
|
||||
|
||||
protected void handleMimeContent(XMLStreamReader reader) throws XMLStreamException {
|
||||
protected void handleMimeContent(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
|
||||
byte[] base64MimeContent = reader.getElementText().getBytes();
|
||||
mimeContent = Base64.decodeBase64(base64MimeContent);
|
||||
responseItem.mimeContent = Base64.decodeBase64(base64MimeContent);
|
||||
}
|
||||
|
||||
protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException {
|
||||
|
@ -23,6 +23,7 @@ import davmail.exception.DavMailException;
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.http.DavGatewayHttpClientFacade;
|
||||
import davmail.util.StringUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
@ -40,23 +41,6 @@ import java.util.*;
|
||||
*/
|
||||
public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
protected static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>();
|
||||
|
||||
static {
|
||||
FIELD_MAP.put("uid", new ExtendedFieldURI(0x300b, ExtendedFieldURI.PropertyType.Binary));
|
||||
FIELD_MAP.put("messageFlags", new ExtendedFieldURI(0x0e07, ExtendedFieldURI.PropertyType.Integer));
|
||||
FIELD_MAP.put("imapUid", new ExtendedFieldURI(0x0e23, ExtendedFieldURI.PropertyType.Integer));
|
||||
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("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));
|
||||
|
||||
FIELD_MAP.put("folderclass", new ExtendedFieldURI(0x3613, ExtendedFieldURI.PropertyType.String));
|
||||
}
|
||||
|
||||
protected Map<String, String> folderIdMap;
|
||||
|
||||
protected class Folder extends ExchangeSession.Folder {
|
||||
@ -126,20 +110,76 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
}
|
||||
|
||||
class Message extends ExchangeSession.Message {
|
||||
// message item id
|
||||
ItemId itemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message create/update properties
|
||||
*
|
||||
* @param properties flag values map
|
||||
* @return field values
|
||||
*/
|
||||
protected Set<FieldUpdate> buildProperties(Map<String, String> properties) {
|
||||
HashSet<FieldUpdate> list = new HashSet<FieldUpdate>();
|
||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||
if ("read".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("read", entry.getValue()));
|
||||
} else if ("junk".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("junk", entry.getValue()));
|
||||
} else if ("flagged".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("flagStatus", entry.getValue()));
|
||||
} else if ("answered".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("lastVerbExecuted", entry.getValue()));
|
||||
if ("102".equals(entry.getValue())) {
|
||||
list.add(Field.createFieldUpdate("iconIndex", "261"));
|
||||
}
|
||||
} else if ("forwarded".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("lastVerbExecuted", entry.getValue()));
|
||||
if ("104".equals(entry.getValue())) {
|
||||
list.add(Field.createFieldUpdate("iconIndex", "262"));
|
||||
}
|
||||
} else if ("bcc".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("bcc", entry.getValue()));
|
||||
} else if ("draft".equals(entry.getKey())) {
|
||||
// note: draft is readonly after create
|
||||
list.add(Field.createFieldUpdate("messageFlags", entry.getValue()));
|
||||
} else if ("deleted".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("deleted", entry.getValue()));
|
||||
} else if ("datereceived".equals(entry.getKey())) {
|
||||
list.add(Field.createFieldUpdate("datereceived", entry.getValue()));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createMessage(String folderPath, String messageName, HashMap<String, String> properties, String messageBody) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
EWSMethod.Item item = new EWSMethod.Item();
|
||||
item.type = "Message";
|
||||
item.mimeContent = Base64.encodeBase64(messageBody.getBytes());
|
||||
Set<FieldUpdate> fieldUpdates = buildProperties(properties);
|
||||
if (!properties.containsKey("draft")) {
|
||||
// need to force draft flag to false
|
||||
fieldUpdates.add(Field.createFieldUpdate("messageFlags", "0"));
|
||||
}
|
||||
item.setFieldUpdates(fieldUpdates);
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(getFolderId(folderPath), item);
|
||||
createItemMethod.messageDisposition = MessageDisposition.SaveOnly;
|
||||
executeMethod(createItemMethod);
|
||||
// TODO: do we need to update message after to force some properties ?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMessage(Message message, Map<String, String> properties) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
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;
|
||||
executeMethod(updateItemMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(Message message) throws IOException {
|
||||
public void deleteMessage(ExchangeSession.Message message) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
@ -151,25 +191,28 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BufferedReader getContentReader(Message message) throws IOException {
|
||||
protected BufferedReader getContentReader(ExchangeSession.Message message) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected Message buildMessage(EWSMethod.Item response) throws URIException {
|
||||
Message message = new Message();
|
||||
|
||||
message.size = response.getInt(FIELD_MAP.get("messageSize").getResponseName());
|
||||
message.uid = response.get(FIELD_MAP.get("uid").getResponseName());
|
||||
message.imapUid = response.getLong(FIELD_MAP.get("imapUid").getResponseName());
|
||||
message.read = response.getBoolean(FIELD_MAP.get("read").getResponseName());
|
||||
message.junk = response.getBoolean(FIELD_MAP.get("junk").getResponseName());
|
||||
message.flagged = "2".equals(response.get(FIELD_MAP.get("flagStatus").getResponseName()));
|
||||
message.draft = "9".equals(response.get(FIELD_MAP.get("messageFlags").getResponseName()));
|
||||
String lastVerbExecuted = response.get(FIELD_MAP.get("lastVerbExecuted").getResponseName());
|
||||
// get item id
|
||||
message.itemId = new ItemId(response.get("ItemId"), response.get("ChangeKey"));
|
||||
|
||||
message.size = response.getInt(Field.get("messageSize").getResponseName());
|
||||
message.uid = response.get(Field.get("uid").getResponseName());
|
||||
message.imapUid = response.getLong(Field.get("imapUid").getResponseName());
|
||||
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()));
|
||||
String lastVerbExecuted = response.get(Field.get("lastVerbExecuted").getResponseName());
|
||||
message.answered = "102".equals(lastVerbExecuted) || "103".equals(lastVerbExecuted);
|
||||
message.forwarded = "104".equals(lastVerbExecuted);
|
||||
message.date = response.get(FIELD_MAP.get("date").getResponseName());
|
||||
message.deleted = "1".equals(response.get(FIELD_MAP.get("deleted").getResponseName()));
|
||||
message.date = response.get(Field.get("date").getResponseName());
|
||||
message.deleted = "1".equals(response.get(Field.get("deleted").getResponseName()));
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
@ -180,6 +223,8 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
if (message.uid != null) {
|
||||
buffer.append(" uid: ").append(message.uid);
|
||||
}
|
||||
buffer.append(" ItemId: ").append(message.itemId.id);
|
||||
buffer.append(" ChangeKey: ").append(message.itemId.changeKey);
|
||||
LOGGER.debug(buffer.toString());
|
||||
}
|
||||
return message;
|
||||
@ -200,9 +245,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
|
||||
protected List<EWSMethod.Item> searchItems(String folderPath, Set<String> attributes, Condition condition, FolderQueryTraversal folderQueryTraversal) throws IOException {
|
||||
FindItemMethod findItemMethod = new FindItemMethod(FolderQueryTraversal.SHALLOW, BaseShape.ID_ONLY, getFolderId(folderPath));
|
||||
FindItemMethod findItemMethod = new FindItemMethod(folderQueryTraversal, BaseShape.ID_ONLY, getFolderId(folderPath));
|
||||
for (String attribute : attributes) {
|
||||
findItemMethod.addAdditionalProperty(FIELD_MAP.get(attribute));
|
||||
findItemMethod.addAdditionalProperty(Field.get(attribute));
|
||||
}
|
||||
if (condition != null && !condition.isEmpty()) {
|
||||
findItemMethod.setSearchExpression((SearchExpression) condition);
|
||||
@ -268,7 +313,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
|
||||
protected FieldURI getFieldURI(String attributeName) {
|
||||
FieldURI fieldURI = FIELD_MAP.get(attributeName);
|
||||
FieldURI fieldURI = Field.get(attributeName);
|
||||
if (fieldURI == null) {
|
||||
throw new IllegalArgumentException("Unknown field: " + attributeName);
|
||||
}
|
||||
@ -316,7 +361,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
public void appendTo(StringBuilder buffer) {
|
||||
buffer.append("<t:Not><t:Exists>");
|
||||
FIELD_MAP.get(attributeName).appendTo(buffer);
|
||||
Field.get(attributeName).appendTo(buffer);
|
||||
buffer.append("</t:Exists></t:Not>");
|
||||
}
|
||||
|
||||
@ -511,7 +556,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
* @inheritDoc
|
||||
*/
|
||||
@Override
|
||||
public void copyMessage(Message message, String targetFolder) throws IOException {
|
||||
public void copyMessage(ExchangeSession.Message message, String targetFolder) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -543,7 +588,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
* @inheritDoc
|
||||
*/
|
||||
@Override
|
||||
protected void moveToTrash(Message message) throws IOException {
|
||||
protected void moveToTrash(ExchangeSession.Message message) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -86,19 +86,23 @@ public class ExtendedFieldURI implements FieldURI {
|
||||
}
|
||||
|
||||
public void appendValue(StringBuilder buffer, String itemType, String value) {
|
||||
appendTo(buffer);
|
||||
buffer.append("<t:");
|
||||
buffer.append(itemType);
|
||||
buffer.append('>');
|
||||
if (itemType != null) {
|
||||
appendTo(buffer);
|
||||
buffer.append("<t:");
|
||||
buffer.append(itemType);
|
||||
buffer.append('>');
|
||||
}
|
||||
buffer.append("<t:ExtendedProperty>");
|
||||
appendTo(buffer);
|
||||
buffer.append("<t:Value>");
|
||||
buffer.append(value);
|
||||
buffer.append("</t:Value>");
|
||||
buffer.append("</t:ExtendedProperty>");
|
||||
buffer.append("</t:");
|
||||
buffer.append(itemType);
|
||||
buffer.append('>');
|
||||
if (itemType != null) {
|
||||
buffer.append("</t:");
|
||||
buffer.append(itemType);
|
||||
buffer.append('>');
|
||||
}
|
||||
}
|
||||
|
||||
public String getResponseName() {
|
||||
|
84
src/java/davmail/exchange/ews/Field.java
Normal file
84
src/java/davmail/exchange/ews/Field.java
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* EWS MAPI fields;
|
||||
*/
|
||||
public class Field {
|
||||
protected static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>();
|
||||
|
||||
static {
|
||||
FIELD_MAP.put("uid", new ExtendedFieldURI(0x300b, ExtendedFieldURI.PropertyType.Binary));
|
||||
FIELD_MAP.put("messageFlags", new ExtendedFieldURI(0x0e07, ExtendedFieldURI.PropertyType.Integer));//PR_MESSAGE_FLAGS
|
||||
FIELD_MAP.put("imapUid", new ExtendedFieldURI(0x0e23, ExtendedFieldURI.PropertyType.Integer));
|
||||
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("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));
|
||||
|
||||
FIELD_MAP.put("iconIndex", new ExtendedFieldURI(0x1080, ExtendedFieldURI.PropertyType.Long));// PR_ICON_INDEX
|
||||
FIELD_MAP.put("datereceived", new ExtendedFieldURI(0x0e06, ExtendedFieldURI.PropertyType.SystemTime));// PR_MESSAGE_DELIVERY_TIME
|
||||
FIELD_MAP.put("bcc", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.InternetHeaders, "bcc"));
|
||||
|
||||
FIELD_MAP.put("folderclass", new ExtendedFieldURI(0x3613, ExtendedFieldURI.PropertyType.String));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Field by alias.
|
||||
*
|
||||
* @param alias field alias
|
||||
* @return field
|
||||
*/
|
||||
public static FieldURI get(String alias) {
|
||||
FieldURI field = FIELD_MAP.get(alias);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Unknown field: " + alias);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Mime header field.
|
||||
*
|
||||
* @param headerName header name
|
||||
* @return field object
|
||||
*/
|
||||
public static FieldURI getHeader(String headerName) {
|
||||
return new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.InternetHeaders, headerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create property update field
|
||||
*
|
||||
* @param alias property alias
|
||||
* @param value property value
|
||||
* @return field update
|
||||
*/
|
||||
public static FieldUpdate createFieldUpdate(String alias, String value) {
|
||||
return new FieldUpdate(Field.get(alias), value);
|
||||
}
|
||||
|
||||
}
|
@ -34,8 +34,32 @@ public class FieldUpdate {
|
||||
}
|
||||
|
||||
public void write(String itemType, Writer writer) throws IOException {
|
||||
String action;
|
||||
if (value == null) {
|
||||
action = "Delete";
|
||||
} else {
|
||||
action = "Set";
|
||||
}
|
||||
if (itemType != null) {
|
||||
writer.write("<t:");
|
||||
writer.write(action);
|
||||
writer.write(itemType);
|
||||
writer.write("Field>");
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
fieldURI.appendValue(buffer, itemType, value);
|
||||
if (value == null) {
|
||||
fieldURI.appendTo(buffer);
|
||||
} else {
|
||||
fieldURI.appendValue(buffer, itemType, value);
|
||||
}
|
||||
writer.write(buffer.toString());
|
||||
|
||||
if (itemType != null) {
|
||||
writer.write("</t:");
|
||||
writer.write(action);
|
||||
writer.write(itemType);
|
||||
writer.write("Field>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package davmail.exchange.ews;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Create Folder method.
|
||||
* Update Folder method.
|
||||
*/
|
||||
public class UpdateFolderMethod extends EWSMethod {
|
||||
public UpdateFolderMethod(FolderId folderId, Set<FieldUpdate> updates) {
|
||||
|
33
src/java/davmail/exchange/ews/UpdateItemMethod.java
Normal file
33
src/java/davmail/exchange/ews/UpdateItemMethod.java
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Uµpdate Item method.
|
||||
*/
|
||||
public class UpdateItemMethod extends EWSMethod {
|
||||
public UpdateItemMethod(ConflictResolution conflictResolution, ItemId itemId, Set<FieldUpdate> updates) {
|
||||
super("Item", "UpdateItem");
|
||||
this.itemId = itemId;
|
||||
this.updates = updates;
|
||||
this.conflictResolution = conflictResolution;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user