1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

EWS: fix UID and RECURRENCE-ID, broken at least on Exchange 2007 with recurring events

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1663 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-04-12 20:32:22 +00:00
parent 6c40abbdfb
commit 184ba21cf0
5 changed files with 96 additions and 0 deletions

View File

@ -573,4 +573,18 @@ public class VCalendar extends VObject {
return status; return status;
} }
public List<VObject> getModifiedOccurrences() {
boolean first = true;
ArrayList<VObject> results = new ArrayList<VObject>();
for (VObject vObject:vObjects) {
if ("VEVENT".equals(vObject.type)) {
if (first) {
first = false;
} else {
results.add(vObject);
}
}
}
return results;
}
} }

View File

@ -443,6 +443,13 @@ public abstract class EWSMethod extends PostMethod {
public String name; public String name;
} }
/**
* Recurring event occurrence
*/
public static class Occurrence {
public String originalStart;
}
/** /**
* Item * Item
*/ */
@ -456,6 +463,7 @@ public abstract class EWSMethod extends PostMethod {
protected List<FileAttachment> attachments; protected List<FileAttachment> attachments;
protected List<Attendee> attendees; protected List<Attendee> attendees;
protected final List<String> fieldNames = new ArrayList<String>(); protected final List<String> fieldNames = new ArrayList<String>();
protected List<Occurrence> occurrences;
@Override @Override
public String toString() { public String toString() {
@ -613,6 +621,22 @@ public abstract class EWSMethod extends PostMethod {
} }
attendees.add(attendee); attendees.add(attendee);
} }
/**
* Add occurrence.
*
* @param attendee attendee object
*/
public void addOccurrence(Occurrence occurrence) {
if (occurrences == null) {
occurrences = new ArrayList<Occurrence>();
}
occurrences.add(occurrence);
}
public List<Occurrence> getOccurrences() {
return occurrences;
}
} }
/** /**
@ -738,6 +762,8 @@ public abstract class EWSMethod extends PostMethod {
handleEmailAddresses(reader, responseItem); handleEmailAddresses(reader, responseItem);
} else if ("RequiredAttendees".equals(tagLocalName) || "OptionalAttendees".equals(tagLocalName)) { } else if ("RequiredAttendees".equals(tagLocalName) || "OptionalAttendees".equals(tagLocalName)) {
handleAttendees(reader, responseItem, tagLocalName); handleAttendees(reader, responseItem, tagLocalName);
} else if ("ModifiedOccurrences".equals(tagLocalName)) {
handleModifiedOccurrences(reader, responseItem);
} else { } else {
if (tagLocalName.endsWith("Id")) { if (tagLocalName.endsWith("Id")) {
value = getAttributeValue(reader, "Id"); value = getAttributeValue(reader, "Id");
@ -780,6 +806,32 @@ public abstract class EWSMethod extends PostMethod {
} }
} }
protected void handleModifiedOccurrences(XMLStreamReader reader, Item item) throws XMLStreamException {
while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "ModifiedOccurrences"))) {
reader.next();
if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName();
if ("Occurrence".equals(tagLocalName)) {
handleOccurrence(reader, item);
}
}
}
}
protected void handleOccurrence(XMLStreamReader reader, Item item) throws XMLStreamException {
while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "Occurrence"))) {
reader.next();
if (XMLStreamUtil.isStartTag(reader)) {
String tagLocalName = reader.getLocalName();
if ("OriginalStart".equals(tagLocalName)) {
Occurrence occurrence = new Occurrence();
occurrence.originalStart = XMLStreamUtil.getElementText(reader);
item.addOccurrence(occurrence);
}
}
}
}
protected void handleAttendee(XMLStreamReader reader, Item item, String attendeeType) throws XMLStreamException { protected void handleAttendee(XMLStreamReader reader, Item item, String attendeeType) throws XMLStreamException {
Attendee attendee = new Attendee(); Attendee attendee = new Attendee();
if ("RequiredAttendees".equals(attendeeType)) { if ("RequiredAttendees".equals(attendeeType)) {

View File

@ -24,6 +24,7 @@ import davmail.exception.DavMailException;
import davmail.exception.HttpNotFoundException; import davmail.exception.HttpNotFoundException;
import davmail.exchange.ExchangeSession; import davmail.exchange.ExchangeSession;
import davmail.exchange.VCalendar; import davmail.exchange.VCalendar;
import davmail.exchange.VObject;
import davmail.exchange.VProperty; import davmail.exchange.VProperty;
import davmail.http.DavGatewayHttpClientFacade; import davmail.http.DavGatewayHttpClientFacade;
import davmail.util.IOUtil; import davmail.util.IOUtil;
@ -1306,6 +1307,7 @@ public class EwsExchangeSession extends ExchangeSession {
getItemMethod.addAdditionalProperty(Field.get("calendaruid")); getItemMethod.addAdditionalProperty(Field.get("calendaruid"));
getItemMethod.addAdditionalProperty(Field.get("requiredattendees")); getItemMethod.addAdditionalProperty(Field.get("requiredattendees"));
getItemMethod.addAdditionalProperty(Field.get("optionalattendees")); getItemMethod.addAdditionalProperty(Field.get("optionalattendees"));
getItemMethod.addAdditionalProperty(Field.get("modifiedoccurrences"));
getItemMethod.addAdditionalProperty(Field.get("xmozlastack")); getItemMethod.addAdditionalProperty(Field.get("xmozlastack"));
getItemMethod.addAdditionalProperty(Field.get("xmozsnoozetime")); getItemMethod.addAdditionalProperty(Field.get("xmozsnoozetime"));
getItemMethod.addAdditionalProperty(Field.get("xmozsendinvitations")); getItemMethod.addAdditionalProperty(Field.get("xmozsendinvitations"));
@ -1339,6 +1341,25 @@ public class EwsExchangeSession extends ExchangeSession {
localVCalendar.addFirstVeventProperty(attendeeProperty); localVCalendar.addFirstVeventProperty(attendeeProperty);
} }
} }
// fix UID and RECURRENCE-ID, broken at least on Exchange 2007
List<EWSMethod.Occurrence> occurences = getItemMethod.getResponseItem().getOccurrences();
if (occurences != null) {
Iterator<VObject> modifiedOccurrencesIterator = localVCalendar.getModifiedOccurrences().iterator();
for (EWSMethod.Occurrence occurrence : occurences) {
if (modifiedOccurrencesIterator.hasNext()) {
VObject modifiedOccurrence = modifiedOccurrencesIterator.next();
// fix uid, should be the same as main VEVENT
if (calendaruid != null) {
modifiedOccurrence.setPropertyValue("UID", calendaruid);
}
VProperty recurrenceId = modifiedOccurrence.getProperty("RECURRENCE-ID");
if (recurrenceId != null) {
recurrenceId.removeParam("TZID");
recurrenceId.getValues().set(0, convertDateFromExchange(occurrence.originalStart));
}
}
}
}
// restore mozilla invitations option // restore mozilla invitations option
localVCalendar.setFirstVeventPropertyValue("X-MOZ-SEND-INVITATIONS", localVCalendar.setFirstVeventPropertyValue("X-MOZ-SEND-INVITATIONS",
getItemMethod.getResponseItem().get(Field.get("xmozsendinvitations").getResponseName())); getItemMethod.getResponseItem().get(Field.get("xmozsendinvitations").getResponseName()));

View File

@ -197,6 +197,7 @@ public final class Field {
FIELD_MAP.put("requiredattendees", new UnindexedFieldURI("calendar:RequiredAttendees")); FIELD_MAP.put("requiredattendees", new UnindexedFieldURI("calendar:RequiredAttendees"));
FIELD_MAP.put("optionalattendees", new UnindexedFieldURI("calendar:OptionalAttendees")); FIELD_MAP.put("optionalattendees", new UnindexedFieldURI("calendar:OptionalAttendees"));
FIELD_MAP.put("modifiedoccurrences", new UnindexedFieldURI("calendar:ModifiedOccurrences"));
FIELD_MAP.put("xmozlastack", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozlastack")); FIELD_MAP.put("xmozlastack", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozlastack"));
FIELD_MAP.put("xmozsnoozetime", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozsnoozetime")); FIELD_MAP.put("xmozsnoozetime", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozsnoozetime"));

View File

@ -135,6 +135,14 @@ public class TestCaldav extends AbstractDavMailTestCase {
assertEquals(HttpStatus.SC_OK, method.getStatusCode()); assertEquals(HttpStatus.SC_OK, method.getStatusCode());
} }
public void testPropfindCalendar() throws IOException {
//Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
PropFindMethod method = new PropFindMethod("/users/" + session.getAlias() + "/calendar/", null, 1);
httpClient.executeMethod(method);
assertEquals(HttpStatus.SC_OK, method.getStatusCode());
}
public void testGetOtherUserCalendar() throws IOException { public void testGetOtherUserCalendar() throws IOException {
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG); Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
PropFindMethod method = new PropFindMethod("/principals/users/" + Settings.getProperty("davmail.to") + "/calendar/"); PropFindMethod method = new PropFindMethod("/principals/users/" + Settings.getProperty("davmail.to") + "/calendar/");