diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java index be38673c2..322d6f5a5 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -364,8 +364,24 @@ public class MessagingController { put("refreshFolderList", null, () -> refreshFolderListSynchronous(account)); } - @Deprecated - public void refreshFolderListSynchronous(Account account) { + public void refreshFolderListBlocking(Account account) { + final CountDownLatch latch = new CountDownLatch(1); + putBackground("refreshFolderListBlocking", null, () -> { + try { + refreshFolderListSynchronous(account); + } finally { + latch.countDown(); + } + }); + + try { + latch.await(); + } catch (Exception e) { + Timber.e(e, "Interrupted while awaiting latch release"); + } + } + + void refreshFolderListSynchronous(Account account) { try { if (isAuthenticationProblem(account, true)) { Timber.d("Authentication will fail. Skip refreshing the folder list."); diff --git a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt index 2f23ab7dc..09d611f29 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt @@ -8,6 +8,7 @@ import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCrea import com.fsck.k9.Account.FolderMode import com.fsck.k9.Core import com.fsck.k9.Preferences +import com.fsck.k9.controller.MessagingController import com.fsck.k9.logging.Timber import com.fsck.k9.mail.ServerSettings import com.fsck.k9.mail.store.imap.ImapStoreSettings.autoDetectNamespace @@ -27,6 +28,7 @@ class AccountCreator( private val localFoldersCreator: SpecialLocalFoldersCreator, private val preferences: Preferences, private val context: Context, + private val messagingController: MessagingController, private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO, ) : AccountSetupExternalContract.AccountCreator { @@ -73,6 +75,8 @@ class AccountCreator( Core.setServicesEnabled(context) + messagingController.refreshFolderListBlocking(newAccount) + return newAccount.uuid } } diff --git a/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt b/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt index e0761974b..c300880d1 100644 --- a/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt +++ b/app/k9mail/src/main/java/com/fsck/k9/account/AccountModule.kt @@ -26,6 +26,7 @@ val newAccountModule = module { localFoldersCreator = get(), preferences = get(), context = androidApplication(), + messagingController = get(), ) }