mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-15 04:02:21 -05:00
IMAP: test session expiration on each command, get a new session on expiration
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@741 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
e9b6bc3ada
commit
393b283324
@ -124,6 +124,40 @@ public final class ExchangeSessionFactory {
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a non expired session.
|
||||||
|
* If the current session is not expired, return current session, else try to create a new session
|
||||||
|
*
|
||||||
|
* @param currentSession current session
|
||||||
|
* @param userName user login
|
||||||
|
* @param password user password
|
||||||
|
* @return authenticated session
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
|
public static ExchangeSession getInstance(ExchangeSession currentSession, String userName, String password)
|
||||||
|
throws IOException {
|
||||||
|
ExchangeSession session = currentSession;
|
||||||
|
try {
|
||||||
|
if (session.isExpired()) {
|
||||||
|
session = null;
|
||||||
|
String baseUrl = Settings.getProperty("davmail.url");
|
||||||
|
PoolKey poolKey = new PoolKey(baseUrl, userName, password);
|
||||||
|
// expired session, remove from cache
|
||||||
|
synchronized (LOCK) {
|
||||||
|
POOL_MAP.remove(poolKey);
|
||||||
|
}
|
||||||
|
session = getInstance(userName, password);
|
||||||
|
}
|
||||||
|
} catch (DavMailAuthenticationException exc) {
|
||||||
|
throw exc;
|
||||||
|
} catch (DavMailException exc) {
|
||||||
|
throw exc;
|
||||||
|
} catch (Exception exc) {
|
||||||
|
handleNetworkDown(exc);
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a request to Exchange server to check current settings.
|
* Send a request to Exchange server to check current settings.
|
||||||
*
|
*
|
||||||
|
@ -126,6 +126,8 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
if (state != State.AUTHENTICATED) {
|
if (state != State.AUTHENTICATED) {
|
||||||
sendClient(commandId + " BAD command authentication required");
|
sendClient(commandId + " BAD command authentication required");
|
||||||
} else {
|
} else {
|
||||||
|
// check for expired session
|
||||||
|
session = ExchangeSessionFactory.getInstance(session, userName, password);
|
||||||
if ("lsub".equalsIgnoreCase(command) || "list".equalsIgnoreCase(command)) {
|
if ("lsub".equalsIgnoreCase(command) || "list".equalsIgnoreCase(command)) {
|
||||||
if (tokens.hasMoreTokens()) {
|
if (tokens.hasMoreTokens()) {
|
||||||
String folderContext = BASE64MailboxDecoder.decode(tokens.nextToken());
|
String folderContext = BASE64MailboxDecoder.decode(tokens.nextToken());
|
||||||
|
Loading…
Reference in New Issue
Block a user