use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagingController method setFlag.
/**
* Set or remove a flag for a set of messages in a specific folder.
* <p>
* <p>
* The {@link Message} objects passed in are updated to reflect the new flag state.
* </p>
*
* @param account
* The account the folder containing the messages belongs to.
* @param folderName
* The name of the folder.
* @param messages
* The messages to change the flag for.
* @param flag
* The flag to change.
* @param newState
* {@code true}, if the flag should be set. {@code false} if it should be removed.
*/
public void setFlag(Account account, String folderName, List<? extends Message> messages, Flag flag, boolean newState) {
// TODO: Put this into the background, but right now some callers depend on the message
// objects being modified right after this method returns.
Folder localFolder = null;
try {
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folderName);
localFolder.open(Folder.OPEN_MODE_RW);
// Allows for re-allowing sending of messages that could not be sent
if (flag == Flag.FLAGGED && !newState && account.getOutboxFolderName().equals(folderName)) {
for (Message message : messages) {
String uid = message.getUid();
if (uid != null) {
sendCount.remove(uid);
}
}
}
// Update the messages in the local store
localFolder.setFlags(messages, Collections.singleton(flag), newState);
int unreadMessageCount = localFolder.getUnreadMessageCount();
for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folderName, unreadMessageCount);
}
// TODO: Skip the remote part for all local-only folders
if (account.getErrorFolderName().equals(folderName)) {
return;
}
List<String> uids = getUidsFromMessages(messages);
queueSetFlag(account, folderName, newState, flag, uids);
processPendingCommands(account);
} catch (MessagingException me) {
addErrorMessage(account, null, me);
throw new RuntimeException(me);
} finally {
closeFolder(localFolder);
}
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagingController method unsuppressMessages.
private void unsuppressMessages(Account account, List<? extends Message> messages) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
cache.unhideMessages(messages);
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagingController method processPendingSetFlag.
/**
* Processes a pending mark read or unread command.
*/
void processPendingSetFlag(PendingSetFlag command, Account account) throws MessagingException {
String folder = command.folder;
if (account.getErrorFolderName().equals(folder) || account.getOutboxFolderName().equals(folder)) {
return;
}
boolean newState = command.newState;
Flag flag = command.flag;
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(folder);
if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(flag)) {
return;
}
try {
remoteFolder.open(Folder.OPEN_MODE_RW);
if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
return;
}
List<Message> messages = new ArrayList<>();
for (String uid : command.uids) {
if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
messages.add(remoteFolder.getMessage(uid));
}
}
if (messages.isEmpty()) {
return;
}
remoteFolder.setFlags(messages, Collections.singleton(flag), newState);
} finally {
closeFolder(remoteFolder);
}
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagingController method evaluateMessageForDownload.
private void evaluateMessageForDownload(final Message message, final String folder, final LocalFolder localFolder, final Folder remoteFolder, final Account account, final List<Message> unsyncedMessages, final List<Message> syncFlagMessages, boolean flagSyncOnly) throws MessagingException {
if (message.isSet(Flag.DELETED)) {
Timber.v("Message with uid %s is marked as deleted", message.getUid());
syncFlagMessages.add(message);
return;
}
Message localMessage = localFolder.getMessage(message.getUid());
if (localMessage == null) {
if (!flagSyncOnly) {
if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
Timber.v("Message with uid %s has not yet been downloaded", message.getUid());
unsyncedMessages.add(message);
} else {
Timber.v("Message with uid %s is partially or fully downloaded", message.getUid());
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
localMessage = localFolder.getMessage(message.getUid());
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, message.isSet(Flag.X_DOWNLOADED_FULL));
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, message.isSet(Flag.X_DOWNLOADED_PARTIAL));
for (MessagingListener l : getListeners()) {
if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
}
}
} else if (!localMessage.isSet(Flag.DELETED)) {
Timber.v("Message with uid %s is present in the local store", message.getUid());
if (!localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
Timber.v("Message with uid %s is not downloaded, even partially; trying again", message.getUid());
unsyncedMessages.add(message);
} else {
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
if (newPushState != null) {
localFolder.setPushState(newPushState);
}
syncFlagMessages.add(message);
}
} else {
Timber.v("Local copy of message with uid %s is marked as deleted", message.getUid());
}
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessageListFragment method changeSort.
/**
* Change the sort type and sort order used for the message list.
*
* @param sortType
* Specifies which field to use for sorting the message list.
* @param sortAscending
* Specifies the sort order. If this argument is {@code null} the default search order
* for the sort type is used.
*/
// FIXME: Don't save the changes in the UI thread
private void changeSort(SortType sortType, Boolean sortAscending) {
this.sortType = sortType;
Account account = this.account;
if (account != null) {
account.setSortType(this.sortType);
if (sortAscending == null) {
this.sortAscending = account.isSortAscending(this.sortType);
} else {
this.sortAscending = sortAscending;
}
account.setSortAscending(this.sortType, this.sortAscending);
sortDateAscending = account.isSortAscending(SortType.SORT_DATE);
account.save(preferences);
} else {
K9.setSortType(this.sortType);
if (sortAscending == null) {
this.sortAscending = K9.isSortAscending(this.sortType);
} else {
this.sortAscending = sortAscending;
}
K9.setSortAscending(this.sortType, this.sortAscending);
sortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
StorageEditor editor = preferences.getStorage().edit();
K9.save(editor);
editor.commit();
}
reSort();
}
Aggregations