Search in sources :

Example 36 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class MessageListFragment method getCheckedMessages.

private List<MessageReference> getCheckedMessages() {
    List<MessageReference> messages = new ArrayList<>(selected.size());
    for (int position = 0, end = adapter.getCount(); position < end; position++) {
        Cursor cursor = (Cursor) adapter.getItem(position);
        long uniqueId = cursor.getLong(uniqueIdColumn);
        if (selected.contains(uniqueId)) {
            MessageReference message = getMessageAtPosition(position);
            if (message != null) {
                messages.add(message);
            }
        }
    }
    return messages;
}
Also used : ArrayList(java.util.ArrayList) MessageReference(com.fsck.k9.activity.MessageReference) Cursor(android.database.Cursor)

Example 37 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class MessageListFragment method groupMessagesByAccount.

private Map<Account, List<MessageReference>> groupMessagesByAccount(final List<MessageReference> messages) {
    Map<Account, List<MessageReference>> messagesByAccount = new HashMap<>();
    for (MessageReference message : messages) {
        Account account = preferences.getAccount(message.getAccountUuid());
        List<MessageReference> msgList = messagesByAccount.get(account);
        if (msgList == null) {
            msgList = new ArrayList<>();
            messagesByAccount.put(account, msgList);
        }
        msgList.add(message);
    }
    return messagesByAccount;
}
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)

Example 38 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class LocalFolder method loadMessageParts.

private void loadMessageParts(SQLiteDatabase db, LocalMessage message) throws MessagingException {
    Map<Long, Part> partById = new HashMap<>();
    String[] columns = { // 0
    "id", // 1
    "type", // 2
    "parent", // 3
    "mime_type", // 4
    "decoded_body_size", // 5
    "display_name", // 6
    "header", // 7
    "encoding", // 8
    "charset", // 9
    "data_location", // 10
    "data", // 11
    "preamble", // 12
    "epilogue", // 13
    "boundary", // 14
    "content_id", // 15
    "server_extra" };
    Cursor cursor = db.query("message_parts", columns, "root = ?", new String[] { String.valueOf(message.getMessagePartId()) }, null, null, "seq");
    try {
        while (cursor.moveToNext()) {
            loadMessagePart(message, partById, cursor);
        }
    } finally {
        cursor.close();
    }
}
Also used : HashMap(java.util.HashMap) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Cursor(android.database.Cursor)

Example 39 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class LocalFolder method moveMessages.

@Override
public Map<String, String> moveMessages(final List<? extends Message> msgs, final Folder destFolder) throws MessagingException {
    if (!(destFolder instanceof LocalFolder)) {
        throw new MessagingException("moveMessages called with non-LocalFolder");
    }
    final LocalFolder lDestFolder = (LocalFolder) destFolder;
    final Map<String, String> uidMap = new HashMap<>();
    try {
        this.localStore.database.execute(false, new DbCallback<Void>() {

            @Override
            public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException {
                try {
                    lDestFolder.open(OPEN_MODE_RW);
                    for (Message message : msgs) {
                        LocalMessage lMessage = (LocalMessage) message;
                        String oldUID = message.getUid();
                        Timber.d("Updating folder_id to %s for message with UID %s, " + "id %d currently in folder %s", lDestFolder.getId(), message.getUid(), lMessage.getId(), getName());
                        String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
                        message.setUid(newUid);
                        uidMap.put(oldUID, newUid);
                        // Message threading in the target folder
                        ThreadInfo threadInfo = lDestFolder.doMessageThreading(db, message);
                        /*
                             * "Move" the message into the new folder
                             */
                        long msgId = lMessage.getId();
                        String[] idArg = new String[] { Long.toString(msgId) };
                        ContentValues cv = new ContentValues();
                        cv.put("folder_id", lDestFolder.getId());
                        cv.put("uid", newUid);
                        db.update("messages", cv, "id = ?", idArg);
                        // Create/update entry in 'threads' table for the message in the
                        // target folder
                        cv.clear();
                        cv.put("message_id", msgId);
                        if (threadInfo.threadId == -1) {
                            if (threadInfo.rootId != -1) {
                                cv.put("root", threadInfo.rootId);
                            }
                            if (threadInfo.parentId != -1) {
                                cv.put("parent", threadInfo.parentId);
                            }
                            db.insert("threads", null, cv);
                        } else {
                            db.update("threads", cv, "id = ?", new String[] { Long.toString(threadInfo.threadId) });
                        }
                        /*
                             * Add a placeholder message so we won't download the original
                             * message again if we synchronize before the remote move is
                             * complete.
                             */
                        // We need to open this folder to get the folder id
                        open(OPEN_MODE_RW);
                        cv.clear();
                        cv.put("uid", oldUID);
                        cv.putNull("flags");
                        cv.put("read", 1);
                        cv.put("deleted", 1);
                        cv.put("folder_id", mFolderId);
                        cv.put("empty", 0);
                        String messageId = message.getMessageId();
                        if (messageId != null) {
                            cv.put("message_id", messageId);
                        }
                        final long newId;
                        if (threadInfo.msgId != -1) {
                            // There already existed an empty message in the target folder.
                            // Let's use it as placeholder.
                            newId = threadInfo.msgId;
                            db.update("messages", cv, "id = ?", new String[] { Long.toString(newId) });
                        } else {
                            newId = db.insert("messages", null, cv);
                        }
                        /*
                             * Update old entry in 'threads' table to point to the newly
                             * created placeholder.
                             */
                        cv.clear();
                        cv.put("message_id", newId);
                        db.update("threads", cv, "id = ?", new String[] { Long.toString(lMessage.getThreadId()) });
                    }
                } catch (MessagingException e) {
                    throw new WrappedException(e);
                }
                return null;
            }
        });
        this.localStore.notifyChange();
        return uidMap;
    } catch (WrappedException e) {
        throw (MessagingException) e.getCause();
    }
}
Also used : ContentValues(android.content.ContentValues) WrappedException(com.fsck.k9.mailstore.LockableDatabase.WrappedException) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessagingException(com.fsck.k9.mail.MessagingException) HashMap(java.util.HashMap) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 40 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class ReplyToParser method getRecipientsToReplyAllTo.

public ReplyToAddresses getRecipientsToReplyAllTo(Message message, Account account) {
    List<Address> replyToAddresses = Arrays.asList(getRecipientsToReplyTo(message, account).to);
    HashSet<Address> alreadyAddedAddresses = new HashSet<>(replyToAddresses);
    ArrayList<Address> toAddresses = new ArrayList<>(replyToAddresses);
    ArrayList<Address> ccAddresses = new ArrayList<>();
    for (Address address : message.getFrom()) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            toAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    for (Address address : message.getRecipients(RecipientType.TO)) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            toAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    for (Address address : message.getRecipients(RecipientType.CC)) {
        if (!alreadyAddedAddresses.contains(address) && !account.isAnIdentity(address)) {
            ccAddresses.add(address);
            alreadyAddedAddresses.add(address);
        }
    }
    return new ReplyToAddresses(toAddresses, ccAddresses);
}
Also used : Address(com.fsck.k9.mail.Address) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Test (org.junit.Test)127 Message (com.fsck.k9.mail.Message)111 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)102 Part (com.fsck.k9.mail.Part)47 LocalMessage (com.fsck.k9.mailstore.LocalMessage)46 MessagingException (com.fsck.k9.mail.MessagingException)41 ArrayList (java.util.ArrayList)41 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 BodyPart (com.fsck.k9.mail.BodyPart)32 Account (com.fsck.k9.Account)27 LocalFolder (com.fsck.k9.mailstore.LocalFolder)24 TextBody (com.fsck.k9.mail.internet.TextBody)23 IOException (java.io.IOException)22 Address (com.fsck.k9.mail.Address)21 LocalStore (com.fsck.k9.mailstore.LocalStore)21 Date (java.util.Date)20 MessageReference (com.fsck.k9.activity.MessageReference)16 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)16 Folder (com.fsck.k9.mail.Folder)14 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)13