2010-08-13 15:58:51 -04:00
|
|
|
/*
|
|
|
|
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
|
|
|
* Copyright (C) 2010 Mickael Guessant
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
package davmail.http;
|
|
|
|
|
|
|
|
import org.apache.commons.httpclient.Cookie;
|
|
|
|
import org.apache.commons.httpclient.cookie.MalformedCookieException;
|
|
|
|
import org.apache.commons.httpclient.cookie.RFC2109Spec;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom CookieSpec to allow extended domain names.
|
|
|
|
*/
|
|
|
|
public class DavMailCookieSpec extends RFC2109Spec {
|
2010-09-24 04:30:40 -04:00
|
|
|
@Override
|
2010-08-13 15:58:51 -04:00
|
|
|
public void validate(String host, int port, String path,
|
2010-11-22 04:36:12 -05:00
|
|
|
boolean secure, final Cookie cookie) throws MalformedCookieException {
|
2010-12-09 06:28:54 -05:00
|
|
|
// workaround for space in cookie name
|
2010-11-22 04:36:12 -05:00
|
|
|
String cookieName = cookie.getName();
|
|
|
|
if (cookieName != null && cookieName.indexOf(' ') >= 0) {
|
|
|
|
cookie.setName(cookieName.replaceAll(" ", ""));
|
|
|
|
} else {
|
|
|
|
cookieName = null;
|
|
|
|
}
|
2010-12-09 06:28:54 -05:00
|
|
|
// workaround for invalid cookie path
|
|
|
|
String cookiePath = cookie.getPath();
|
|
|
|
if (cookiePath != null && !path.startsWith(cookiePath)) {
|
|
|
|
cookie.setPath(path);
|
|
|
|
} else {
|
|
|
|
cookiePath = null;
|
|
|
|
}
|
2010-08-13 15:58:51 -04:00
|
|
|
String hostWithoutDomain = host.substring(0, host.length()
|
2010-11-22 04:36:12 -05:00
|
|
|
- cookie.getDomain().length());
|
|
|
|
int dotIndex = hostWithoutDomain.indexOf('.');
|
|
|
|
if (dotIndex != -1) {
|
2010-08-13 15:58:51 -04:00
|
|
|
// discard additional host name part
|
2010-11-22 04:36:12 -05:00
|
|
|
super.validate(host.substring(dotIndex + 1), port, path, secure, cookie);
|
2010-08-13 15:58:51 -04:00
|
|
|
} else {
|
|
|
|
super.validate(host, port, path, secure, cookie);
|
|
|
|
}
|
2010-11-22 04:36:12 -05:00
|
|
|
if (cookieName != null) {
|
|
|
|
cookie.setName(cookieName);
|
|
|
|
}
|
2010-12-09 06:28:54 -05:00
|
|
|
if (cookiePath != null) {
|
|
|
|
cookie.setPath(cookiePath);
|
|
|
|
}
|
2010-08-13 15:58:51 -04:00
|
|
|
}
|
|
|
|
}
|