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;
}
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;
}
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();
}
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();
}
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;
}
Aggregations