Search in sources :

Example 56 with MessagingException

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

the class EmailProviderTest method query_forThreadedMessages_showsThreadOfEmailOnce.

@Test
public void query_forThreadedMessages_showsThreadOfEmailOnce() throws MessagingException {
    Account account = Preferences.getPreferences(getContext()).newAccount();
    account.getUuid();
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(message));
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(reply));
    Cursor cursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages/threaded"), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT, EmailProvider.MessageColumns.SUBJECT, EmailProvider.MessageColumns.DATE, EmailProvider.SpecialColumns.THREAD_COUNT }, "", new String[] {}, EmailProvider.MessageColumns.DATE + " DESC");
    assertNotNull(cursor);
    assertTrue(cursor.moveToFirst());
    assertEquals(2, cursor.getInt(5));
    assertFalse(cursor.moveToNext());
}
Also used : Account(com.fsck.k9.Account) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 57 with MessagingException

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

the class Account method getStats.

/**
     * @return <code>null</code> if not available
     * @throws MessagingException
     * @see {@link #isAvailable(Context)}
     */
public AccountStats getStats(Context context) throws MessagingException {
    if (!isAvailable(context)) {
        return null;
    }
    AccountStats stats = new AccountStats();
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + getUuid() + "/stats");
    String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
    // Create LocalSearch instance to exclude special folders (Trash, Drafts, Spam, Outbox,
    // Sent) and limit the search to displayable folders.
    LocalSearch search = new LocalSearch();
    excludeSpecialFolders(search);
    limitToDisplayableFolders(search);
    // Use the LocalSearch instance to create a WHERE clause to query the content provider
    StringBuilder query = new StringBuilder();
    List<String> queryArgs = new ArrayList<>();
    ConditionsTreeNode conditions = search.getConditions();
    SqlQueryBuilder.buildWhereClause(this, conditions, query, queryArgs);
    String selection = query.toString();
    String[] selectionArgs = queryArgs.toArray(new String[0]);
    Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            stats.unreadMessageCount = cursor.getInt(0);
            stats.flaggedMessageCount = cursor.getInt(1);
        }
    } finally {
        Utility.closeQuietly(cursor);
    }
    LocalStore localStore = getLocalStore();
    if (K9.measureAccounts()) {
        stats.size = localStore.getSize();
    }
    return stats;
}
Also used : ConditionsTreeNode(com.fsck.k9.search.ConditionsTreeNode) LocalSearch(com.fsck.k9.search.LocalSearch) ArrayList(java.util.ArrayList) LocalStore(com.fsck.k9.mailstore.LocalStore) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 58 with MessagingException

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

the class MessageCompose method processMessageToForward.

private void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    String subject = message.getSubject();
    if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
        subjectView.setText("Fwd: " + subject);
    } else {
        subjectView.setText(subject);
    }
    // even if there are multiple references.
    if (!TextUtils.isEmpty(message.getMessageId())) {
        repliedToMessageId = message.getMessageId();
        referencedMessageIds = repliedToMessageId;
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.processMessageToForward(messageViewInfo);
    attachmentPresenter.processMessageToForward(messageViewInfo);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 59 with MessagingException

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

the class ReconstructMessageFromDatabaseTest method testThatByteIdenticalCopyOfMessageIsReconstructed.

public void testThatByteIdenticalCopyOfMessageIsReconstructed() throws IOException, MessagingException {
    LocalFolder folder = createFolderInDatabase();
    MimeMessage message = parseMessage();
    saveMessageToDatabase(folder, message);
    LocalMessage localMessage = readMessageFromDatabase(folder, message);
    String reconstructedMessage = writeMessageToString(localMessage);
    assertEquals(MESSAGE_SOURCE, reconstructedMessage);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage)

Example 60 with MessagingException

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

the class MessagingControllerTest method localMessageWithCopyOnServer.

private LocalMessage localMessageWithCopyOnServer() throws MessagingException {
    String messageUid = "UID";
    Message remoteMessage = mock(Message.class);
    LocalMessage localMessage = mock(LocalMessage.class);
    when(remoteMessage.getUid()).thenReturn(messageUid);
    when(localMessage.getUid()).thenReturn(messageUid);
    when(remoteFolder.getMessages(anyInt(), anyInt(), any(Date.class), any(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));
    return localMessage;
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) LocalMessage(com.fsck.k9.mailstore.LocalMessage) Message(com.fsck.k9.mail.Message) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) MessageRetrievalListener(com.fsck.k9.mail.MessageRetrievalListener)

Aggregations

MessagingException (com.fsck.k9.mail.MessagingException)159 Test (org.junit.Test)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)52 LocalFolder (com.fsck.k9.mailstore.LocalFolder)49 LocalStore (com.fsck.k9.mailstore.LocalStore)49 ArrayList (java.util.ArrayList)49 Message (com.fsck.k9.mail.Message)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 IOException (java.io.IOException)42 FetchProfile (com.fsck.k9.mail.FetchProfile)30 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)26 BodyPart (com.fsck.k9.mail.BodyPart)23 Part (com.fsck.k9.mail.Part)22 Account (com.fsck.k9.Account)21 Body (com.fsck.k9.mail.Body)21 TextBody (com.fsck.k9.mail.internet.TextBody)21 Date (java.util.Date)20 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)18