mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
Fix another URI encoding issue with calendar and fix all day events (add X-MICROSOFT-CDO-ALLDAYEVENT)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@223 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
6dc0eb450a
commit
efc9be7c23
@ -42,6 +42,12 @@ public class ExchangeSession {
|
|||||||
MESSAGE_REQUEST_PROPERTIES.add("http://schemas.microsoft.com/mapi/proptag/x0e080003");
|
MESSAGE_REQUEST_PROPERTIES.add("http://schemas.microsoft.com/mapi/proptag/x0e080003");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final Vector<String> EVENT_REQUEST_PROPERTIES = new Vector<String>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
EVENT_REQUEST_PROPERTIES.add("DAV:getetag");
|
||||||
|
}
|
||||||
|
|
||||||
protected static final Vector<String> WELL_KNOWN_FOLDERS = new Vector<String>();
|
protected static final Vector<String> WELL_KNOWN_FOLDERS = new Vector<String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -903,11 +909,9 @@ public class ExchangeSession {
|
|||||||
public Event getEvent(String path) throws IOException {
|
public Event getEvent(String path) throws IOException {
|
||||||
// TODO : refactor with getAllEvents
|
// TODO : refactor with getAllEvents
|
||||||
Event event = new Event();
|
Event event = new Event();
|
||||||
final Vector<String> EVENT_REQUEST_PROPERTIES = new Vector<String>();
|
|
||||||
EVENT_REQUEST_PROPERTIES.add("DAV:getetag");
|
|
||||||
|
|
||||||
//wdr.setDebug(4);
|
//wdr.setDebug(4);
|
||||||
Enumeration calendarEnum = wdr.propfindMethod(calendarUrl + "/" + path, 0, EVENT_REQUEST_PROPERTIES);
|
Enumeration calendarEnum = wdr.propfindMethod(calendarUrl + "/" + URIUtil.decode(path), 0, EVENT_REQUEST_PROPERTIES);
|
||||||
//wdr.setDebug(0);
|
//wdr.setDebug(0);
|
||||||
if (!calendarEnum.hasMoreElements()) {
|
if (!calendarEnum.hasMoreElements()) {
|
||||||
throw new IOException("Unable to get calendar event");
|
throw new IOException("Unable to get calendar event");
|
||||||
@ -926,6 +930,53 @@ public class ExchangeSession {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String fixICSToExchange(String icsBody) throws IOException {
|
||||||
|
// first pass : detect
|
||||||
|
boolean isAllDay = false;
|
||||||
|
boolean hasCdoAllDay = false;
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new StringReader(icsBody));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
int index = line.indexOf(':');
|
||||||
|
if (index >= 0) {
|
||||||
|
String key = line.substring(0, index);
|
||||||
|
String value = line.substring(index + 1);
|
||||||
|
if ("DTSTART;VALUE=DATE".equals(key)) {
|
||||||
|
isAllDay = true;
|
||||||
|
} else if ("X-MICROSOFT-CDO-ALLDAYEVENT".equals(key)) {
|
||||||
|
hasCdoAllDay = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// second pass : fix
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new StringReader(icsBody));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE".equals(line)) {
|
||||||
|
line = "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE";
|
||||||
|
} else if ("END:VEVENT".equals(line) && isAllDay && !hasCdoAllDay) {
|
||||||
|
result.append("X-MICROSOFT-CDO-ALLDAYEVENT:TRUE").append((char) 13).append((char) 10);
|
||||||
|
} else if (!isAllDay && "X-MICROSOFT-CDO-ALLDAYEVENT:TRUE".equals(line)) {
|
||||||
|
line = "X-MICROSOFT-CDO-ALLDAYEVENT:FALSE";
|
||||||
|
}
|
||||||
|
result.append(line).append((char) 13).append((char) 10);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public int createOrUpdateEvent(String path, String icsBody, String etag) throws IOException {
|
public int createOrUpdateEvent(String path, String icsBody, String etag) throws IOException {
|
||||||
String messageUrl = URIUtil.encodePathQuery(calendarUrl + "/" + URIUtil.decode(path));
|
String messageUrl = URIUtil.encodePathQuery(calendarUrl + "/" + URIUtil.decode(path));
|
||||||
String uid = path.substring(0, path.lastIndexOf("."));
|
String uid = path.substring(0, path.lastIndexOf("."));
|
||||||
@ -951,7 +1002,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(icsBody.getBytes("UTF-8"), "ISO-8859-1"));
|
body.append(new String(fixICSToExchange(icsBody).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