mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-14 06:58:19 -05:00
IMAP: Improve error handling, do not fail on message retrieval error, just send error message
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@870 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
618cc4a3ea
commit
d4cdc76721
35
src/java/davmail/exception/HttpServerErrorException.java
Normal file
35
src/java/davmail/exception/HttpServerErrorException.java
Normal file
@ -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 500 internal server error status.
|
||||
*/
|
||||
public class HttpServerErrorException extends HttpException {
|
||||
/**
|
||||
* HttpException with 500 internal server error status.
|
||||
*
|
||||
* @param message exception message
|
||||
*/
|
||||
public HttpServerErrorException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import davmail.Settings;
|
||||
import davmail.exception.DavMailException;
|
||||
import davmail.exception.HttpForbiddenException;
|
||||
import davmail.exception.HttpNotFoundException;
|
||||
import davmail.exception.HttpServerErrorException;
|
||||
import davmail.ui.tray.DavGatewayTray;
|
||||
import org.apache.commons.httpclient.*;
|
||||
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||
@ -389,14 +390,14 @@ public final class DavGatewayHttpClientFacade {
|
||||
}
|
||||
if (status != HttpStatus.SC_OK) {
|
||||
LOGGER.warn("GET failed with status " + status + " at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
||||
throw new DavMailException("EXCEPTION_GET_FAILED", status, method.getURI());
|
||||
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
||||
}
|
||||
// check for expired session
|
||||
if (followRedirects) {
|
||||
String queryString = method.getQueryString();
|
||||
if (queryString != null && queryString.contains("reason=2")) {
|
||||
LOGGER.warn("GET failed, session expired at " + method.getURI() + ": " + method.getResponseBodyAsString());
|
||||
throw new DavMailException("EXCEPTION_GET_FAILED", status, method.getURI());
|
||||
throw DavGatewayHttpClientFacade.buildHttpException(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,6 +425,8 @@ public final class DavGatewayHttpClientFacade {
|
||||
return new HttpForbiddenException(message.toString());
|
||||
} else if (status == HttpStatus.SC_NOT_FOUND) {
|
||||
return new HttpNotFoundException(message.toString());
|
||||
} else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
|
||||
return new HttpServerErrorException(message.toString());
|
||||
} else {
|
||||
return new HttpException(message.toString());
|
||||
}
|
||||
|
@ -257,7 +257,12 @@ public class ImapConnection extends AbstractConnection {
|
||||
while (uidRangeIterator.hasNext()) {
|
||||
DavGatewayTray.switchIcon();
|
||||
ExchangeSession.Message message = uidRangeIterator.next();
|
||||
handleFetch(message, uidRangeIterator.currentIndex, parameters);
|
||||
try {
|
||||
handleFetch(message, uidRangeIterator.currentIndex, parameters);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.log(e);
|
||||
sendClient(commandId + " NO Unable to retrieve message: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
sendClient(commandId + " OK UID FETCH completed");
|
||||
}
|
||||
@ -319,7 +324,13 @@ public class ImapConnection extends AbstractConnection {
|
||||
while (rangeIterator.hasNext()) {
|
||||
DavGatewayTray.switchIcon();
|
||||
ExchangeSession.Message message = rangeIterator.next();
|
||||
handleFetch(message, rangeIterator.currentIndex, parameters);
|
||||
try {
|
||||
handleFetch(message, rangeIterator.currentIndex, parameters);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.log(e);
|
||||
sendClient(commandId + " NO Unable to retrieve message: "+e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
sendClient(commandId + " OK FETCH completed");
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ EXCEPTION_INVALID_REQUEST=Invalid request: {0}
|
||||
EXCEPTION_INVALID_SEARCH_PARAMETERS=Invalid search parameters: {0}
|
||||
EXCEPTION_NETWORK_DOWN=All network interfaces down or host unreachable !
|
||||
EXCEPTION_UNABLE_TO_CREATE_MESSAGE=Unable to create message {0}: {1}{2}{3}
|
||||
EXCEPTION_GET_FAILED=Get request failed with status {0} at {1}
|
||||
EXCEPTION_UNABLE_TO_GET_FOLDER=Unable to get folder at {0}
|
||||
EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER=Unable to get mail folder at {0}
|
||||
EXCEPTION_UNABLE_TO_GET_PROPERTY=Unable to get property {0}
|
||||
|
Loading…
Reference in New Issue
Block a user