From b84a2974f09f188f924a3580023264f62f2be21f Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 19 Jan 2009 14:44:02 +0000 Subject: [PATCH] Workaroung for Lightning bug https://bugzilla.mozilla.org/show_bug.cgi?id=474112: do not pretty print Caldav XML responses (remove non mandatory spaces and CRLF) git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@299 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 301 +++++++++--------- 1 file changed, 150 insertions(+), 151 deletions(-) diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 391f872f..410ff2dc 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -255,117 +255,117 @@ public class CaldavConnection extends AbstractConnection { protected void appendEventResponse(StringBuilder buffer, CaldavRequest request, ExchangeSession.Event event) throws IOException { String eventPath = event.getPath().replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append("\n"); - buffer.append(" /users/").append(session.getEmail()).append("/calendar").append(eventPath).append("\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("/users/").append(session.getEmail()).append("/calendar").append(eventPath).append(""); + buffer.append(""); + buffer.append(""); if (request.hasProperty("calendar-data")) { String ics = event.getICS(); if (ics != null && ics.length() > 0) { ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append(" "); + buffer.append(""); buffer.append(ics); - buffer.append("\n"); + buffer.append(""); } } if (request.hasProperty("getetag")) { - buffer.append(" ").append(event.getEtag()).append("\n"); + buffer.append("").append(event.getEtag()).append(""); } if (request.hasProperty("resourcetype")) { - buffer.append(" "); + buffer.append(""); } if (request.hasProperty("displayname")) { - buffer.append(" ").append(eventPath).append(""); + buffer.append("").append(eventPath).append(""); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("HTTP/1.1 200 OK"); + buffer.append(""); + buffer.append(""); } public void appendCalendar(StringBuilder buffer, String principal, CaldavRequest request) throws IOException { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("/calendar\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("/users/").append(principal).append("/calendar"); + buffer.append(""); + buffer.append(""); if (request.hasProperty("resourcetype")) { - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append(""); } if (request.hasProperty("owner")) { - buffer.append(" \n"); - buffer.append(" /principals/users/").append(principal).append("\n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("/principals/users/").append(principal).append(""); + buffer.append(""); } if (request.hasProperty("getetag")) { - buffer.append(" ") + buffer.append("") .append(session.getCalendarEtag()) - .append("\n"); + .append(""); } if (request.hasProperty("getctag")) { - buffer.append(" ") + buffer.append("") .append(base64Encode(session.getCalendarCtag())) - .append("\n"); + .append(""); } if (request.hasProperty("displayname")) { - buffer.append(" calendar"); + buffer.append("calendar"); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("HTTP/1.1 200 OK"); + buffer.append(""); + buffer.append(""); } public void appendInbox(StringBuilder buffer, String principal, CaldavRequest request) throws IOException { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("/inbox\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("/users/").append(principal).append("/inbox"); + buffer.append(""); + buffer.append(""); if (request.hasProperty("resourcetype")) { - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append(""); } if (request.hasProperty("getctag")) { - buffer.append(" 0\n"); + buffer.append("0"); } if (request.hasProperty("displayname")) { - buffer.append(" inbox"); + buffer.append("inbox"); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("HTTP/1.1 200 OK"); + buffer.append(""); + buffer.append(""); } public void appendOutbox(StringBuilder buffer, String principal, CaldavRequest request) throws IOException { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("/outbox\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("/users/").append(principal).append("/outbox"); + buffer.append(""); + buffer.append(""); if (request.hasProperty("resourcetype")) { - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append(""); } if (request.hasProperty("getctag")) { - buffer.append(" 0\n"); + buffer.append("0"); } if (request.hasProperty("displayname")) { - buffer.append(" outbox"); + buffer.append("outbox"); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("HTTP/1.1 200 OK"); + buffer.append(""); + buffer.append(""); } public void sendGetRoot() throws IOException { @@ -378,35 +378,35 @@ public class CaldavConnection extends AbstractConnection { public void sendInbox(CaldavRequest request, String principal) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); + buffer.append(""); + buffer.append(""); appendInbox(buffer, principal, request); - buffer.append("\n"); + buffer.append(""); sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); } public void reportInbox() throws IOException { // inbox is always empty StringBuilder buffer = new StringBuilder(); - buffer.append("\n" + - "\n"); + buffer.append("" + + ""); buffer.append(""); sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); } public void sendOutbox(CaldavRequest request, String principal) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); + buffer.append(""); + buffer.append(""); appendOutbox(buffer, principal, request); - buffer.append("\n"); + buffer.append(""); sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); } public void sendCalendar(CaldavRequest request, int depth, String principal) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); + buffer.append(""); + buffer.append(""); appendCalendar(buffer, principal, request); if (depth == 1) { DavGatewayTray.debug("Searching calendar events..."); @@ -414,7 +414,7 @@ public class CaldavConnection extends AbstractConnection { DavGatewayTray.debug("Found "+events.size()+" calendar events"); appendEventsResponses(buffer, request, events); } - buffer.append("\n"); + buffer.append(""); sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); } @@ -452,18 +452,18 @@ public class CaldavConnection extends AbstractConnection { } StringBuilder buffer = new StringBuilder(); - buffer.append("\n" + - "\n"); + buffer.append("" + + ""); appendEventsResponses(buffer, request, events); // send not found events errors for (String href : notFound) { - buffer.append(" \n"); - buffer.append(" ").append(href).append("\n"); - buffer.append(" \n"); - buffer.append(" HTTP/1.1 404 Not Found\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("").append(href).append(""); + buffer.append(""); + buffer.append("HTTP/1.1 404 Not Found"); + buffer.append(""); + buffer.append(""); } buffer.append(""); @@ -472,104 +472,104 @@ public class CaldavConnection extends AbstractConnection { public void sendUserRoot(CaldavRequest request, int depth, String principal) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append("/users/").append(principal).append(""); + buffer.append(""); + buffer.append(""); if (request.hasProperty("resourcetype")) { - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); } if (request.hasProperty("displayname")) { - buffer.append(" ").append(principal).append(""); + buffer.append("").append(principal).append(""); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append("HTTP/1.1 200 OK"); + buffer.append(""); + buffer.append(""); if (depth == 1) { appendInbox(buffer, principal, request); appendOutbox(buffer, principal, request); appendCalendar(buffer, principal, request); } - buffer.append("\n"); + buffer.append(""); sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); } public void sendRoot(CaldavRequest request) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); - buffer.append(" \n"); - buffer.append(" /\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append("/"); + buffer.append(""); + buffer.append(""); if (request.hasProperty("principal-collection-set")) { - buffer.append(" \n"); - buffer.append(" /principals/users/").append(session.getEmail()).append("\n"); - buffer.append(" "); + buffer.append(""); + buffer.append("/principals/users/").append(session.getEmail()).append(""); + buffer.append(""); } if (request.hasProperty("displayname")) { - buffer.append(" ROOT"); + buffer.append("ROOT"); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append("\n"); + 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); } public void sendPrincipal(CaldavRequest request, String principal) throws IOException { StringBuilder buffer = new StringBuilder(); - buffer.append("\n"); - buffer.append("\n"); - buffer.append(" \n"); - buffer.append(" /principals/users/").append(principal).append("\n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append("/principals/users/").append(principal).append(""); + buffer.append(""); + buffer.append(""); if (request.hasProperty("calendar-home-set")) { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("\n"); - buffer.append(" "); + buffer.append(""); + buffer.append("/users/").append(principal).append(""); + buffer.append(""); } if (request.hasProperty("calendar-user-address-set")) { - buffer.append(" \n"); - buffer.append(" mailto:").append(principal).append("\n"); - buffer.append(" "); + buffer.append(""); + buffer.append("mailto:").append(principal).append(""); + buffer.append(""); } if (request.hasProperty("schedule-inbox-URL")) { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("/inbox\n"); - buffer.append(" "); + buffer.append(""); + buffer.append("/users/").append(principal).append("/inbox"); + buffer.append(""); } if (request.hasProperty("schedule-outbox-URL")) { - buffer.append(" \n"); - buffer.append(" /users/").append(principal).append("/outbox\n"); - buffer.append(" "); + buffer.append(""); + buffer.append("/users/").append(principal).append("/outbox"); + buffer.append(""); } if (request.hasProperty("displayname")) { - buffer.append(" ").append(principal).append(""); + buffer.append("").append(principal).append(""); } if (request.hasProperty("resourcetype")) { - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append(" \n"); + buffer.append(""); + buffer.append(""); + buffer.append(""); + buffer.append(""); } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); - buffer.append("\n"); + 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); } @@ -601,15 +601,14 @@ public class CaldavConnection extends AbstractConnection { } String freeBusy = session.getFreebusy(valueMap); if (freeBusy != null) { - String response = "\n" + - " \n" + - " \n" + - " \n" + - " " + valueMap.get("ATTENDEE") + "\n" + - " \n" + - " 2.0;Success\n" + - " BEGIN:VCALENDAR\n" + + String response = "" + + "" + + "" + + "" + + "" + valueMap.get("ATTENDEE") + "" + + "" + + "2.0;Success" + + "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n" + "METHOD:REPLY\n" + @@ -623,9 +622,9 @@ public class CaldavConnection extends AbstractConnection { "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:" + freeBusy + "\n" + "END:VFREEBUSY\n" + "END:VCALENDAR" + - "\n" + - " \n" + - " "; + "" + + "" + + ""; sendHttpResponse(HttpStatus.SC_OK, null, "text/xml;charset=UTF-8", response, true); } else { sendHttpResponse(HttpStatus.SC_NOT_FOUND, null, "text/plain", "Unknown recipient: " + valueMap.get("ATTENDEE"), true);