From dd648bbf54043d2bafc4a5ec8803704f256e2883 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 22 Nov 2010 09:36:12 +0000 Subject: [PATCH] Workaround for malformed cookies with space in name git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1548 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/http/DavMailCookieSpec.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/java/davmail/http/DavMailCookieSpec.java b/src/java/davmail/http/DavMailCookieSpec.java index e8949847..bae768b0 100644 --- a/src/java/davmail/http/DavMailCookieSpec.java +++ b/src/java/davmail/http/DavMailCookieSpec.java @@ -28,14 +28,24 @@ import org.apache.commons.httpclient.cookie.RFC2109Spec; public class DavMailCookieSpec extends RFC2109Spec { @Override public void validate(String host, int port, String path, - boolean secure, final Cookie cookie) throws MalformedCookieException { + boolean secure, final Cookie cookie) throws MalformedCookieException { + String cookieName = cookie.getName(); + if (cookieName != null && cookieName.indexOf(' ') >= 0) { + cookie.setName(cookieName.replaceAll(" ", "")); + } else { + cookieName = null; + } String hostWithoutDomain = host.substring(0, host.length() - - cookie.getDomain().length()); - if (hostWithoutDomain.indexOf('.') != -1) { + - cookie.getDomain().length()); + int dotIndex = hostWithoutDomain.indexOf('.'); + if (dotIndex != -1) { // discard additional host name part - super.validate(host.substring(hostWithoutDomain.indexOf('.')+1), port, path, secure, cookie); + super.validate(host.substring(dotIndex + 1), port, path, secure, cookie); } else { super.validate(host, port, path, secure, cookie); } + if (cookieName != null) { + cookie.setName(cookieName); + } } }