Search in sources :

Example 31 with MessageReference

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;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(com.fsck.k9.activity.MessageReference)

Example 32 with MessageReference

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;
}
Also used : Account(com.fsck.k9.Account) Toast(android.widget.Toast) MessageReference(com.fsck.k9.activity.MessageReference)

Example 33 with MessageReference

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);
}
Also used : Cursor(android.database.Cursor) MessageReference(com.fsck.k9.activity.MessageReference)

Example 34 with MessageReference

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);
        }
    }
}
Also used : Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with MessageReference

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);
            }
        }
    }
}
Also used : Account(com.fsck.k9.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) MessageReference(com.fsck.k9.activity.MessageReference) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Aggregations

MessageReference (com.fsck.k9.activity.MessageReference)54 PendingIntent (android.app.PendingIntent)25 Account (com.fsck.k9.Account)18 Test (org.junit.Test)14 NotificationCompat (android.support.v4.app.NotificationCompat)9 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)8 List (java.util.List)7 HashMap (java.util.HashMap)5 SearchAccount (com.fsck.k9.search.SearchAccount)4 Cursor (android.database.Cursor)3 Preferences (com.fsck.k9.Preferences)3 MessagingException (com.fsck.k9.mail.MessagingException)3 LocalFolder (com.fsck.k9.mailstore.LocalFolder)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Message (com.fsck.k9.mail.Message)2