1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package davmail.http;
20
21 import org.apache.commons.httpclient.Cookie;
22 import org.apache.commons.httpclient.cookie.MalformedCookieException;
23 import org.apache.commons.httpclient.cookie.RFC2109Spec;
24
25
26
27
28 public class DavMailCookieSpec extends RFC2109Spec {
29 @Override
30 public void validate(String host, int port, String path,
31 boolean secure, final Cookie cookie) throws MalformedCookieException {
32
33 String cookieName = cookie.getName();
34 if (cookieName != null && cookieName.indexOf(' ') >= 0) {
35 cookie.setName(cookieName.replaceAll(" ", ""));
36 } else {
37 cookieName = null;
38 }
39
40 String cookiePath = cookie.getPath();
41 if (cookiePath != null && !path.startsWith(cookiePath)) {
42 cookie.setPath(path);
43 } else {
44 cookiePath = null;
45 }
46
47 int dotIndex = -1;
48 if (host.endsWith(cookie.getDomain())) {
49 String hostWithoutDomain = host.substring(0, host.length()
50 - cookie.getDomain().length());
51 dotIndex = hostWithoutDomain.indexOf('.');
52 }
53 if (".login.microsoftonline.com".equals(cookie.getDomain())) {
54 cookie.setDomain(host);
55 }
56 if (dotIndex != -1) {
57
58 super.validate(host.substring(dotIndex + 1), port, path, secure, cookie);
59 } else {
60 super.validate(host, port, path, secure, cookie);
61 }
62 if (cookieName != null) {
63 cookie.setName(cookieName);
64 }
65 if (cookiePath != null) {
66 cookie.setPath(cookiePath);
67 }
68 }
69 }