mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Recurring events support
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@226 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
399da671ae
commit
6a18d3cdc1
@ -840,7 +840,7 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
method.releaseConnection();
|
method.releaseConnection();
|
||||||
}
|
}
|
||||||
return fixICS(buffer.toString());
|
return fixICS(buffer.toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() throws URIException {
|
public String getPath() throws URIException {
|
||||||
@ -864,16 +864,17 @@ public class ExchangeSession {
|
|||||||
List<Event> events = new ArrayList<Event>();
|
List<Event> events = new ArrayList<Event>();
|
||||||
String searchRequest = "<?xml version=\"1.0\"?>\n" +
|
String searchRequest = "<?xml version=\"1.0\"?>\n" +
|
||||||
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
|
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
|
||||||
" <d:sql> Select \"DAV:getetag\"" +
|
" <d:sql> Select \"DAV:getetag\", \"urn:schemas:calendar:instancetype\"" +
|
||||||
" FROM Scope('SHALLOW TRAVERSAL OF \"" + calendarUrl + "\"')\n" +
|
" FROM Scope('SHALLOW TRAVERSAL OF \"" + calendarUrl + "\"')\n" +
|
||||||
" WHERE NOT \"urn:schemas:calendar:instancetype\" = 1\n" +
|
" WHERE NOT\"urn:schemas:calendar:instancetype\" = 2\n" +
|
||||||
|
" AND NOT\"urn:schemas:calendar:instancetype\" = 3\n" +
|
||||||
" AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n" +
|
" AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n" +
|
||||||
dateCondition +
|
dateCondition +
|
||||||
" ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n" +
|
" ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n" +
|
||||||
" </d:sql>\n" +
|
" </d:sql>\n" +
|
||||||
"</d:searchrequest>";
|
"</d:searchrequest>";
|
||||||
SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(calendarUrl), searchRequest);
|
SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(calendarUrl), searchRequest);
|
||||||
//searchMethod.setDebug(4);
|
searchMethod.setDebug(4);
|
||||||
try {
|
try {
|
||||||
int status = wdr.retrieveSessionInstance().executeMethod(searchMethod);
|
int status = wdr.retrieveSessionInstance().executeMethod(searchMethod);
|
||||||
// Also accept OK sent by buggy servers.
|
// Also accept OK sent by buggy servers.
|
||||||
@ -930,11 +931,15 @@ public class ExchangeSession {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String fixICS(String icsBody) throws IOException {
|
protected String fixICS(String icsBody, boolean fromServer) throws IOException {
|
||||||
// first pass : detect
|
// first pass : detect
|
||||||
|
class AllDayState {
|
||||||
boolean isAllDay = false;
|
boolean isAllDay = false;
|
||||||
boolean hasCdoAllDay = false;
|
boolean hasCdoAllDay = false;
|
||||||
boolean isCdoAllDay = false;
|
boolean isCdoAllDay = false;
|
||||||
|
}
|
||||||
|
List<AllDayState> allDayStates = new ArrayList<AllDayState>();
|
||||||
|
AllDayState currentAllDayState = new AllDayState();
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new StringReader(icsBody));
|
reader = new BufferedReader(new StringReader(icsBody));
|
||||||
@ -945,10 +950,13 @@ public class ExchangeSession {
|
|||||||
String key = line.substring(0, index);
|
String key = line.substring(0, index);
|
||||||
String value = line.substring(index + 1);
|
String value = line.substring(index + 1);
|
||||||
if ("DTSTART;VALUE=DATE".equals(key)) {
|
if ("DTSTART;VALUE=DATE".equals(key)) {
|
||||||
isAllDay = true;
|
currentAllDayState.isAllDay = true;
|
||||||
} else if ("X-MICROSOFT-CDO-ALLDAYEVENT".equals(key)) {
|
} else if ("X-MICROSOFT-CDO-ALLDAYEVENT".equals(key)) {
|
||||||
hasCdoAllDay = true;
|
currentAllDayState.hasCdoAllDay = true;
|
||||||
isCdoAllDay = "TRUE".equals(value);
|
currentAllDayState.isCdoAllDay = "TRUE".equals(value);
|
||||||
|
} else if ("END:VEVENT".equals(line)) {
|
||||||
|
allDayStates.add(currentAllDayState);
|
||||||
|
currentAllDayState = new AllDayState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -958,21 +966,24 @@ public class ExchangeSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// second pass : fix
|
// second pass : fix
|
||||||
|
int count = 0;
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new StringReader(icsBody));
|
reader = new BufferedReader(new StringReader(icsBody));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE".equals(line)) {
|
if (currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE".equals(line)) {
|
||||||
line = "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE";
|
line = "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE";
|
||||||
} else if ("END:VEVENT".equals(line) && isAllDay && !hasCdoAllDay) {
|
} else if ("END:VEVENT".equals(line) && currentAllDayState.isAllDay && !currentAllDayState.hasCdoAllDay) {
|
||||||
result.append("X-MICROSOFT-CDO-ALLDAYEVENT:TRUE").append((char) 13).append((char) 10);
|
result.append("X-MICROSOFT-CDO-ALLDAYEVENT:TRUE").append((char) 13).append((char) 10);
|
||||||
} else if (!isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE".equals(line)) {
|
} else if (!currentAllDayState.isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE".equals(line)) {
|
||||||
line = "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE";
|
line = "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE";
|
||||||
} else if (isCdoAllDay && line.startsWith("DTSTART;TZID")) {
|
} else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTSTART;TZID")) {
|
||||||
line = getAllDayLine(line);
|
line = getAllDayLine(line);
|
||||||
} else if (isCdoAllDay && line.startsWith("DTEND;TZID")) {
|
} else if (fromServer && currentAllDayState.isCdoAllDay && line.startsWith("DTEND;TZID")) {
|
||||||
line = getAllDayLine(line);
|
line = getAllDayLine(line);
|
||||||
|
} else if ("BEGIN:VEVENT".equals(line)) {
|
||||||
|
currentAllDayState = allDayStates.get(count++);
|
||||||
}
|
}
|
||||||
result.append(line).append((char) 13).append((char) 10);
|
result.append(line).append((char) 13).append((char) 10);
|
||||||
}
|
}
|
||||||
@ -1031,7 +1042,7 @@ public class ExchangeSession {
|
|||||||
"\tmethod=REQUEST;\n" +
|
"\tmethod=REQUEST;\n" +
|
||||||
"\tcharset=\"utf-8\"\n" +
|
"\tcharset=\"utf-8\"\n" +
|
||||||
"Content-Transfer-Encoding: 8bit\n\n");
|
"Content-Transfer-Encoding: 8bit\n\n");
|
||||||
body.append(new String(fixICS(icsBody).getBytes("UTF-8"), "ISO-8859-1"));
|
body.append(new String(fixICS(icsBody, false).getBytes("UTF-8"), "ISO-8859-1"));
|
||||||
body.append("------=_NextPart_").append(uid).append("--\n");
|
body.append("------=_NextPart_").append(uid).append("--\n");
|
||||||
putmethod.setRequestBody(body.toString());
|
putmethod.setRequestBody(body.toString());
|
||||||
int status;
|
int status;
|
||||||
|
Loading…
Reference in New Issue
Block a user