Move authentication failure handling out of ImapSync
This commit is contained in:
parent
8ea215117d
commit
ddfe93cab5
4 changed files with 11 additions and 11 deletions
|
@ -4199,9 +4199,13 @@ public class MessagingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncFailed(@NotNull String folderServerId, @NotNull String message) {
|
public void syncFailed(@NotNull String folderServerId, @NotNull String message, Exception exception) {
|
||||||
syncFailed = true;
|
syncFailed = true;
|
||||||
|
|
||||||
|
if (exception instanceof AuthenticationFailedException) {
|
||||||
|
handleAuthenticationFailure(account, true);
|
||||||
|
}
|
||||||
|
|
||||||
for (MessagingListener messagingListener : getListeners(listener)) {
|
for (MessagingListener messagingListener : getListeners(listener)) {
|
||||||
messagingListener.synchronizeMailboxFailed(account, folderServerId, message);
|
messagingListener.synchronizeMailboxFailed(account, folderServerId, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ interface SyncListener {
|
||||||
fun syncRemovedMessage(folderServerId: String, message: Message)
|
fun syncRemovedMessage(folderServerId: String, message: Message)
|
||||||
|
|
||||||
fun syncFinished(folderServerId: String, totalMessagesInMailbox: Int, numNewMessages: Int)
|
fun syncFinished(folderServerId: String, totalMessagesInMailbox: Int, numNewMessages: Int)
|
||||||
fun syncFailed(folderServerId: String, message: String)
|
fun syncFailed(folderServerId: String, message: String, exception: Exception?)
|
||||||
|
|
||||||
fun folderStatusChanged(folderServerId: String, unreadMessageCount: Int)
|
fun folderStatusChanged(folderServerId: String, unreadMessageCount: Int)
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,9 +251,7 @@ class ImapSync {
|
||||||
Timber.i("Done synchronizing folder %s:%s", account.getDescription(), folder);
|
Timber.i("Done synchronizing folder %s:%s", account.getDescription(), folder);
|
||||||
|
|
||||||
} catch (AuthenticationFailedException e) {
|
} catch (AuthenticationFailedException e) {
|
||||||
handleAuthenticationFailure(account, true);
|
listener.syncFailed(folder, "Authentication failure", e);
|
||||||
|
|
||||||
listener.syncFailed(folder, "Authentication failure");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Timber.e(e, "synchronizeMailbox");
|
Timber.e(e, "synchronizeMailbox");
|
||||||
// If we don't set the last checked, it can try too often during
|
// If we don't set the last checked, it can try too often during
|
||||||
|
@ -269,7 +267,7 @@ class ImapSync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listener.syncFailed(folder, rootMessage);
|
listener.syncFailed(folder, rootMessage, e);
|
||||||
|
|
||||||
notifyUserIfCertificateProblem(account, e, true);
|
notifyUserIfCertificateProblem(account, e, true);
|
||||||
Timber.e("Failed synchronizing folder %s:%s @ %tc", account.getDescription(), folder,
|
Timber.e("Failed synchronizing folder %s:%s @ %tc", account.getDescription(), folder,
|
||||||
|
@ -815,10 +813,6 @@ class ImapSync {
|
||||||
controller.updateMoreMessages(remoteFolder, localFolder, earliestDate, remoteStart);
|
controller.updateMoreMessages(remoteFolder, localFolder, earliestDate, remoteStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAuthenticationFailure(Account account, boolean incoming) {
|
|
||||||
controller.handleAuthenticationFailure(account, incoming);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyUserIfCertificateProblem(Account account, Exception exception, boolean incoming) {
|
private void notifyUserIfCertificateProblem(Account account, Exception exception, boolean incoming) {
|
||||||
controller.notifyUserIfCertificateProblem(account, exception, incoming);
|
controller.notifyUserIfCertificateProblem(account, exception, incoming);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.robolectric.shadows.ShadowLog;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
@ -121,7 +122,8 @@ public class ImapSyncTest extends RobolectricTest {
|
||||||
|
|
||||||
imapSync.sync(account, FOLDER_NAME, listener, remoteFolder);
|
imapSync.sync(account, FOLDER_NAME, listener, remoteFolder);
|
||||||
|
|
||||||
verify(listener).syncFailed(FOLDER_NAME, "Exception: Message count -1 for folder Folder");
|
verify(listener).syncFailed(eq(FOLDER_NAME), eq("Exception: Message count -1 for folder Folder"),
|
||||||
|
any(Exception.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue