use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.
the class LocalFolder method getMessagesByReference.
public List<LocalMessage> getMessagesByReference(@NonNull List<MessageReference> messageReferences) throws MessagingException {
open(OPEN_MODE_RW);
String accountUuid = getAccountUuid();
String folderName = getName();
List<LocalMessage> messages = new ArrayList<>();
for (MessageReference messageReference : messageReferences) {
if (!accountUuid.equals(messageReference.getAccountUuid())) {
throw new IllegalArgumentException("all message references must belong to this Account!");
}
if (!folderName.equals(messageReference.getFolderName())) {
throw new IllegalArgumentException("all message references must belong to this LocalFolder!");
}
LocalMessage message = getMessage(messageReference.getUid());
if (message != null) {
messages.add(message);
}
}
return messages;
}
use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.
the class MessageListFragment method checkCopyOrMovePossible.
/**
* Display a Toast message if any message isn't synchronized
*
* @param messages
* The messages to copy or move. Never {@code null}.
* @param operation
* The type of operation to perform. Never {@code null}.
*
* @return {@code true}, if operation is possible.
*/
private boolean checkCopyOrMovePossible(final List<MessageReference> messages, final FolderOperation operation) {
if (messages.isEmpty()) {
return false;
}
boolean first = true;
for (MessageReference message : messages) {
if (first) {
first = false;
Account account = preferences.getAccount(message.getAccountUuid());
if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(account)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(account))) {
return false;
}
}
// message check
if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(message)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(message))) {
final Toast toast = Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return false;
}
}
return true;
}
use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.
the class MessageListFragment method getMessageAtPosition.
private MessageReference getMessageAtPosition(int adapterPosition) {
if (adapterPosition == AdapterView.INVALID_POSITION) {
return null;
}
Cursor cursor = (Cursor) adapter.getItem(adapterPosition);
String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
String folderName = cursor.getString(FOLDER_NAME_COLUMN);
String messageUid = cursor.getString(UID_COLUMN);
return new MessageReference(accountUuid, folderName, messageUid, null);
}
use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.
the class MessageListFragment method onSpamConfirmed.
private void onSpamConfirmed(List<MessageReference> messages) {
Map<Account, List<MessageReference>> messagesByAccount = groupMessagesByAccount(messages);
for (Entry<Account, List<MessageReference>> entry : messagesByAccount.entrySet()) {
Account account = entry.getKey();
String spamFolder = account.getSpamFolderName();
if (!K9.FOLDER_NONE.equals(spamFolder)) {
move(entry.getValue(), spamFolder);
}
}
}
use of com.fsck.k9.activity.MessageReference in project k-9 by k9mail.
the class MessageListFragment method copyOrMove.
/**
* The underlying implementation for {@link #copy(List, String)} and
* {@link #move(List, String)}. This method was added mainly because those 2
* methods share common behavior.
*
* @param messages
* The list of messages to copy or move. Never {@code null}.
* @param destination
* The name of the destination folder. Never {@code null} or {@link K9#FOLDER_NONE}.
* @param operation
* Specifies what operation to perform. Never {@code null}.
*/
private void copyOrMove(List<MessageReference> messages, final String destination, final FolderOperation operation) {
Map<String, List<MessageReference>> folderMap = new HashMap<>();
for (MessageReference message : messages) {
if ((operation == FolderOperation.MOVE && !messagingController.isMoveCapable(message)) || (operation == FolderOperation.COPY && !messagingController.isCopyCapable(message))) {
Toast.makeText(getActivity(), R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG).show();
// message isn't synchronized
return;
}
String folderName = message.getFolderName();
if (folderName.equals(destination)) {
// Skip messages already in the destination folder
continue;
}
List<MessageReference> outMessages = folderMap.get(folderName);
if (outMessages == null) {
outMessages = new ArrayList<>();
folderMap.put(folderName, outMessages);
}
outMessages.add(message);
}
for (Map.Entry<String, List<MessageReference>> entry : folderMap.entrySet()) {
String folderName = entry.getKey();
List<MessageReference> outMessages = entry.getValue();
Account account = preferences.getAccount(outMessages.get(0).getAccountUuid());
if (operation == FolderOperation.MOVE) {
if (showingThreadedList) {
messagingController.moveMessagesInThread(account, folderName, outMessages, destination);
} else {
messagingController.moveMessages(account, folderName, outMessages, destination);
}
} else {
if (showingThreadedList) {
messagingController.copyMessagesInThread(account, folderName, outMessages, destination);
} else {
messagingController.copyMessages(account, folderName, outMessages, destination);
}
}
}
}
Aggregations