Search in sources :

Example 36 with Account

use of com.fsck.k9.Account 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();
}
Also used : Account(com.fsck.k9.Account) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 37 with Account

use of com.fsck.k9.Account 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 Account

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

the class MessageListFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String accountUuid = accountUuids[id];
    Account account = preferences.getAccount(accountUuid);
    String threadId = getThreadId(search);
    Uri uri;
    String[] projection;
    boolean needConditions;
    if (threadId != null) {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/thread/" + threadId);
        projection = PROJECTION;
        needConditions = false;
    } else if (showingThreadedList) {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/messages/threaded");
        projection = THREADED_PROJECTION;
        needConditions = true;
    } else {
        uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + accountUuid + "/messages");
        projection = PROJECTION;
        needConditions = true;
    }
    StringBuilder query = new StringBuilder();
    List<String> queryArgs = new ArrayList<>();
    if (needConditions) {
        boolean selectActive = activeMessage != null && activeMessage.getAccountUuid().equals(accountUuid);
        if (selectActive) {
            query.append("(" + MessageColumns.UID + " = ? AND " + SpecialColumns.FOLDER_NAME + " = ?) OR (");
            queryArgs.add(activeMessage.getUid());
            queryArgs.add(activeMessage.getFolderName());
        }
        SqlQueryBuilder.buildWhereClause(account, search.getConditions(), query, queryArgs);
        if (selectActive) {
            query.append(')');
        }
    }
    String selection = query.toString();
    String[] selectionArgs = queryArgs.toArray(new String[0]);
    String sortOrder = buildSortOrder();
    return new CursorLoader(getActivity(), uri, projection, selection, selectionArgs, sortOrder);
}
Also used : CursorLoader(android.content.CursorLoader) Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) Uri(android.net.Uri)

Example 39 with Account

use of com.fsck.k9.Account 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)

Example 40 with Account

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

the class MigrationTest method migrateTextHtml.

@Test
public void migrateTextHtml() throws Exception {
    SQLiteDatabase db = createV50Database();
    insertMultipartAlternativeMessage(db);
    db.close();
    LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
    LocalMessage msg = localStore.getFolder("dev").getMessage("9");
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
    Assert.assertEquals(8, msg.getId());
    Assert.assertEquals(9, msg.getHeaderNames().size());
    Assert.assertEquals("multipart/alternative", msg.getMimeType());
    Assert.assertEquals(0, msg.getAttachmentCount());
    Multipart msgBody = (Multipart) msg.getBody();
    Assert.assertEquals("------------060200010509000000040004", msgBody.getBoundary());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Aggregations

Account (com.fsck.k9.Account)122 Test (org.junit.Test)81 MessagingException (com.fsck.k9.mail.MessagingException)53 LocalFolder (com.fsck.k9.mailstore.LocalFolder)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)43 LocalStore (com.fsck.k9.mailstore.LocalStore)42 ArrayList (java.util.ArrayList)34 MessageReference (com.fsck.k9.activity.MessageReference)32 Message (com.fsck.k9.mail.Message)29 Folder (com.fsck.k9.mail.Folder)27 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)25 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 IOException (java.io.IOException)22 Cursor (android.database.Cursor)21 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)20 Store (com.fsck.k9.mail.Store)20 SearchAccount (com.fsck.k9.search.SearchAccount)20 PendingIntent (android.app.PendingIntent)19 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)19 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)18