diff --git a/src/java/davmail/exchange/VCalendar.java b/src/java/davmail/exchange/VCalendar.java index 8ffa0e66..56471c7c 100644 --- a/src/java/davmail/exchange/VCalendar.java +++ b/src/java/davmail/exchange/VCalendar.java @@ -464,6 +464,9 @@ public class VCalendar extends VObject { firstVevent.setPropertyValue(propertyName, propertyValue); } + public void addFirstVeventProperty(VProperty vProperty) { + firstVevent.addProperty(vProperty); + } /** * VCalendar recipients for notifications diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java index df83bdce..22931cac 100644 --- a/src/java/davmail/exchange/ews/EWSMethod.java +++ b/src/java/davmail/exchange/ews/EWSMethod.java @@ -412,6 +412,13 @@ public abstract class EWSMethod extends PostMethod { this.serverVersion = serverVersion; } + public static class Attendee { + public String role; + public String email; + public String partstat; + public String name; + } + /** * Item */ @@ -423,6 +430,7 @@ public abstract class EWSMethod extends PostMethod { protected byte[] mimeContent; protected List fieldUpdates; protected List attachments; + protected List attendees; protected List fieldNames = new ArrayList(); @Override @@ -556,6 +564,17 @@ public abstract class EWSMethod extends PostMethod { } return result; } + + public List getAttendees() { + return attendees; + } + + public void addAttendee(Attendee attendee) { + if (attendees == null) { + attendees = new ArrayList(); + } + attendees.add(attendee); + } } /** @@ -679,6 +698,8 @@ public abstract class EWSMethod extends PostMethod { responseItem.attachments = handleAttachments(reader); } else if ("EmailAddresses".equals(tagLocalName)) { handleEmailAddresses(reader, responseItem); + } else if ("RequiredAttendees".equals(tagLocalName) || "OptionalAttendees".equals(tagLocalName)) { + handleAttendees(reader, responseItem, tagLocalName); } else { if (tagLocalName.endsWith("Id")) { value = getAttributeValue(reader, "Id"); @@ -709,6 +730,50 @@ public abstract class EWSMethod extends PostMethod { } } + protected void handleAttendees(XMLStreamReader reader, Item item, String attendeeType) throws XMLStreamException { + while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, attendeeType))) { + reader.next(); + if (XMLStreamUtil.isStartTag(reader)) { + String tagLocalName = reader.getLocalName(); + if ("Attendee".equals(tagLocalName)) { + handleAttendee(reader, item, attendeeType); + } + } + } + } + + protected void handleAttendee(XMLStreamReader reader, Item item, String attendeeType) throws XMLStreamException { + Attendee attendee = new Attendee(); + if ("RequiredAttendees".equals(attendeeType)) { + attendee.role = "REQ-PARTICIPANT"; + } else { + attendee.role = "OPT-PARTICIPANT"; + } + while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Attendee"))) { + reader.next(); + if (XMLStreamUtil.isStartTag(reader)) { + String tagLocalName = reader.getLocalName(); + if ("EmailAddress".equals(tagLocalName)) { + attendee.email = reader.getElementText(); + } else if ("Name".equals(tagLocalName)) { + attendee.name = reader.getElementText(); + } else if ("ResponseType".equals(tagLocalName)) { + String responseType = reader.getElementText(); + if ("Accept".equals(responseType)) { + attendee.partstat = "ACCEPTED"; + } else if ("Tentative".equals(responseType)) { + attendee.partstat = "TENTATIVE"; + } else if ("Decline".equals(responseType)) { + attendee.partstat = "DECLINED"; + } else { + attendee.partstat = "NEEDS-ACTION"; + } + } + } + } + item.addAttendee(attendee); + } + protected List handleAttachments(XMLStreamReader reader) throws XMLStreamException { List attachments = new ArrayList(); while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Attachments"))) { diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 8ca73cda..7c2fae5f 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -23,6 +23,7 @@ import davmail.exception.DavMailException; import davmail.exception.HttpNotFoundException; import davmail.exchange.ExchangeSession; import davmail.exchange.VCalendar; +import davmail.exchange.VProperty; import davmail.http.DavGatewayHttpClientFacade; import davmail.util.IOUtil; import davmail.util.StringUtil; @@ -1181,6 +1182,9 @@ public class EwsExchangeSession extends ExchangeSession { GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true); getItemMethod.addAdditionalProperty(Field.get("reminderset")); getItemMethod.addAdditionalProperty(Field.get("calendaruid")); + getItemMethod.addAdditionalProperty(Field.get("requiredattendees")); + getItemMethod.addAdditionalProperty(Field.get("optionalattendees")); + executeMethod(getItemMethod); content = getItemMethod.getMimeContent(); VCalendar localVCalendar = new VCalendar(content, email, getVTimezone()); @@ -1192,6 +1196,16 @@ public class EwsExchangeSession extends ExchangeSession { if (calendaruid != null) { localVCalendar.setFirstVeventPropertyValue("UID", calendaruid); } + List attendees = getItemMethod.getResponseItem().getAttendees(); + if (attendees != null) { + for (EWSMethod.Attendee attendee : attendees) { + VProperty attendeeProperty = new VProperty("ATTENDEE", "mailto:"+attendee.email); + attendeeProperty.addParam("CN", attendee.name); + attendeeProperty.addParam("PARTSTAT", attendee.partstat); + attendeeProperty.addParam("ROLE", attendee.role); + localVCalendar.addFirstVeventProperty(attendeeProperty); + } + } content = localVCalendar.toString().getBytes("UTF-8"); } catch (IOException e) { diff --git a/src/java/davmail/exchange/ews/Field.java b/src/java/davmail/exchange/ews/Field.java index bd64bdf6..f9065a8e 100644 --- a/src/java/davmail/exchange/ews/Field.java +++ b/src/java/davmail/exchange/ews/Field.java @@ -193,6 +193,9 @@ public class Field { FIELD_MAP.put("busystatus", new UnindexedFieldURI("calendar:LegacyFreeBusyStatus")); + FIELD_MAP.put("requiredattendees", new UnindexedFieldURI("calendar:RequiredAttendees")); + FIELD_MAP.put("optionalattendees", new UnindexedFieldURI("calendar:OptionalAttendees")); + // attachments FIELD_MAP.put("attachments", new UnindexedFieldURI("item:Attachments")); }