Search in sources :

Example 96 with MessagingException

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

the class MimePartStreamParser method parse.

public static MimeBodyPart parse(FileFactory fileFactory, InputStream inputStream) throws MessagingException, IOException {
    MimeBodyPart parsedRootPart = new MimeBodyPart();
    MimeConfig parserConfig = new MimeConfig.Builder().setMaxHeaderLen(-1).setMaxLineLen(-1).setMaxHeaderCount(-1).build();
    MimeStreamParser parser = new MimeStreamParser(parserConfig);
    parser.setContentHandler(new PartBuilder(parser, fileFactory, parsedRootPart));
    parser.setRecurse();
    try {
        parser.parse(new EOLConvertingInputStream(inputStream));
    } catch (MimeException e) {
        throw new MessagingException("Failed to parse decrypted content", e);
    }
    return parsedRootPart;
}
Also used : MimeConfig(org.apache.james.mime4j.stream.MimeConfig) MessagingException(com.fsck.k9.mail.MessagingException) MimeStreamParser(org.apache.james.mime4j.parser.MimeStreamParser) MimeException(org.apache.james.mime4j.MimeException) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) EOLConvertingInputStream(org.apache.james.mime4j.io.EOLConvertingInputStream)

Example 97 with MessagingException

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

the class LocalMessage method populateFromGetMessageCursor.

void populateFromGetMessageCursor(Cursor cursor) throws MessagingException {
    final String subject = cursor.getString(LocalStore.MSG_INDEX_SUBJECT);
    this.setSubject(subject == null ? "" : subject);
    Address[] from = Address.unpack(cursor.getString(LocalStore.MSG_INDEX_SENDER_LIST));
    if (from.length > 0) {
        this.setFrom(from[0]);
    }
    this.setInternalSentDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_DATE)));
    this.setUid(cursor.getString(LocalStore.MSG_INDEX_UID));
    String flagList = cursor.getString(LocalStore.MSG_INDEX_FLAGS);
    if (flagList != null && flagList.length() > 0) {
        String[] flags = flagList.split(",");
        for (String flag : flags) {
            try {
                this.setFlagInternal(Flag.valueOf(flag), true);
            } catch (Exception e) {
                if (!"X_BAD_FLAG".equals(flag)) {
                    Timber.w("Unable to parse flag %s", flag);
                }
            }
        }
    }
    this.databaseId = cursor.getLong(LocalStore.MSG_INDEX_ID);
    mTo = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_TO)));
    mCc = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_CC)));
    mBcc = getAddressesOrNull(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_BCC)));
    headerNeedsUpdating = true;
    this.setReplyTo(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_REPLY_TO)));
    this.attachmentCount = cursor.getInt(LocalStore.MSG_INDEX_ATTACHMENT_COUNT);
    this.setInternalDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_INTERNAL_DATE)));
    this.setMessageId(cursor.getString(LocalStore.MSG_INDEX_MESSAGE_ID_HEADER));
    String previewTypeString = cursor.getString(LocalStore.MSG_INDEX_PREVIEW_TYPE);
    DatabasePreviewType databasePreviewType = DatabasePreviewType.fromDatabaseValue(previewTypeString);
    previewType = databasePreviewType.getPreviewType();
    if (previewType == PreviewType.TEXT) {
        preview = cursor.getString(LocalStore.MSG_INDEX_PREVIEW);
    } else {
        preview = "";
    }
    if (this.mFolder == null) {
        LocalFolder f = new LocalFolder(this.localStore, cursor.getInt(LocalStore.MSG_INDEX_FOLDER_ID));
        f.open();
        this.mFolder = f;
    }
    threadId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ID);
    rootId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ROOT_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ROOT_ID);
    boolean deleted = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_DELETED) == 1);
    boolean read = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_READ) == 1);
    boolean flagged = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FLAGGED) == 1);
    boolean answered = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_ANSWERED) == 1);
    boolean forwarded = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FORWARDED) == 1);
    setFlagInternal(Flag.DELETED, deleted);
    setFlagInternal(Flag.SEEN, read);
    setFlagInternal(Flag.FLAGGED, flagged);
    setFlagInternal(Flag.ANSWERED, answered);
    setFlagInternal(Flag.FORWARDED, forwarded);
    setMessagePartId(cursor.getLong(LocalStore.MSG_INDEX_MESSAGE_PART_ID));
    MimeType mimeType = MimeType.parseOrNull(cursor.getString(LocalStore.MSG_INDEX_MIME_TYPE));
    this.mimeType = mimeType != null ? mimeType.toString() : DEFAULT_MIME_TYPE;
    byte[] header = cursor.getBlob(LocalStore.MSG_INDEX_HEADER_DATA);
    if (header != null) {
        MessageHeaderParser.parse(new ByteArrayInputStream(header), this::addRawHeader);
    } else {
        Timber.d("No headers available for this message!");
    }
    headerNeedsUpdating = false;
}
Also used : Address(com.fsck.k9.mail.Address) ByteArrayInputStream(java.io.ByteArrayInputStream) Date(java.util.Date) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) MimeType(com.fsck.k9.mail.MimeType)

Example 98 with MessagingException

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

the class LocalMessage method debugClearLocalData.

public void debugClearLocalData() throws MessagingException {
    if (!K9.DEVELOPER_MODE) {
        throw new AssertionError("method must only be used in developer mode!");
    }
    localStore.getDatabase().execute(true, new DbCallback<Void>() {

        @Override
        public Void doDbWork(final SQLiteDatabase db) throws MessagingException {
            ContentValues cv = new ContentValues();
            cv.putNull("message_part_id");
            db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
            mFolder.deleteMessagePartsAndDataFromDisk(messagePartId);
            setFlag(Flag.X_DOWNLOADED_FULL, false);
            setFlag(Flag.X_DOWNLOADED_PARTIAL, false);
            return null;
        }
    });
    localStore.notifyChange();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MessagingException(com.fsck.k9.mail.MessagingException)

Example 99 with MessagingException

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

the class LocalMessage method delete.

/*
     * If a message is being marked as deleted we want to clear out its content. Delete will not actually remove the
     * row since we need to retain the UID for synchronization purposes.
     */
public void delete() throws MessagingException {
    localStore.getDatabase().execute(true, new DbCallback<Void>() {

        @Override
        public Void doDbWork(final SQLiteDatabase db) throws MessagingException {
            ContentValues cv = new ContentValues();
            cv.put("deleted", 1);
            cv.put("preview_type", DatabasePreviewType.fromPreviewType(PreviewType.NONE).getDatabaseValue());
            cv.put("read", 0);
            cv.put("flagged", 0);
            cv.put("answered", 0);
            cv.put("forwarded", 0);
            cv.putNull("subject");
            cv.putNull("sender_list");
            cv.putNull("date");
            cv.putNull("to_list");
            cv.putNull("cc_list");
            cv.putNull("bcc_list");
            cv.putNull("preview");
            cv.putNull("reply_to_list");
            cv.putNull("message_part_id");
            cv.putNull("flags");
            cv.putNull("attachment_count");
            cv.putNull("internal_date");
            cv.putNull("mime_type");
            cv.putNull("encryption_type");
            db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
            mFolder.deleteMessagePartsAndDataFromDisk(messagePartId);
            getFolder().deleteFulltextIndexEntry(db, databaseId);
            return null;
        }
    });
    localStore.notifyChange();
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) MessagingException(com.fsck.k9.mail.MessagingException)

Example 100 with MessagingException

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

the class AttachmentInfoExtractor method extractAttachmentInfoForView.

@WorkerThread
public List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts) throws MessagingException {
    List<AttachmentViewInfo> attachments = new ArrayList<>();
    for (Part part : attachmentParts) {
        AttachmentViewInfo attachmentViewInfo = extractAttachmentInfo(part);
        attachments.add(attachmentViewInfo);
    }
    return attachments;
}
Also used : Part(com.fsck.k9.mail.Part) LocalPart(com.fsck.k9.mailstore.LocalPart) ArrayList(java.util.ArrayList) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) WorkerThread(androidx.annotation.WorkerThread)

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