diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index a8b563f5..fcee3ed7 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -2516,19 +2516,13 @@ public abstract class ExchangeSession { } boolean caldavDisableTasks = Settings.getBooleanProperty("davmail.caldavDisableTasks"); - Condition condition; - if (caldavDisableTasks) { - condition = or(isEqualTo("instancetype", 1), - and(isEqualTo("instancetype", 0), dateCondition)); - } else { - condition = or(isNull("instancetype"), - isEqualTo("instancetype", 1), - and(isEqualTo("instancetype", 0), dateCondition)); - } + Condition condition = getCalendarItemCondition(caldavDisableTasks, dateCondition); return searchEvents(folderPath, condition); } + protected abstract Condition getCalendarItemCondition(boolean excludeTasks, Condition dateCondition); + protected Condition getRangeCondition(String timeRangeStart, String timeRangeEnd) throws IOException { try { SimpleDateFormat parser = getZuluDateFormat(); @@ -2557,15 +2551,7 @@ public abstract class ExchangeSession { public List searchEvents(String folderPath, String timeRangeStart, String timeRangeEnd) throws IOException { Condition dateCondition = getRangeCondition(timeRangeStart, timeRangeEnd); boolean caldavDisableTasks = Settings.getBooleanProperty("davmail.caldavDisableTasks"); - Condition condition; - if (caldavDisableTasks) { - condition = or(isEqualTo("instancetype", 1), - and(isEqualTo("instancetype", 0), dateCondition)); - } else { - condition = or(isNull("instancetype"), - isEqualTo("instancetype", 1), - and(isEqualTo("instancetype", 0), dateCondition)); - } + Condition condition = getCalendarItemCondition(caldavDisableTasks, dateCondition); return searchEvents(folderPath, condition); } @@ -2581,19 +2567,18 @@ public abstract class ExchangeSession { */ public List searchEventsOnly(String folderPath, String timeRangeStart, String timeRangeEnd) throws IOException { Condition dateCondition = getRangeCondition(timeRangeStart, timeRangeEnd); - return searchEvents(folderPath, or(isEqualTo("instancetype", 1), - and(isEqualTo("instancetype", 0), dateCondition))); + return searchEvents(folderPath, getCalendarItemCondition(true, dateCondition)); } /** * Search tasks only (VTODO). * * @param folderPath Exchange folder path - * @return list of calendar events + * @return list of tasks * @throws IOException on error */ public List searchTasksOnly(String folderPath) throws IOException { - return searchEvents(folderPath, isNull("instancetype")); + return searchEvents(folderPath, not(isEqualTo("outlookmessageclass", "IPM.Appointment"))); } /** @@ -2611,7 +2596,7 @@ public abstract class ExchangeSession { LOGGER.debug("Shared or public calendar: exclude private events"); privateCondition = isEqualTo("sensitivity", 0); } - // instancetype 0 single appointment / 1 master recurring appointment + return searchEvents(folderPath, ITEM_PROPERTIES, and(filter, privateCondition)); } diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index cacf2bea..92fdde1a 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -1867,6 +1867,19 @@ public class DavExchangeSession extends ExchangeSession { return events; } + @Override + protected Condition getCalendarItemCondition(boolean excludeTasks, Condition dateCondition) { + // instancetype 0 single appointment / 1 master recurring appointment + if (excludeTasks) { + return or(isEqualTo("instancetype", 1), + and(isEqualTo("instancetype", 0), dateCondition)); + } else { + return or(isNull("instancetype"), + isEqualTo("instancetype", 1), + and(isEqualTo("instancetype", 0), dateCondition)); + } + } + protected MultiStatusResponse[] searchItems(String folderPath, Set attributes, Condition condition, FolderQueryTraversal folderQueryTraversal, int maxCount) throws IOException { String folderUrl = getFolderPath(folderPath); diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index df69afa5..1128ab8d 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -1393,6 +1393,19 @@ public class EwsExchangeSession extends ExchangeSession { return contacts; } + @Override + protected Condition getCalendarItemCondition(boolean excludeTasks, Condition dateCondition) { + // instancetype 0 single appointment / 1 master recurring appointment + if (excludeTasks) { + return or(isTrue("isrecurring"), + and(isFalse("isrecurring"), dateCondition)); + } else { + return or(not(isEqualTo("outlookmessageclass", "IPM.Appointment")), + isTrue("isrecurring"), + and(isFalse("isrecurring"), dateCondition)); + } + } + @Override public List getEventMessages(String folderPath) throws IOException { return searchEvents(folderPath, ITEM_PROPERTIES, diff --git a/src/java/davmail/exchange/ews/Field.java b/src/java/davmail/exchange/ews/Field.java index 440a1af7..90506bc6 100644 --- a/src/java/davmail/exchange/ews/Field.java +++ b/src/java/davmail/exchange/ews/Field.java @@ -199,6 +199,8 @@ public final class Field { FIELD_MAP.put("optionalattendees", new UnindexedFieldURI("calendar:OptionalAttendees")); FIELD_MAP.put("modifiedoccurrences", new UnindexedFieldURI("calendar:ModifiedOccurrences")); + FIELD_MAP.put("isrecurring", new UnindexedFieldURI("calendar:IsRecurring")); + FIELD_MAP.put("xmozlastack", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozlastack")); FIELD_MAP.put("xmozsnoozetime", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozsnoozetime")); FIELD_MAP.put("xmozsendinvitations", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "xmozsendinvitations"));