IMAP: improve public folder error handling

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@756 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-09-25 11:50:46 +00:00
parent f377b76d45
commit 6ba6dadaae
3 changed files with 35 additions and 16 deletions

View File

@ -139,16 +139,7 @@ public class ImapConnection extends AbstractConnection {
List<ExchangeSession.Folder> folders = session.getSubFolders(folderQuery.substring(0, folderQuery.length() - 3), false);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderPath) + '\"');
try {
List<ExchangeSession.Folder> subfolders = session.getSubFolders(folder.folderPath, false);
for (ExchangeSession.Folder subfolder : subfolders) {
sendClient("* " + command + " (" + subfolder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(subfolder.folderPath) + '\"');
}
} catch (HttpForbiddenException e) {
// access forbidden, ignore
} catch (HttpNotFoundException e) {
// not found, ignore
}
sendSubFolders(command, folder.folderPath, false);
}
sendClient(commandId + " OK " + command + " completed");
} else if (folderQuery.endsWith("%") || folderQuery.endsWith("*")) {
@ -160,10 +151,7 @@ public class ImapConnection extends AbstractConnection {
sendClient("* " + command + " (\\HasChildren) \"/\" \"/public\"");
}
boolean recursive = folderQuery.endsWith("*") && !folderQuery.startsWith("/public");
List<ExchangeSession.Folder> folders = session.getSubFolders(folderQuery.substring(0, folderQuery.length() - 1), recursive);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderPath) + '\"');
}
sendSubFolders(command, folderQuery.substring(0, folderQuery.length() - 1), recursive);
sendClient(commandId + " OK " + command + " completed");
} else {
ExchangeSession.Folder folder = null;
@ -171,8 +159,13 @@ public class ImapConnection extends AbstractConnection {
folder = session.getFolder(folderQuery);
} catch (HttpForbiddenException e) {
// access forbidden, ignore
DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_ACCESS_FORBIDDEN", folderQuery));
} catch (HttpNotFoundException e) {
// not found, ignore
DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_NOT_FOUND", folderQuery));
} catch (HttpException e) {
// other errors, ignore
DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_ACCESS_ERROR", folderQuery, e.getMessage()));
}
if (folder != null) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderPath) + '\"');
@ -717,6 +710,24 @@ public class ImapConnection extends AbstractConnection {
}
}
protected void sendSubFolders(String command, String folderPath, boolean recursive) throws IOException {
try {
List<ExchangeSession.Folder> folders = session.getSubFolders(folderPath, recursive);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderPath) + '\"');
}
} catch (HttpForbiddenException e) {
// access forbidden, ignore
DavGatewayTray.debug(new BundleMessage("LOG_SUBFOLDER_ACCESS_FORBIDDEN", folderPath));
} catch (HttpNotFoundException e) {
// not found, ignore
DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_NOT_FOUND", folderPath));
} catch (HttpException e) {
// other errors, ignore
DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_ACCESS_ERROR", folderPath, e.getMessage()));
}
}
static final class SearchConditions {
Boolean flagged;
Boolean answered;

View File

@ -226,4 +226,8 @@ UI_UNTRUSTED_CERTIFICATE_HTML=<html><b>Server provided an untrusted certificate,
UI_VALID_FROM=Valid from
UI_VALID_UNTIL=Valid until
MEETING_REQUEST=Meeting request
LOG_EXCEPTION_CLOSING_KEYSTORE_INPUT_STREAM=Exception closing keystore input stream
LOG_EXCEPTION_CLOSING_KEYSTORE_INPUT_STREAM=Exception closing keystore input stream
LOG_SUBFOLDER_ACCESS_FORBIDDEN=Subfolder access forbidden to {0}
LOG_FOLDER_NOT_FOUND=Folder {0} not found
LOG_FOLDER_ACCESS_FORBIDDEN=Folder access to {0} forbidden
LOG_FOLDER_ACCESS_ERROR=Folder access to {0} error: {1}

View File

@ -226,4 +226,8 @@ LOG_ACCESS_FORBIDDEN=Acc
LOG_LDAP_REQ_BIND_INVALID_CREDENTIALS=LDAP_REQ_BIND Utilisateur ou mot de passe invalide
LOG_LDAP_REQ_BIND_SUCCESS=LOG_LDAP_REQ_BIND Authentification réussie
EXCEPTION_GET_FAILED=La requête GET a échoué avec le statut {0} à l''adresse {1}
LOG_EXCEPTION_CLOSING_KEYSTORE_INPUT_STREAM=Erreur à la fermeture du flux d''entrée du fichier de clés
LOG_EXCEPTION_CLOSING_KEYSTORE_INPUT_STREAM=Erreur à la fermeture du flux d''entrée du fichier de clés
LOG_SUBFOLDER_ACCESS_FORBIDDEN=Accès interdit au sous dossiers de {0}
LOG_FOLDER_ACCESS_FORBIDDEN=Accès interdit au dossier {0}
LOG_FOLDER_NOT_FOUND=Dossier {0} introuvable
LOG_FOLDER_ACCESS_ERROR=Erreur lors de l''accès au dossier {0} : {1}