use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class SqlQueryBuilder method getFolderId.
private static long getFolderId(Account account, String folderName) {
long folderId = 0;
try {
LocalStore localStore = account.getLocalStore();
LocalFolder folder = localStore.getFolder(folderName);
folder.open(Folder.OPEN_MODE_RO);
folderId = folder.getId();
} catch (MessagingException e) {
//FIXME
e.printStackTrace();
}
return folderId;
}
use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MessagingController method loadMessageMetadata.
public LocalMessage loadMessageMetadata(Account account, long folderId, String uid) throws MessagingException {
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(folderId);
localFolder.open();
LocalMessage message = localFolder.getMessage(uid);
if (message == null || message.getDatabaseId() == 0) {
String folderName = localFolder.getName();
throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
}
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
localFolder.fetch(Collections.singletonList(message), fp, null);
return message;
}
use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MessagingController method deleteDraft.
public void deleteDraft(final Account account, long id) {
try {
Long folderId = account.getDraftsFolderId();
if (folderId == null) {
Timber.w("No Drafts folder configured. Can't delete draft.");
return;
}
LocalStore localStore = localStoreProvider.getInstance(account);
LocalFolder localFolder = localStore.getFolder(folderId);
localFolder.open();
String uid = localFolder.getMessageUidById(id);
if (uid != null) {
MessageReference messageReference = new MessageReference(account.getUuid(), folderId, uid);
deleteMessage(messageReference);
}
} catch (MessagingException me) {
Timber.e(me, "Error deleting draft");
}
}
use of com.fsck.k9.mailstore.LocalStore 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.LocalStore 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();
}
Aggregations