diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index bd72686f..405216d4 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -16,8 +16,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import java.io.IOException; -import java.io.StringReader; +import java.io.*; import java.net.Socket; import java.net.SocketException; import java.net.SocketTimeoutException; @@ -253,12 +252,12 @@ public class CaldavConnection extends AbstractConnection { if ("inbox".equals(paths[3])) { paths[3] = "INBOX"; } - int status = session.deleteEvent(paths[3]+"/"+paths[4]); + int status = session.deleteEvent(paths[3] + "/" + paths[4]); sendHttpResponse(status, true); } else if ("GET".equals(command) && "users".equals(paths[1]) && paths.length == 5 && "calendar".equals(paths[3]) // only current user for now && session.getEmail().equalsIgnoreCase(paths[2])) { - ExchangeSession.Event event = session.getEvent(paths[3]+"/"+paths[4]); + ExchangeSession.Event event = session.getEvent(paths[3] + "/" + paths[4]); sendHttpResponse(HttpStatus.SC_OK, null, "text/calendar;charset=UTF-8", event.getICS(), true); } else { @@ -270,128 +269,96 @@ public class CaldavConnection extends AbstractConnection { } } - protected void appendEventsResponses(StringBuilder buffer, CaldavRequest request, String path, List events) throws IOException { + protected void appendEventsResponses(CaldavResponse response, CaldavRequest request, String path, List events) throws IOException { int size = events.size(); int count = 0; for (ExchangeSession.Event event : events) { DavGatewayTray.debug("Retrieving event " + (++count) + "/" + size); - appendEventResponse(buffer, request, path, event); + appendEventResponse(response, request, path, event); } } - protected void appendEventResponse(StringBuilder buffer, CaldavRequest request, String path, ExchangeSession.Event event) throws IOException { + protected void appendEventResponse(CaldavResponse response, CaldavRequest request, String path, ExchangeSession.Event event) throws IOException { String eventPath = event.getPath().replaceAll("<", "<").replaceAll(">", ">"); - buffer.append(""); - buffer.append("/users/").append(session.getEmail()).append("/").append(path).append("/").append(URIUtil.encodeWithinQuery(eventPath)).append(""); - buffer.append(""); - buffer.append(""); + response.startResponse("/users/" + session.getEmail() + "/" + path + "/" + URIUtil.encodeWithinQuery(eventPath)); + response.startPropstat(); if (request.hasProperty("calendar-data")) { - String ics = event.getICS(); - if (ics != null && ics.length() > 0) { - ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append(""); - buffer.append(ics); - buffer.append(""); - } + response.appendCalendarData(event.getICS()); } if (request.hasProperty("getetag")) { - buffer.append("").append(event.getEtag()).append(""); + response.appendProperty("D:getetag", event.getEtag()); } if (request.hasProperty("resourcetype")) { - buffer.append(""); + response.appendProperty("D:resourcetype"); } if (request.hasProperty("displayname")) { - buffer.append("").append(eventPath).append(""); + response.appendProperty("D:displayname", eventPath); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); + response.endPropStatOK(); + response.endResponse(); } - public void appendCalendar(StringBuilder buffer, String principal, CaldavRequest request) throws IOException { - buffer.append(""); - buffer.append("/users/").append(principal).append("/calendar"); - buffer.append(""); - buffer.append(""); + public void appendCalendar(CaldavResponse response, String principal, CaldavRequest request) throws IOException { + response.startResponse("/users/" + principal + "/calendar"); + response.startPropstat(); if (request.hasProperty("resourcetype")) { - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append(""); + response.appendProperty("D:resourcetype", "" + + ""); } if (request.hasProperty("owner")) { - buffer.append(""); - buffer.append("/principals/users/").append(principal).append(""); - buffer.append(""); + response.appendProperty("D:owner", "/principals/users/" + principal + ""); } if (request.hasProperty("getetag")) { - buffer.append("") - .append(session.getCalendarEtag()) - .append(""); + response.appendProperty("D:getetag", session.getCalendarEtag()); } if (request.hasProperty("getctag")) { - buffer.append("") - .append(base64Encode(session.getCalendarCtag())) - .append(""); + response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"", + base64Encode(session.getCalendarCtag())); } if (request.hasProperty("displayname")) { - buffer.append("calendar"); + response.appendProperty("D:displayname", "calendar"); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); + response.endPropStatOK(); + response.endResponse(); } - public void appendInbox(StringBuilder buffer, String principal, CaldavRequest request) { - buffer.append(""); - buffer.append("/users/").append(principal).append("/inbox"); - buffer.append(""); - buffer.append(""); + public void appendInbox(CaldavResponse response, String principal, CaldavRequest request) throws IOException { + response.startResponse("/users/" + principal + "/inbox"); + response.startPropstat(); if (request.hasProperty("resourcetype")) { - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append(""); + response.appendProperty("D:resourcetype", "" + + ""); } if (request.hasProperty("getctag")) { - buffer.append("0"); + response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"", + base64Encode(session.getInboxCtag())); } if (request.hasProperty("displayname")) { - buffer.append("inbox"); + response.appendProperty("", "inbox"); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); + response.endPropStatOK(); + response.endResponse(); } - public void appendOutbox(StringBuilder buffer, String principal, CaldavRequest request) { - buffer.append(""); - buffer.append("/users/").append(principal).append("/outbox"); - buffer.append(""); - buffer.append(""); + public void appendOutbox(CaldavResponse response, String principal, CaldavRequest request) throws IOException { + response.startResponse("/users/" + principal + "/outbox"); + response.startPropstat(); if (request.hasProperty("resourcetype")) { - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append(""); + response.appendProperty("D:resourcetype", "" + + ""); } if (request.hasProperty("getctag")) { - buffer.append("0"); + response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"", + "0"); } if (request.hasProperty("displayname")) { - buffer.append("outbox"); + response.appendProperty("", "outbox"); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); + response.endPropStatOK(); + response.endResponse(); } public void sendGetRoot() throws IOException { @@ -403,42 +370,39 @@ public class CaldavConnection extends AbstractConnection { } public void sendInbox(CaldavRequest request, int depth, String principal) throws IOException { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - appendInbox(buffer, principal, request); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + appendInbox(response, principal, request); if (depth == 1) { DavGatewayTray.debug("Searching calendar messages..."); List events = session.getEventMessages(); DavGatewayTray.debug("Found " + events.size() + " calendar messages"); - appendEventsResponses(buffer, request, "inbox", events); + appendEventsResponses(response, request, "inbox", events); } - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendOutbox(CaldavRequest request, String principal) throws IOException { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - appendOutbox(buffer, principal, request); - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + appendOutbox(response, principal, request); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendCalendar(CaldavRequest request, int depth, String principal) throws IOException { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - appendCalendar(buffer, principal, request); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + appendCalendar(response, principal, request); if (depth == 1) { DavGatewayTray.debug("Searching calendar events..."); List events = session.getAllEvents(); DavGatewayTray.debug("Found " + events.size() + " calendar events"); - appendEventsResponses(buffer, request, "calendar", events); + appendEventsResponses(response, request, "calendar", events); } - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } protected String getEventFileNameFromPath(String path) { @@ -464,89 +428,73 @@ public class CaldavConnection extends AbstractConnection { if (eventName == null) { notFound.add(href); } else { - events.add(session.getEvent(path+"/"+eventName)); + events.add(session.getEvent(path + "/" + eventName)); } } catch (HttpException e) { notFound.add(href); } } - } else if ("INBOX".equals(path)){ + } else if ("INBOX".equals(path)) { events = session.getEventMessages(); } else { events = session.getAllEvents(); } - StringBuilder buffer = new StringBuilder(); - buffer.append("" + - ""); - appendEventsResponses(buffer, request, path, events); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + appendEventsResponses(response, request, path, events); // send not found events errors for (String href : notFound) { - buffer.append(""); - buffer.append("").append(URIUtil.encodeWithinQuery(href)).append(""); - buffer.append(""); - buffer.append("HTTP/1.1 404 Not Found"); - buffer.append(""); - buffer.append(""); + response.startResponse(URIUtil.encodeWithinQuery(href)); + response.appendPropstatNotFound(); + response.endResponse(); } - buffer.append(""); + response.endMultistatus(); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendUserRoot(CaldavRequest request, int depth, String principal) throws IOException { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("/users/").append(principal).append(""); - buffer.append(""); - buffer.append(""); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + response.startResponse("/users/" + principal); + response.startPropstat(); + if (request.hasProperty("resourcetype")) { - buffer.append(""); - buffer.append(""); - buffer.append(""); + response.appendProperty("D:resourcetype", ""); } if (request.hasProperty("displayname")) { - buffer.append("").append(principal).append(""); + response.appendProperty("D:displayname", principal); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); + response.endPropStatOK(); if (depth == 1) { - appendInbox(buffer, principal, request); - appendOutbox(buffer, principal, request); - appendCalendar(buffer, principal, request); + appendInbox(response, principal, request); + appendOutbox(response, principal, request); + appendCalendar(response, principal, request); } - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + response.endResponse(); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendRoot(CaldavRequest request) throws IOException { - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("/"); - buffer.append(""); - buffer.append(""); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + response.startResponse("/"); + response.startPropstat(); + if (request.hasProperty("principal-collection-set")) { - buffer.append(""); - buffer.append("/principals/users/").append(session.getEmail()).append(""); - buffer.append(""); + response.appendProperty("D:principal-collection-set", "/principals/users/" + session.getEmail() + ""); } if (request.hasProperty("displayname")) { - buffer.append("ROOT"); + response.appendProperty("D:displayname", "ROOT"); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + response.endPropStatOK(); + response.endResponse(); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendPrincipal(CaldavRequest request, String principal) throws IOException { @@ -556,52 +504,37 @@ public class CaldavConnection extends AbstractConnection { actualPrincipal = session.getEmail(); } - StringBuilder buffer = new StringBuilder(); - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append("/principals/users/").append(principal).append(""); - buffer.append(""); - buffer.append(""); + CaldavResponse response = new CaldavResponse(); + response.startMultistatus(); + response.startResponse("/principals/users/" + principal); + response.startPropstat(); + if (request.hasProperty("calendar-home-set")) { - buffer.append(""); - buffer.append("/users/").append(actualPrincipal).append(""); - buffer.append(""); + response.appendProperty("C:calendar-home-set", "/users/" + actualPrincipal + ""); } if (request.hasProperty("calendar-user-address-set")) { - buffer.append(""); - buffer.append("mailto:").append(actualPrincipal).append(""); - buffer.append(""); + response.appendProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal + ""); } if (request.hasProperty("schedule-inbox-URL")) { - buffer.append(""); - buffer.append("/users/").append(actualPrincipal).append("/inbox"); - buffer.append(""); + response.appendProperty("C:schedule-inbox-URL", "/users/" + actualPrincipal + "/inbox"); } if (request.hasProperty("schedule-outbox-URL")) { - buffer.append(""); - buffer.append("/users/").append(actualPrincipal).append("/outbox"); - buffer.append(""); + response.appendProperty("C:schedule-outbox-URL", "/users/" + actualPrincipal + "/outbox"); } if (request.hasProperty("displayname")) { - buffer.append("").append(actualPrincipal).append(""); + response.appendProperty("D:displayname", actualPrincipal); } if (request.hasProperty("resourcetype")) { - buffer.append(""); - buffer.append(""); - buffer.append(""); - buffer.append(""); + response.appendProperty("D:resourcetype", ""); } - buffer.append(""); - buffer.append("HTTP/1.1 200 OK"); - buffer.append(""); - buffer.append(""); - buffer.append(""); - sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); + response.endPropStatOK(); + response.endResponse(); + response.endMultistatus(); + sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, response, true); } public void sendFreeBusy(String body) throws IOException { @@ -640,18 +573,15 @@ public class CaldavConnection extends AbstractConnection { } } if (!freeBusyMap.isEmpty()) { - StringBuilder response = new StringBuilder(); + CaldavResponse response = new CaldavResponse(); + response.startScheduleResponse(); - response.append("") - .append(""); for (Map.Entry entry : freeBusyMap.entrySet()) { String attendee = entry.getKey(); - response.append("") - .append("") - .append("").append(attendee).append("") - .append("") - .append("2.0;Success") - .append("BEGIN:VCALENDAR").append((char) 13).append((char) 10) + response.startRecipientResponse(attendee); + + StringBuilder ics = new StringBuilder(); + ics.append("BEGIN:VCALENDAR").append((char) 13).append((char) 10) .append("VERSION:2.0").append((char) 13).append((char) 10) .append("PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN").append((char) 13).append((char) 10) .append("METHOD:REPLY").append((char) 13).append((char) 10) @@ -663,15 +593,16 @@ public class CaldavConnection extends AbstractConnection { .append("UID:").append(valueMap.get("UID")).append("").append((char) 13).append((char) 10) .append(attendeeKeyMap.get(attendee)).append(":").append(attendee).append("").append((char) 13).append((char) 10); if (entry.getValue().length() > 0) { - response.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(entry.getValue()).append("").append((char) 13).append((char) 10); + ics.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(entry.getValue()).append("").append((char) 13).append((char) 10); } - response.append("END:VFREEBUSY").append((char) 13).append((char) 10) - .append("END:VCALENDAR") - .append("") - .append(""); + ics.append("END:VFREEBUSY").append((char) 13).append((char) 10) + .append("END:VCALENDAR"); + response.appendCalendarData(ics.toString()); + response.endRecipientResponse(); + } - response.append(""); - sendHttpResponse(HttpStatus.SC_OK, null, "text/xml;charset=UTF-8", response.toString(), true); + response.endScheduleResponse(); + sendHttpResponse(HttpStatus.SC_OK, null, response, true); } else { sendHttpResponse(HttpStatus.SC_NOT_FOUND, null, "text/plain", "Unknown recipient: " + valueMap.get("ATTENDEE"), true); } @@ -687,7 +618,7 @@ public class CaldavConnection extends AbstractConnection { buffer.append(path); Map responseHeaders = new HashMap(); responseHeaders.put("Location", buffer.toString()); - sendHttpResponse(HttpStatus.SC_MOVED_PERMANENTLY, responseHeaders, null, null, true); + sendHttpResponse(HttpStatus.SC_MOVED_PERMANENTLY, responseHeaders, true); } public void sendErr(int status, Exception e) throws IOException { @@ -705,23 +636,35 @@ public class CaldavConnection extends AbstractConnection { public void sendOptions() throws IOException { HashMap headers = new HashMap(); headers.put("Allow", "OPTIONS, GET, PROPFIND, PUT, POST"); - sendHttpResponse(HttpStatus.SC_OK, headers, null, null, true); + sendHttpResponse(HttpStatus.SC_OK, headers, true); } public void sendUnauthorized() throws IOException { HashMap headers = new HashMap(); headers.put("WWW-Authenticate", "Basic realm=\"" + Settings.getProperty("davmail.url") + "\""); - sendHttpResponse(HttpStatus.SC_UNAUTHORIZED, headers, null, null, true); + sendHttpResponse(HttpStatus.SC_UNAUTHORIZED, headers, true); } public void sendHttpResponse(int status, boolean keepAlive) throws IOException { - sendHttpResponse(status, null, null, null, keepAlive); + sendHttpResponse(status, null, null, (byte[]) null, keepAlive); + } + + public void sendHttpResponse(int status, Map headers, boolean keepAlive) throws IOException { + sendHttpResponse(status, headers, null, (byte[]) null, keepAlive); + } + + public void sendHttpResponse(int status, Map headers, CaldavResponse response, boolean keepAlive) throws IOException { + sendHttpResponse(status, headers, "text/xml;charset=UTF-8", response.getBytes(), keepAlive); } public void sendHttpResponse(int status, Map headers, String contentType, String content, boolean keepAlive) throws IOException { + sendHttpResponse(status, headers, contentType, content.getBytes("UTF-8"), keepAlive); + } + + public void sendHttpResponse(int status, Map headers, String contentType, byte[] content, boolean keepAlive) throws IOException { sendClient("HTTP/1.1 " + status + " " + HttpStatus.getStatusText(status)); sendClient("Server: DavMail Gateway"); - sendClient("DAV: 1, 2, 3, access-control, calendar-access, ticket, calendar-schedule, calendarserver-private-events"); + sendClient("DAV: 1, 2, 3, access-control, calendar-access, ticket, calendar-auto-schedule, calendar-schedule, calendarserver-private-events"); SimpleDateFormat formatter = new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH); sendClient("Date: " + formatter.format(new java.util.Date())); if (headers != null) { @@ -734,18 +677,18 @@ public class CaldavConnection extends AbstractConnection { } closed = closed || !keepAlive; sendClient("Connection: " + (closed ? "close" : "keep-alive")); - if (content != null && content.length() > 0) { - sendClient("Content-Length: " + content.getBytes("UTF-8").length); + if (content != null && content.length > 0) { + sendClient("Content-Length: " + content.length); } else { sendClient("Content-Length: 0"); } sendClient(""); - if (content != null && content.length() > 0) { + if (content != null && content.length > 0) { // full debug trace if (wireLogger.isDebugEnabled()) { - wireLogger.debug("> " + content); + wireLogger.debug("> " + new String(content, "UTF-8")); } - sendClient(content.getBytes("UTF-8")); + sendClient(content); } } @@ -845,5 +788,124 @@ public class CaldavConnection extends AbstractConnection { return hrefs; } } + + protected static class CaldavResponse { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStreamWriter writer; + + public CaldavResponse() throws IOException { + writer = new OutputStreamWriter(baos, "UTF-8"); + writer.write(""); + } + + public void startMultistatus() throws IOException { + writer.write(""); + } + + public void startResponse(String href) throws IOException { + writer.write(""); + writer.write(""); + writer.write(href); + writer.write(""); + } + + public void startPropstat() throws IOException { + writer.write(""); + writer.write(""); + } + + public void appendCalendarData(String ics) throws IOException { + if (ics != null && ics.length() > 0) { + ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + writer.write(""); + writer.write(ics); + writer.write(""); + } + } + + public void appendProperty(String propertyName) throws IOException { + appendProperty(propertyName, null); + } + + public void appendProperty(String propertyName, String propertyValue) throws IOException { + appendProperty(propertyName, null, propertyValue); + } + + public void appendProperty(String propertyName, String namespace, String propertyValue) throws IOException { + if (propertyValue != null) { + writer.write('<'); + writer.write(propertyName); + if (namespace != null) { + writer.write(" xmlns:"); + writer.write(namespace); + } + writer.write('>'); + writer.write(propertyValue); + writer.write("'); + } else { + writer.write('<'); + writer.write(propertyName); + writer.write("/>"); + } + } + + public void endPropStatOK() throws IOException { + writer.write(""); + writer.write("HTTP/1.1 200 OK"); + writer.write(""); + } + + public void appendPropstatNotFound() throws IOException { + writer.write(""); + writer.write("HTTP/1.1 404 Not Found"); + writer.write(""); + } + + public void endResponse() throws IOException { + writer.write(""); + } + + public void endMultistatus() throws IOException { + writer.write(""); + } + + public void startScheduleResponse() throws IOException { + writer.write(""); + } + + public void startRecipientResponse(String recipient) throws IOException { + writer.write(""); + writer.write(""); + writer.write(""); + writer.write(recipient); + writer.write(""); + writer.write(""); + writer.write("2.0;Success"); + } + + public void endRecipientResponse() throws IOException { + writer.write(""); + } + + public void endScheduleResponse() throws IOException { + writer.write(""); + } + + public void close() throws IOException { + try { + writer.close(); + } finally { + baos.close(); + } + } + + public byte[] getBytes() throws IOException { + close(); + return baos.toByteArray(); + } + } } diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index d3f8e9ca..72cd14a5 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1142,7 +1142,7 @@ public class ExchangeSession { MimeBodyPart bodyPart = null; for (int i = 0; i < multiPart.getCount(); i++) { String contentType = multiPart.getBodyPart(i).getContentType(); - if (contentType.startsWith("text/calendar") || contentType.startsWith("application/ics") ) { + if (contentType.startsWith("text/calendar") || contentType.startsWith("application/ics")) { bodyPart = (MimeBodyPart) multiPart.getBodyPart(i); } } @@ -1576,9 +1576,17 @@ public class ExchangeSession { return wdr.getStatusCode(); } + public String getInboxCtag() throws IOException { + return getFolderCtag(inboxUrl); + } + public String getCalendarCtag() throws IOException { + return getFolderCtag(calendarUrl); + } + + public String getFolderCtag(String folderUrl) throws IOException { String ctag = null; - Enumeration calendarEnum = wdr.propfindMethod(calendarUrl, 0); + Enumeration calendarEnum = wdr.propfindMethod(folderUrl, 0); if (!calendarEnum.hasMoreElements()) { throw new IOException("Unable to get calendar object"); }