From cc1aa6ce32fae85b37ca960c5bdb4ce623c3c79a Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 3 Mar 2009 15:59:06 +0000 Subject: [PATCH] Caldav: Fix AllDay handling git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@414 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 72cd14a5..680dc57c 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -961,7 +961,7 @@ public class ExchangeSession { byte[] decodedValue = Base64.decode(uid.getBytes()); long result = 0; - for (int i = 2; i < 9; i++) { + for (int i = 3; i < 9; i++) { result = result << 8; result |= decodedValue[i] & 0xff; } @@ -1094,7 +1094,14 @@ public class ExchangeSession { } public int compareTo(Object message) { - return (int) (getUidAsLong() - ((Message) message).getUidAsLong()); + long compareValue = (getUidAsLong() - ((Message) message).getUidAsLong()); + if (compareValue > 0) { + return 1; + } else if (compareValue < 0) { + return -1; + } else { + return 0; + } } @Override @@ -1309,15 +1316,15 @@ public class ExchangeSession { String line; while ((line = reader.readLine()) != null) { - if (currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE".equals(line)) { + if (!fromServer && currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE".equals(line)) { line = "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE"; - } else if ("END:VEVENT".equals(line) && currentAllDayState.isAllDay && !currentAllDayState.hasCdoAllDay) { + } else if (!fromServer && "END:VEVENT".equals(line) && currentAllDayState.isAllDay && !currentAllDayState.hasCdoAllDay) { result.writeLine("X-MICROSOFT-CDO-ALLDAYEVENT:TRUE"); - } else if (!currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE".equals(line)) { + } else if (!fromServer && !currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE".equals(line)) { line = "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE"; - } else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTSTART;TZID")) { + } else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTSTART") && !line.startsWith("DTSTART;VALUE=DATE")) { line = getAllDayLine(line); - } else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTEND;TZID")) { + } else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTEND") && !line.startsWith("DTEND;VALUE=DATE")) { line = getAllDayLine(line); } else if ("BEGIN:VEVENT".equals(line)) { currentAllDayState = allDayStates.get(count++); @@ -1383,11 +1390,11 @@ public class ExchangeSession { int keyIndex = line.indexOf(';'); int valueIndex = line.lastIndexOf(':'); int valueEndIndex = line.lastIndexOf('T'); - if (keyIndex < 0 || valueIndex < 0 || valueEndIndex < 0) { + if (valueIndex < 0 || valueEndIndex < 0) { throw new IOException("Invalid ICS line: " + line); } - String dateValue = line.substring(valueIndex + 1); - String key = line.substring(0, keyIndex); + String dateValue = line.substring(valueIndex + 1, valueEndIndex); + String key = line.substring(0, Math.max(keyIndex, valueIndex)); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date; @@ -1399,7 +1406,7 @@ public class ExchangeSession { if ("DTEND".equals(key)) { date.setTime(date.getTime() - 1); } - return line.substring(0, keyIndex) + ";VALUE=DATE:" + line.substring(valueIndex + 1, valueEndIndex); + return key + ";VALUE=DATE:" + dateValue; }