Search in sources :

Example 1 with MessagingException

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

the class ImapFolderTest method getUnreadMessageCount_connectionThrowsIOException_shouldThrowMessagingException.

@Test
public void getUnreadMessageCount_connectionThrowsIOException_shouldThrowMessagingException() throws Exception {
    ImapFolder folder = createFolder("Folder");
    prepareImapFolderForOpen(OPEN_MODE_RW);
    when(imapConnection.executeSimpleCommand("SEARCH 1:* UNSEEN NOT DELETED")).thenThrow(new IOException());
    folder.open(OPEN_MODE_RW);
    try {
        folder.getUnreadMessageCount();
        fail("Expected exception");
    } catch (MessagingException e) {
        assertEquals("IO Error", e.getMessage());
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with MessagingException

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

the class ImapFolderTest method areMoreMessagesAvailable_withClosedFolder_shouldThrow.

@Test
public void areMoreMessagesAvailable_withClosedFolder_shouldThrow() throws Exception {
    ImapFolder folder = createFolder("Folder");
    when(imapStore.getConnection()).thenReturn(imapConnection);
    try {
        folder.areMoreMessagesAvailable(10, new Date());
        fail("Expected exception");
    } catch (MessagingException e) {
        assertCheckOpenErrorMessage("Folder", e);
    }
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) Date(java.util.Date) Test(org.junit.Test)

Example 3 with MessagingException

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

the class MigrationTo55 method createFtsSearchTable.

static void createFtsSearchTable(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
    db.execSQL("CREATE VIRTUAL TABLE messages_fulltext USING fts4 (fulltext)");
    LocalStore localStore = migrationsHelper.getLocalStore();
    MessageFulltextCreator fulltextCreator = localStore.getMessageFulltextCreator();
    try {
        List<LocalFolder> folders = localStore.getPersonalNamespaces(true);
        ContentValues cv = new ContentValues();
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.BODY);
        for (LocalFolder folder : folders) {
            List<String> messageUids = folder.getAllMessageUids();
            for (String messageUid : messageUids) {
                LocalMessage localMessage = folder.getMessage(messageUid);
                folder.fetch(Collections.singletonList(localMessage), fp, null);
                String fulltext = fulltextCreator.createFulltext(localMessage);
                if (!TextUtils.isEmpty(fulltext)) {
                    Timber.d("fulltext for msg id %d is %d chars long", localMessage.getId(), fulltext.length());
                    cv.clear();
                    cv.put("docid", localMessage.getId());
                    cv.put("fulltext", fulltext);
                    db.insert("messages_fulltext", null, cv);
                } else {
                    Timber.d("no fulltext for msg id %d :(", localMessage.getId());
                }
            }
        }
    } catch (MessagingException e) {
        Timber.e(e, "error indexing fulltext - skipping rest, fts index is incomplete!");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) ContentValues(android.content.ContentValues) LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) MessageFulltextCreator(com.fsck.k9.message.extractors.MessageFulltextCreator) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 4 with MessagingException

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

the class MessageViewInfoExtractor method extractMessageForView.

@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations annotations) throws MessagingException {
    Part rootPart;
    CryptoResultAnnotation cryptoResultAnnotation;
    List<Part> extraParts;
    CryptoMessageParts cryptoMessageParts = MessageCryptoSplitter.split(message, annotations);
    if (cryptoMessageParts != null) {
        rootPart = cryptoMessageParts.contentPart;
        cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
        extraParts = cryptoMessageParts.extraParts;
    } else {
        if (annotations != null && !annotations.isEmpty()) {
            Timber.e("Got message annotations but no crypto root part!");
        }
        rootPart = message;
        cryptoResultAnnotation = null;
        extraParts = null;
    }
    List<AttachmentViewInfo> attachmentInfos = new ArrayList<>();
    ViewableExtractedText viewable = extractViewableAndAttachments(Collections.singletonList(rootPart), attachmentInfos);
    List<AttachmentViewInfo> extraAttachmentInfos = new ArrayList<>();
    String extraViewableText = null;
    if (extraParts != null) {
        ViewableExtractedText extraViewable = extractViewableAndAttachments(extraParts, extraAttachmentInfos);
        extraViewableText = extraViewable.text;
    }
    AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart);
    boolean isMessageIncomplete = !message.isSet(Flag.X_DOWNLOADED_FULL) || MessageExtractor.hasMissingParts(message);
    return MessageViewInfo.createWithExtractedContent(message, isMessageIncomplete, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, attachmentResolver, extraViewableText, extraAttachmentInfos);
}
Also used : CryptoMessageParts(com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts) Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 5 with MessagingException

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

the class LocalFolder method saveMessagePart.

private long saveMessagePart(SQLiteDatabase db, PartContainer partContainer, long rootMessagePartId, int order) throws IOException, MessagingException {
    Part part = partContainer.part;
    ContentValues cv = new ContentValues();
    if (rootMessagePartId != -1) {
        cv.put("root", rootMessagePartId);
    }
    cv.put("parent", partContainer.parent);
    cv.put("seq", order);
    cv.put("server_extra", part.getServerExtra());
    return updateOrInsertMessagePart(db, cv, part, INVALID_MESSAGE_PART_ID);
}
Also used : ContentValues(android.content.ContentValues) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part)

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