From 5b2a34fd38d235fdb36538777e75162c48fc3a81 Mon Sep 17 00:00:00 2001 From: mguessan Date: Thu, 30 Aug 2012 22:40:28 +0000 Subject: [PATCH] Caldav: fix attendees in modified occurences git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2011 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/VCalendar.java | 8 ++++ src/java/davmail/exchange/ews/EWSMethod.java | 12 ++++- .../exchange/ews/EwsExchangeSession.java | 44 ++++++++++++------- src/java/davmail/exchange/ews/ItemId.java | 11 +++++ 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/src/java/davmail/exchange/VCalendar.java b/src/java/davmail/exchange/VCalendar.java index cc2d8e22..c61f06b9 100644 --- a/src/java/davmail/exchange/VCalendar.java +++ b/src/java/davmail/exchange/VCalendar.java @@ -720,6 +720,14 @@ public class VCalendar extends VObject { return status; } + /** + * Get first VEvent + * @return first VEvent + */ + public VObject getFirstVevent() { + return firstVevent; + } + /** * Get recurring VCalendar occurence exceptions. * diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java index f28a0e76..c35bd7c0 100644 --- a/src/java/davmail/exchange/ews/EWSMethod.java +++ b/src/java/davmail/exchange/ews/EWSMethod.java @@ -477,6 +477,11 @@ public abstract class EWSMethod extends PostMethod { * Original occurence start date */ public String originalStart; + + /** + * Occurence itemid + */ + public ItemId itemId; } /** @@ -867,17 +872,20 @@ public abstract class EWSMethod extends PostMethod { } protected void handleOccurrence(XMLStreamReader reader, Item item) throws XMLStreamException { + Occurrence occurrence = new Occurrence(); while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Occurrence"))) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); + if ("ItemId".equals(tagLocalName)) { + occurrence.itemId = new ItemId("ItemId", getAttributeValue(reader, "Id"), getAttributeValue(reader, "ChangeKey")); + } if ("OriginalStart".equals(tagLocalName)) { - Occurrence occurrence = new Occurrence(); occurrence.originalStart = XMLStreamUtil.getElementText(reader); - item.addOccurrence(occurrence); } } } + item.addOccurrence(occurrence); } public static String responseTypeToPartstat(String responseType) { diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 3d131c84..e5c91819 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -1655,22 +1655,7 @@ public class EwsExchangeSession extends ExchangeSession { 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); - String myResponseType = getItemMethod.getResponseItem().get(Field.get("myresponsetype").getResponseName()); - if ("Exchange2007_SP1".equals(serverVersion) && email.equalsIgnoreCase(attendee.email) && myResponseType != null) { - attendeeProperty.addParam("PARTSTAT", EWSMethod.responseTypeToPartstat(myResponseType)); - } else { - attendeeProperty.addParam("PARTSTAT", attendee.partstat); - } - //attendeeProperty.addParam("RSVP", "TRUE"); - attendeeProperty.addParam("ROLE", attendee.role); - localVCalendar.addFirstVeventProperty(attendeeProperty); - } - } + fixAttendees(getItemMethod, localVCalendar.getFirstVevent()); // fix UID and RECURRENCE-ID, broken at least on Exchange 2007 List occurences = getItemMethod.getResponseItem().getOccurrences(); if (occurences != null) { @@ -1678,7 +1663,13 @@ public class EwsExchangeSession extends ExchangeSession { for (EWSMethod.Occurrence occurrence : occurences) { if (modifiedOccurrencesIterator.hasNext()) { VObject modifiedOccurrence = modifiedOccurrencesIterator.next(); - // TODO: fix modified occurences attendees + // fix modified occurrences attendees + GetItemMethod getOccurrenceMethod = new GetItemMethod(BaseShape.ID_ONLY, occurrence.itemId, false); + getOccurrenceMethod.addAdditionalProperty(Field.get("requiredattendees")); + getOccurrenceMethod.addAdditionalProperty(Field.get("optionalattendees")); + getOccurrenceMethod.addAdditionalProperty(Field.get("modifiedoccurrences")); + executeMethod(getOccurrenceMethod); + fixAttendees(getOccurrenceMethod, modifiedOccurrence); if ("Exchange2007_SP1".equals(serverVersion)) { // fix uid, should be the same as main VEVENT @@ -1714,6 +1705,25 @@ public class EwsExchangeSession extends ExchangeSession { } return content; } + + protected void fixAttendees(GetItemMethod getItemMethod, VObject vEvent) throws EWSException { + 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); + String myResponseType = getItemMethod.getResponseItem().get(Field.get("myresponsetype").getResponseName()); + if ("Exchange2007_SP1".equals(serverVersion) && email.equalsIgnoreCase(attendee.email) && myResponseType != null) { + attendeeProperty.addParam("PARTSTAT", EWSMethod.responseTypeToPartstat(myResponseType)); + } else { + attendeeProperty.addParam("PARTSTAT", attendee.partstat); + } + //attendeeProperty.addParam("RSVP", "TRUE"); + attendeeProperty.addParam("ROLE", attendee.role); + vEvent.addProperty(attendeeProperty); + } + } + } } @Override diff --git a/src/java/davmail/exchange/ews/ItemId.java b/src/java/davmail/exchange/ews/ItemId.java index 86c3d9aa..c7ee14b2 100644 --- a/src/java/davmail/exchange/ews/ItemId.java +++ b/src/java/davmail/exchange/ews/ItemId.java @@ -69,6 +69,17 @@ public class ItemId { this.changeKey = null; } + /** + * Build Item id object from item id and change key. + * + * @param itemId item id + */ + public ItemId(String name, String itemId, String changeKey) { + this.name = name; + this.id = itemId; + this.changeKey = changeKey; + } + /** * Write item id as XML. *