diff --git a/src/java/davmail/exception/LoginTimeoutException.java b/src/java/davmail/exception/LoginTimeoutException.java new file mode 100644 index 00000000..3cc92897 --- /dev/null +++ b/src/java/davmail/exception/LoginTimeoutException.java @@ -0,0 +1,35 @@ +/* + * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway + * Copyright (C) 2009 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.exception; + +import org.apache.commons.httpclient.HttpException; + +/** + * HttpException with 440 login timeout status. + */ +public class LoginTimeoutException extends HttpException { + /** + * HttpException with 550 login timeout status. + * + * @param message exception message + */ + public LoginTimeoutException(String message) { + super(message); + } +} diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 280f78fc..0529a17f 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -2435,6 +2435,10 @@ public class DavExchangeSession extends ExchangeSession { contentInputStream.close(); } + } catch (LoginTimeoutException e) { + // throw error on expired session + LOGGER.warn(e.getMessage()); + throw e; } catch (IOException e) { LOGGER.warn("Broken message at: " + message.messageUrl + " permanentUrl: " + message.permanentUrl + ", trying to rebuild from properties"); diff --git a/src/java/davmail/http/DavGatewayHttpClientFacade.java b/src/java/davmail/http/DavGatewayHttpClientFacade.java index cb26da8d..8790efcd 100644 --- a/src/java/davmail/http/DavGatewayHttpClientFacade.java +++ b/src/java/davmail/http/DavGatewayHttpClientFacade.java @@ -631,10 +631,6 @@ public final class DavGatewayHttpClientFacade { */ public static HttpException buildHttpException(HttpMethod method) { int status = method.getStatusCode(); - // 440 means forbidden on Exchange - if (status == 440) { - status = HttpStatus.SC_FORBIDDEN; - } StringBuilder message = new StringBuilder(); message.append(status).append(' ').append(method.getStatusText()); try { @@ -645,7 +641,10 @@ public final class DavGatewayHttpClientFacade { } catch (URIException e) { message.append(method.getPath()); } - if (status == HttpStatus.SC_FORBIDDEN) { + // 440 means forbidden on Exchange + if (status == 440) { + return new LoginTimeoutException(message.toString()); + } else if (status == HttpStatus.SC_FORBIDDEN) { return new HttpForbiddenException(message.toString()); } else if (status == HttpStatus.SC_NOT_FOUND) { return new HttpNotFoundException(message.toString());