use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method setFlagSynchronous.
private void setFlagSynchronous(final Account account, final List<Long> ids, final Flag flag, final boolean newState, final boolean threadedList) {
LocalStore localStore;
try {
localStore = localStoreProvider.getInstance(account);
} catch (MessagingException e) {
Timber.e(e, "Couldn't get LocalStore instance");
return;
}
// can be updated with the new state.
try {
if (threadedList) {
localStore.setFlagForThreads(ids, flag, newState);
removeFlagForThreadsFromCache(account, ids, flag);
} else {
localStore.setFlag(ids, flag, newState);
removeFlagFromCache(account, ids, flag);
}
} catch (MessagingException e) {
Timber.e(e, "Couldn't set flags in local database");
}
// Read folder ID and UID of messages from the database
Map<Long, List<String>> folderMap;
try {
folderMap = localStore.getFolderIdsAndUids(ids, threadedList);
} catch (MessagingException e) {
Timber.e(e, "Couldn't get folder name and UID of messages");
return;
}
boolean accountSupportsFlags = supportsFlags(account);
// Loop over all folders
for (Entry<Long, List<String>> entry : folderMap.entrySet()) {
long folderId = entry.getKey();
List<String> uids = entry.getValue();
// Notify listeners of changed folder status
for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folderId);
}
if (flag == Flag.SEEN && newState) {
cancelNotificationsForMessages(account, folderId, uids);
}
if (accountSupportsFlags) {
LocalFolder localFolder = localStore.getFolder(folderId);
try {
localFolder.open();
if (!localFolder.isLocalOnly()) {
// Send flag change to server
queueSetFlag(account, folderId, newState, flag, uids);
processPendingCommands(account);
}
} catch (MessagingException e) {
Timber.e(e, "Couldn't open folder. Account: %s, folder ID: %d", account, folderId);
}
}
}
}
use of com.fsck.k9.mailstore.LocalFolder 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.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method getFolderUnreadMessageCount.
public int getFolderUnreadMessageCount(Account account, Long folderId) throws MessagingException {
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(folderId);
return localFolder.getUnreadMessageCount();
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method setFlag.
/**
* Set or remove a flag for a message referenced by message UID.
*/
public void setFlag(Account account, long folderId, String uid, Flag flag, boolean newState) {
try {
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(folderId);
localFolder.open();
LocalMessage message = localFolder.getMessage(uid);
if (message != null) {
setFlag(account, folderId, Collections.singletonList(message), flag, newState);
}
} catch (MessagingException me) {
throw new RuntimeException(me);
}
}
use of com.fsck.k9.mailstore.LocalFolder 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