diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 7b6b0a35..2345cd00 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -143,11 +143,7 @@ public class CaldavConnection extends AbstractConnection { tokens = new StringTokenizer(line); String command = tokens.nextToken(); Map headers = parseHeaders(); - String encodedPath = tokens.nextToken(); - // make sure + sign in URL is encoded - if (encodedPath.indexOf('+') >= 0) { - encodedPath = encodedPath.replaceAll("\\+", "%2B"); - } + String encodedPath = encodePlusSign(tokens.nextToken()); String path = URIUtil.decode(encodedPath); String content = getContent(headers.get("content-length")); setSocketTimeout(headers.get("keep-alive")); @@ -236,8 +232,8 @@ public class CaldavConnection extends AbstractConnection { } } else if (request.isPath(2, "public")) { StringBuilder prefixBuffer = new StringBuilder("public"); - for (int i=3; i headers, String contentType, byte[] content, boolean keepAlive) throws IOException { sendClient("HTTP/1.1 " + status + ' ' + HttpStatus.getStatusText(status)); String version = DavGateway.getCurrentVersion(); - sendClient("Server: DavMail Gateway "+ (version==null?"":version)); + sendClient("Server: DavMail Gateway " + (version == null ? "" : version)); sendClient("DAV: 1, calendar-access, calendar-schedule, calendarserver-private-events, calendar-proxy"); SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH); String now = formatter.format(new Date()); @@ -1035,6 +1031,20 @@ public class CaldavConnection extends AbstractConnection { return result; } + /** + * Make sure + sign in URL is encoded. + * @param path URL path + * @return reencoded path + */ + protected String encodePlusSign(String path) { + // make sure + sign in URL is encoded + if (path.indexOf('+') >= 0) { + return path.replaceAll("\\+", "%2B"); + } else { + return path; + } + } + protected class CaldavRequest { protected final String command; protected final String path; @@ -1211,7 +1221,7 @@ public class CaldavConnection extends AbstractConnection { if (isIcal()) { hrefs.add(streamReader.getText()); } else { - hrefs.add(URIUtil.decode(streamReader.getText())); + hrefs.add(URIUtil.decode(encodePlusSign(streamReader.getText()))); } } inElement = false;