use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.
the class MessagingController method processPendingEmptyTrash.
void processPendingEmptyTrash(Account account) throws MessagingException {
if (!account.hasTrashFolder()) {
return;
}
long trashFolderId = account.getTrashFolderId();
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder folder = localStore.getFolder(trashFolderId);
folder.open();
String trashFolderServerId = folder.getServerId();
Backend backend = getBackend(account);
backend.deleteAllMessages(trashFolderServerId);
if (account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY && backend.getSupportsExpunge()) {
backend.expunge(trashFolderServerId);
}
// Remove all messages marked as deleted
folder.destroyDeletedMessages();
compact(account, null);
}
use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.
the class MessagingControllerTest method sendPendingMessagesSynchronous_shouldSetAndRemoveSendInProgressFlag.
@Test
public void sendPendingMessagesSynchronous_shouldSetAndRemoveSendInProgressFlag() throws MessagingException {
setupAccountWithMessageToSend();
controller.sendPendingMessagesSynchronous(account);
InOrder ordering = inOrder(localMessageToSend1, backend);
ordering.verify(localMessageToSend1).setFlag(Flag.X_SEND_IN_PROGRESS, true);
ordering.verify(backend).sendMessage(localMessageToSend1);
ordering.verify(localMessageToSend1).setFlag(Flag.X_SEND_IN_PROGRESS, false);
}
use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.
the class MessagingController method loadSearchResultsSynchronous.
private void loadSearchResultsSynchronous(Account account, List<String> messageServerIds, LocalFolder localFolder) throws MessagingException {
Backend backend = getBackend(account);
String folderServerId = localFolder.getServerId();
for (String messageServerId : messageServerIds) {
LocalMessage localMessage = localFolder.getMessage(messageServerId);
if (localMessage == null) {
backend.downloadMessageStructure(folderServerId, messageServerId);
}
}
}
use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.
the class MessagingController method sendMessageBlocking.
public void sendMessageBlocking(Account account, Message message) throws MessagingException {
Backend backend = getBackend(account);
backend.sendMessage(message);
}
use of com.fsck.k9.backend.api.Backend in project k-9 by k9mail.
the class MessagingController method processPendingMoveOrCopy.
@VisibleForTesting
void processPendingMoveOrCopy(Account account, long srcFolderId, long destFolderId, List<String> uids, MoveOrCopyFlavor operation, Map<String, String> newUidMap) throws MessagingException {
checkNotNull(newUidMap);
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localSourceFolder = localStore.getFolder(srcFolderId);
localSourceFolder.open();
String srcFolderServerId = localSourceFolder.getServerId();
LocalFolder localDestFolder = localStore.getFolder(destFolderId);
localDestFolder.open();
String destFolderServerId = localDestFolder.getServerId();
Backend backend = getBackend(account);
Map<String, String> remoteUidMap;
switch(operation) {
case COPY:
remoteUidMap = backend.copyMessages(srcFolderServerId, destFolderServerId, uids);
break;
case MOVE:
remoteUidMap = backend.moveMessages(srcFolderServerId, destFolderServerId, uids);
break;
case MOVE_AND_MARK_AS_READ:
remoteUidMap = backend.moveMessagesAndMarkAsRead(srcFolderServerId, destFolderServerId, uids);
break;
default:
throw new RuntimeException("Unsupported messaging operation");
}
if (operation != MoveOrCopyFlavor.COPY) {
if (backend.getSupportsExpunge() && account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY) {
Timber.i("processingPendingMoveOrCopy expunging folder %s:%s", account, srcFolderServerId);
backend.expungeMessages(srcFolderServerId, uids);
}
destroyPlaceholderMessages(localSourceFolder, uids);
}
// TODO: Change Backend interface to ensure we never receive null for remoteUidMap
if (remoteUidMap == null) {
remoteUidMap = Collections.emptyMap();
}
// Update local messages (that currently have local UIDs) with new server IDs
for (String uid : uids) {
String localUid = newUidMap.get(uid);
String newUid = remoteUidMap.get(uid);
LocalMessage localMessage = localDestFolder.getMessage(localUid);
if (localMessage == null) {
// Local message no longer exists
continue;
}
if (newUid != null) {
// Update local message with new server ID
localMessage.setUid(newUid);
localDestFolder.changeUid(localMessage);
for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, destFolderId, localUid, newUid);
}
} else {
// New server ID wasn't provided. Remove local message.
localMessage.destroy();
}
}
}
Aggregations