use of com.fsck.k9.mailstore.MessageStore in project k-9 by k9mail.
the class MessagingController method syncFolder.
private void syncFolder(Account account, long folderId, boolean notify, MessagingListener listener, Backend backend, NotificationState notificationState) {
ServerSettings serverSettings = account.getIncomingServerSettings();
if (serverSettings.isMissingCredentials()) {
handleAuthenticationFailure(account, true);
return;
}
Exception commandException = null;
try {
processPendingCommandsSynchronous(account);
} catch (Exception e) {
Timber.e(e, "Failure processing command, but allow message sync attempt");
commandException = e;
}
LocalFolder localFolder;
try {
LocalStore localStore = localStoreProvider.getInstance(account);
localFolder = localStore.getFolder(folderId);
localFolder.open();
} catch (MessagingException e) {
Timber.e(e, "syncFolder: Couldn't load local folder %d", folderId);
return;
}
// We can't sync local folders
if (localFolder.isLocalOnly()) {
return;
}
final boolean suppressNotifications;
if (notify) {
MessageStore messageStore = messageStoreManager.getMessageStore(account);
Long lastChecked = messageStore.getFolder(folderId, FolderDetailsAccessor::getLastChecked);
suppressNotifications = lastChecked == null;
} else {
suppressNotifications = true;
}
String folderServerId = localFolder.getServerId();
SyncConfig syncConfig = createSyncConfig(account);
ControllerSyncListener syncListener = new ControllerSyncListener(account, listener, suppressNotifications, notificationState);
backend.sync(folderServerId, syncConfig, syncListener);
if (commandException != null && !syncListener.syncFailed) {
String rootMessage = getRootCauseMessage(commandException);
Timber.e("Root cause failure in %s:%s was '%s'", account, folderServerId, rootMessage);
updateFolderStatus(account, folderServerId, rootMessage);
listener.synchronizeMailboxFailed(account, folderId, rootMessage);
}
}
use of com.fsck.k9.mailstore.MessageStore in project k-9 by k9mail.
the class MessagingController method getFolderId.
private long getFolderId(Account account, String folderServerId) {
MessageStore messageStore = messageStoreManager.getMessageStore(account);
Long folderId = messageStore.getFolderId(folderServerId);
if (folderId == null) {
throw new IllegalStateException("Folder not found (server ID: " + folderServerId + ")");
}
return folderId;
}
use of com.fsck.k9.mailstore.MessageStore in project k-9 by k9mail.
the class MessagingController method moveOrDeleteSentMessage.
private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalMessage message) throws MessagingException {
if (!account.hasSentFolder() || !account.isUploadSentMessages()) {
Timber.i("Not uploading sent message; deleting local message");
message.destroy();
} else {
long sentFolderId = account.getSentFolderId();
LocalFolder sentFolder = localStore.getFolder(sentFolderId);
sentFolder.open();
String sentFolderServerId = sentFolder.getServerId();
Timber.i("Moving sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
MessageStore messageStore = messageStoreManager.getMessageStore(account);
long destinationMessageId = messageStore.moveMessage(message.getDatabaseId(), sentFolderId);
Timber.i("Moved sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
if (!sentFolder.isLocalOnly()) {
String destinationUid = messageStore.getMessageServerId(destinationMessageId);
PendingCommand command = PendingAppend.create(sentFolderId, destinationUid);
queuePendingCommand(account, command);
processPendingCommands(account);
}
}
for (MessagingListener listener : getListeners()) {
listener.folderStatusChanged(account, account.getOutboxFolderId());
}
}
use of com.fsck.k9.mailstore.MessageStore in project k-9 by k9mail.
the class MessagingController method clearNewMessagesBlocking.
private void clearNewMessagesBlocking(Account account) {
MessageStore messageStore = messageStoreManager.getMessageStore(account);
messageStore.clearNewMessageState();
}
use of com.fsck.k9.mailstore.MessageStore in project k-9 by k9mail.
the class MessagingController method messagesPendingSend.
private boolean messagesPendingSend(final Account account) {
Long outboxFolderId = account.getOutboxFolderId();
if (outboxFolderId == null) {
Timber.w("Could not get Outbox folder ID from Account");
return false;
}
MessageStore messageStore = messageStoreManager.getMessageStore(account);
return messageStore.getMessageCount(outboxFolderId) > 0;
}
Aggregations