Merge pull request #5926 from k9mail/create_outbox

Create Outbox if necessary when attempting to send a message
This commit is contained in:
cketti 2022-02-21 16:58:52 +01:00 committed by GitHub
commit e61666db81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import com.fsck.k9.backend.BackendManager
import com.fsck.k9.mailstore.LocalStoreProvider
import com.fsck.k9.mailstore.MessageStoreManager
import com.fsck.k9.mailstore.SaveMessageDataCreator
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator
import com.fsck.k9.notification.NotificationController
import com.fsck.k9.notification.NotificationStrategy
import org.koin.core.qualifier.named
@ -23,6 +24,7 @@ val controllerModule = module {
get<Preferences>(),
get<MessageStoreManager>(),
get<SaveMessageDataCreator>(),
get<SpecialLocalFoldersCreator>(),
get(named("controllerExtensions"))
)
}

View file

@ -78,6 +78,7 @@ import com.fsck.k9.mailstore.OutboxStateRepository;
import com.fsck.k9.mailstore.SaveMessageData;
import com.fsck.k9.mailstore.SaveMessageDataCreator;
import com.fsck.k9.mailstore.SendState;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
import com.fsck.k9.notification.NotificationController;
import com.fsck.k9.notification.NotificationStrategy;
import com.fsck.k9.search.LocalSearch;
@ -118,6 +119,7 @@ public class MessagingController {
private final Preferences preferences;
private final MessageStoreManager messageStoreManager;
private final SaveMessageDataCreator saveMessageDataCreator;
private final SpecialLocalFoldersCreator specialLocalFoldersCreator;
private final Thread controllerThread;
@ -143,7 +145,8 @@ public class MessagingController {
NotificationStrategy notificationStrategy, LocalStoreProvider localStoreProvider,
MessageCountsProvider messageCountsProvider, BackendManager backendManager,
Preferences preferences, MessageStoreManager messageStoreManager,
SaveMessageDataCreator saveMessageDataCreator, List<ControllerExtension> controllerExtensions) {
SaveMessageDataCreator saveMessageDataCreator, SpecialLocalFoldersCreator specialLocalFoldersCreator,
List<ControllerExtension> controllerExtensions) {
this.context = context;
this.notificationController = notificationController;
this.notificationStrategy = notificationStrategy;
@ -153,6 +156,7 @@ public class MessagingController {
this.preferences = preferences;
this.messageStoreManager = messageStoreManager;
this.saveMessageDataCreator = saveMessageDataCreator;
this.specialLocalFoldersCreator = specialLocalFoldersCreator;
controllerThread = new Thread(new Runnable() {
@Override
@ -1424,8 +1428,13 @@ public class MessagingController {
try {
Long outboxFolderId = account.getOutboxFolderId();
if (outboxFolderId == null) {
Timber.e("Error sending message. No Outbox folder configured.");
return;
if (BuildConfig.DEBUG) {
throw new AssertionError("Outbox does not exist");
}
Timber.w("Outbox does not exist");
outboxFolderId = specialLocalFoldersCreator.createOutbox(account);
}
message.setFlag(Flag.SEEN, true);
@ -1513,7 +1522,7 @@ public class MessagingController {
OutboxStateRepository outboxStateRepository = localStore.getOutboxStateRepository();
LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderId());
if (!localFolder.exists()) {
Timber.v("Outbox does not exist");
Timber.w("Outbox does not exist");
return;
}

View file

@ -50,6 +50,18 @@ class SpecialLocalFoldersCreator(
preferences.saveAccount(account)
}
fun createOutbox(account: Account): Long {
Timber.d("Creating Outbox folder")
val localStore = localStoreProvider.getInstance(account)
val outboxFolderId = localStore.createLocalFolder(OUTBOX_FOLDER_NAME, FolderType.OUTBOX)
account.outboxFolderId = outboxFolderId
preferences.saveAccount(account)
return outboxFolderId
}
private fun Account.isPop3() = incomingServerSettings.type == Protocols.POP3
companion object {

View file

@ -31,6 +31,7 @@ import com.fsck.k9.mailstore.OutboxState;
import com.fsck.k9.mailstore.OutboxStateRepository;
import com.fsck.k9.mailstore.SaveMessageDataCreator;
import com.fsck.k9.mailstore.SendState;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
import com.fsck.k9.notification.NotificationController;
import com.fsck.k9.notification.NotificationStrategy;
import com.fsck.k9.preferences.Protocols;
@ -84,6 +85,8 @@ public class MessagingControllerTest extends K9RobolectricTest {
@Mock
private SaveMessageDataCreator saveMessageDataCreator;
@Mock
private SpecialLocalFoldersCreator specialLocalFoldersCreator;
@Mock
private SimpleMessagingListener listener;
@Mock
private LocalSearch search;
@ -139,7 +142,7 @@ public class MessagingControllerTest extends K9RobolectricTest {
controller = new MessagingController(appContext, notificationController, notificationStrategy,
localStoreProvider, messageCountsProvider, backendManager, preferences, messageStoreManager,
saveMessageDataCreator, Collections.<ControllerExtension>emptyList());
saveMessageDataCreator, specialLocalFoldersCreator, Collections.<ControllerExtension>emptyList());
configureAccount();
configureBackendManager();