use of com.fsck.k9.mailstore.LocalFolder 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.LocalFolder in project k-9 by k9mail.
the class MessagingController method checkMailForAccount.
private void checkMailForAccount(Account account, boolean ignoreLastCheckedTime, boolean notify, MessagingListener listener) {
Timber.i("Synchronizing account %s", account);
NotificationState notificationState = new NotificationState();
sendPendingMessages(account, listener);
refreshFolderListIfStale(account);
try {
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
Account.FolderMode aSyncMode = account.getFolderSyncMode();
LocalStore localStore = localStoreProvider.getInstance(account);
for (final LocalFolder folder : localStore.getPersonalNamespaces(false)) {
folder.open();
FolderClass fDisplayClass = folder.getDisplayClass();
FolderClass fSyncClass = folder.getSyncClass();
if (LocalFolder.isModeMismatch(aDisplayMode, fDisplayClass)) {
// Never sync a folder that isn't displayed
continue;
}
if (LocalFolder.isModeMismatch(aSyncMode, fSyncClass)) {
// Do not sync folders in the wrong class
continue;
}
synchronizeFolder(account, folder, ignoreLastCheckedTime, notify, listener, notificationState);
}
} catch (MessagingException e) {
Timber.e(e, "Unable to synchronize account %s", account);
} finally {
putBackground("clear notification flag for " + account, null, new Runnable() {
@Override
public void run() {
Timber.v("Clearing notification flag for %s", account);
clearFetchingMailNotification(account);
if (getUnreadMessageCount(account) == 0) {
notificationController.clearNewMailNotifications(account, false);
}
}
});
}
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingControllerTest method searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage.
@Test
public void searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage() throws Exception {
LocalMessage localMessage = mock(LocalMessage.class);
when(localMessage.getFolder()).thenReturn(localFolder);
when(search.searchAllAccounts()).thenReturn(true);
when(search.getAccountUuids()).thenReturn(new String[0]);
when(localStore.searchForMessages(nullable(MessageRetrievalListener.class), eq(search))).thenThrow(new MessagingException("Test"));
controller.searchLocalMessagesSynchronous(search, listener);
verify(localStore).searchForMessages(messageRetrievalListenerCaptor.capture(), eq(search));
messageRetrievalListenerCaptor.getValue().messageFinished(localMessage, 1, 1);
verify(listener).listLocalMessagesAddMessages(eq(account), eq((String) null), eq(Collections.singletonList(localMessage)));
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method moveOrDeleteSentMessage.
private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalFolder localFolder, LocalMessage message) throws MessagingException {
if (!account.hasSentFolder()) {
Timber.i("Account does not have a sent mail folder; deleting sent message");
message.setFlag(Flag.DELETED, true);
} else {
LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName());
Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid());
queuePendingCommand(account, command);
processPendingCommands(account);
}
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method searchRemoteMessagesSynchronous.
@VisibleForTesting
void searchRemoteMessagesSynchronous(final String acctUuid, final String folderName, final String query, final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags, final MessagingListener listener) {
final Account acct = Preferences.getPreferences(context).getAccount(acctUuid);
if (listener != null) {
listener.remoteSearchStarted(folderName);
}
List<Message> extraResults = new ArrayList<>();
try {
Store remoteStore = acct.getRemoteStore();
LocalStore localStore = acct.getLocalStore();
if (remoteStore == null || localStore == null) {
throw new MessagingException("Could not get store");
}
Folder remoteFolder = remoteStore.getFolder(folderName);
LocalFolder localFolder = localStore.getFolder(folderName);
if (remoteFolder == null || localFolder == null) {
throw new MessagingException("Folder not found");
}
List<Message> messages = remoteFolder.search(query, requiredFlags, forbiddenFlags);
Timber.i("Remote search got %d results", messages.size());
// There's no need to fetch messages already completely downloaded
List<Message> remoteMessages = localFolder.extractNewMessages(messages);
messages.clear();
if (listener != null) {
listener.remoteSearchServerQueryComplete(folderName, remoteMessages.size(), acct.getRemoteSearchNumResults());
}
Collections.sort(remoteMessages, new UidReverseComparator());
int resultLimit = acct.getRemoteSearchNumResults();
if (resultLimit > 0 && remoteMessages.size() > resultLimit) {
extraResults = remoteMessages.subList(resultLimit, remoteMessages.size());
remoteMessages = remoteMessages.subList(0, resultLimit);
}
loadSearchResultsSynchronous(remoteMessages, localFolder, remoteFolder, listener);
} catch (Exception e) {
if (Thread.currentThread().isInterrupted()) {
Timber.i(e, "Caught exception on aborted remote search; safe to ignore.");
} else {
Timber.e(e, "Could not complete remote search");
if (listener != null) {
listener.remoteSearchFailed(null, e.getMessage());
}
addErrorMessage(acct, null, e);
}
} finally {
if (listener != null) {
listener.remoteSearchFinished(folderName, 0, acct.getRemoteSearchNumResults(), extraResults);
}
}
}
Aggregations