mirror of
https://github.com/moparisthebest/davmail
synced 2024-08-13 16:53:51 -04:00
EWS: retrieve and decode MIME content
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1061 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
9d0cd0da4b
commit
b81fa5331a
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package davmail.exchange.ews;
|
package davmail.exchange.ews;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.Header;
|
||||||
import org.apache.commons.httpclient.HttpConnection;
|
import org.apache.commons.httpclient.HttpConnection;
|
||||||
import org.apache.commons.httpclient.HttpState;
|
import org.apache.commons.httpclient.HttpState;
|
||||||
@ -47,12 +48,15 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
protected FolderIdType folderId;
|
protected FolderIdType folderId;
|
||||||
protected FolderIdType parentFolderId;
|
protected FolderIdType parentFolderId;
|
||||||
protected ItemIdType itemId;
|
protected ItemIdType itemId;
|
||||||
protected HashSet<FieldURI> additionalProperties = null;
|
protected HashSet<FieldURI> additionalProperties;
|
||||||
|
|
||||||
protected final String itemType;
|
protected final String itemType;
|
||||||
protected final String methodName;
|
protected final String methodName;
|
||||||
protected final String responseCollectionName;
|
protected final String responseCollectionName;
|
||||||
|
|
||||||
|
protected byte[] mimeContent;
|
||||||
|
protected List<Item> responseItems;
|
||||||
|
protected String errorDetail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build EWS method
|
* Build EWS method
|
||||||
@ -215,13 +219,22 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Item> responseItems;
|
|
||||||
protected String errorDetail;
|
|
||||||
|
|
||||||
public List<Item> getResponseItems() {
|
public List<Item> getResponseItems() {
|
||||||
return responseItems;
|
return responseItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Item getResponseItem() {
|
||||||
|
if (responseItems != null && responseItems.size() == 1) {
|
||||||
|
return responseItems.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getMimeContent() {
|
||||||
|
return mimeContent;
|
||||||
|
}
|
||||||
|
|
||||||
protected String handleTag(XMLStreamReader reader, String localName) throws XMLStreamException {
|
protected String handleTag(XMLStreamReader reader, String localName) throws XMLStreamException {
|
||||||
String result = null;
|
String result = null;
|
||||||
int event = reader.getEventType();
|
int event = reader.getEventType();
|
||||||
@ -270,6 +283,8 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
String value = null;
|
String value = null;
|
||||||
if ("ExtendedProperty".equals(tagLocalName)) {
|
if ("ExtendedProperty".equals(tagLocalName)) {
|
||||||
addExtendedPropertyValue(reader, item);
|
addExtendedPropertyValue(reader, item);
|
||||||
|
} else if (tagLocalName.endsWith("MimeContent")) {
|
||||||
|
handleMimeContent(reader);
|
||||||
} else {
|
} else {
|
||||||
if (tagLocalName.endsWith("Id")) {
|
if (tagLocalName.endsWith("Id")) {
|
||||||
value = getAttributeValue(reader, "Id");
|
value = getAttributeValue(reader, "Id");
|
||||||
@ -286,10 +301,15 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleMimeContent(XMLStreamReader reader) throws XMLStreamException {
|
||||||
|
byte[] base64MimeContent = reader.getElementText().getBytes();
|
||||||
|
mimeContent = Base64.decodeBase64(base64MimeContent);
|
||||||
|
}
|
||||||
|
|
||||||
protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException {
|
protected void addExtendedPropertyValue(XMLStreamReader reader, Item item) throws XMLStreamException {
|
||||||
String propertyTag = null;
|
String propertyTag = null;
|
||||||
String propertyValue = null;
|
String propertyValue = null;
|
||||||
while (reader.hasNext() && !(isEndTag(reader, "ExtendedProperty"))) {
|
while (reader.hasNext() && !(isEndTag(reader, "ExtendedProperty"))) {
|
||||||
reader.next();
|
reader.next();
|
||||||
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
|
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
|
||||||
String tagLocalName = reader.getLocalName();
|
String tagLocalName = reader.getLocalName();
|
||||||
|
@ -22,10 +22,10 @@ package davmail.exchange.ews;
|
|||||||
* Get Item method.
|
* Get Item method.
|
||||||
*/
|
*/
|
||||||
public class GetItemMethod extends EWSMethod {
|
public class GetItemMethod extends EWSMethod {
|
||||||
public GetItemMethod(BaseShapeType baseShape, FolderIdType folderId, boolean includeMimeContent) {
|
public GetItemMethod(BaseShapeType baseShape, ItemIdType itemId, boolean includeMimeContent) {
|
||||||
super("Item", "GetItem");
|
super("Item", "GetItem");
|
||||||
this.baseShape = baseShape;
|
this.baseShape = baseShape;
|
||||||
this.folderId = folderId;
|
this.itemId = itemId;
|
||||||
this.includeMimeContent = includeMimeContent;
|
this.includeMimeContent = includeMimeContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user