Commit 5ddab45b authored by Mickaël Guessant's avatar Mickaël Guessant

Caldav: EWS refactoring, implement reminder update

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2517 3d1905a2-6b24-0410-a738-b14d5a86fcbd
parent 1a58df1d
......@@ -652,8 +652,8 @@ public class VCalendar extends VObject {
if (vObjects != null) {
for (VObject vObject : vObjects) {
if ("VEVENT".equals(vObject.type)) {
if (vObject.vObjects != null) {
return true;
if (vObject.vObjects != null && !vObject.vObjects.isEmpty()) {
return vObject.vObjects.get(0).isVAlarm();
}
}
}
......@@ -661,6 +661,37 @@ public class VCalendar extends VObject {
return false;
}
public String getReminderMinutesBeforeStart() {
String result = "0";
if (vObjects != null) {
for (VObject vObject : vObjects) {
if (vObject.vObjects != null && !vObject.vObjects.isEmpty() &&
vObject.vObjects.get(0).isVAlarm()) {
String trigger = vObject.vObjects.get(0).getPropertyValue("TRIGGER");
if (trigger != null) {
if (trigger.startsWith("-PT") && trigger.endsWith("M")) {
result = trigger.substring(3, trigger.length() - 1);
} else if (trigger.startsWith("-PT") && trigger.endsWith("H")) {
result = trigger.substring(3, trigger.length() - 1);
// convert to minutes
result = String.valueOf(Integer.parseInt(result) * 60);
} else if (trigger.startsWith("-P") && trigger.endsWith("D")) {
result = trigger.substring(2, trigger.length() - 1);
// convert to minutes
result = String.valueOf(Integer.parseInt(result) * 60 * 24);
} else if (trigger.startsWith("-P") && trigger.endsWith("W")) {
result = trigger.substring(2, trigger.length() - 1);
// convert to minutes
result = String.valueOf(Integer.parseInt(result) * 60 * 24 * 7);
}
}
}
}
}
return result;
}
/**
* Check if this VCalendar is a meeting.
*
......
......@@ -100,6 +100,11 @@ public class VObject {
return "VEVENT".equals(type);
}
public boolean isVAlarm() {
return "VALARM".equals(type);
}
protected void handleLine(String line, BufferedReader reader) throws IOException {
// skip empty lines
if (line.length() > 0) {
......@@ -292,4 +297,5 @@ public class VObject {
public void setType(String type) {
this.type = type;
}
}
......@@ -1604,6 +1604,13 @@ public class EwsExchangeSession extends ExchangeSession {
updates.add(Field.createFieldUpdate("keywords", StringUtil.join(categoryValues, ",")));
}
updates.add(Field.createFieldUpdate("reminderset", String.valueOf(vCalendar.hasVAlarm())));
if (vCalendar.hasVAlarm()) {
updates.add(Field.createFieldUpdate("reminderminutesbeforestart", vCalendar.getReminderMinutesBeforeStart()));
}
VProperty rrule = vCalendar.getFirstVevent().getProperty("RRULE");
if (rrule != null) {
RecurrenceFieldUpdate recurrenceFieldUpdate = new RecurrenceFieldUpdate();
......@@ -1738,8 +1745,8 @@ public class EwsExchangeSession extends ExchangeSession {
} else {
// update existing item
if (currentItemId != null && /*) {
if (*/vCalendar.isMeeting() && !vCalendar.isMeetingOrganizer()) {
if (currentItemId != null) {
if (vCalendar.isMeeting() && !vCalendar.isMeetingOrganizer()) {
// This is a meeting response
EWSMethod.Item item = new EWSMethod.Item();
......@@ -1750,8 +1757,8 @@ public class EwsExchangeSession extends ExchangeSession {
getFolderId(SENT),
item
);
/*} else {
/*createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
} else {
createOrUpdateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
ConflictResolution.AutoResolve,
SendMeetingInvitationsOrCancellations.SendToAllAndSaveCopy,
currentItemId, buildFieldUpdates(vCalendar));
......@@ -1759,13 +1766,13 @@ public class EwsExchangeSession extends ExchangeSession {
if (serverVersion != null && serverVersion.startsWith("Exchange201")) {
createOrUpdateItemMethod.setTimezoneContext(EwsExchangeSession.this.getVTimezone().getPropertyValue("TZID"));
}
}*/
}
} else {
// old hard/delete approach on update
if (currentItemId != null) {
/*if (currentItemId != null) {
DeleteItemMethod deleteItemMethod = new DeleteItemMethod(currentItemId, DeleteType.HardDelete, SendMeetingCancellations.SendToNone);
executeMethod(deleteItemMethod);
}
}*/
// create
EWSMethod.Item newItem = new EWSMethod.Item();
newItem.type = "CalendarItem";
......
......@@ -211,6 +211,8 @@ public final class Field {
FIELD_MAP.put("processed", new ExtendedFieldURI(0x65e8, ExtendedFieldURI.PropertyType.Boolean));
FIELD_MAP.put("reminderset", new UnindexedFieldURI("item:ReminderIsSet"));
FIELD_MAP.put("reminderminutesbeforestart", new UnindexedFieldURI("item:ReminderMinutesBeforeStart"));
FIELD_MAP.put("ismeeting", new UnindexedFieldURI("item:IsMeeting"));
FIELD_MAP.put("apptstateflags", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Appointment, 0x8217, ExtendedFieldURI.PropertyType.Integer)); // PidLidAppointmentStateFlags 1: Meeting, 2: Received, 4: Cancelled
FIELD_MAP.put("appointmentstate", new UnindexedFieldURI("calendar:AppointmentState"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment