use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageCryptoHelper method getDataSinkForDecryptedInlineData.
private OpenPgpDataSink<MimeBodyPart> getDataSinkForDecryptedInlineData() {
return new OpenPgpDataSink<MimeBodyPart>() {
@Override
public MimeBodyPart processData(InputStream is) throws IOException {
try {
ByteArrayOutputStream decryptedByteOutputStream = new ByteArrayOutputStream();
IOUtils.copy(is, decryptedByteOutputStream);
TextBody body = new TextBody(new String(decryptedByteOutputStream.toByteArray()));
return new MimeBodyPart(body, "text/plain");
} catch (MessagingException e) {
Timber.e(e, "MessagingException");
}
return null;
}
};
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class LocalFolder method updateOrInsertMessagePart.
private long updateOrInsertMessagePart(SQLiteDatabase db, ContentValues cv, Part part, long existingMessagePartId) throws IOException, MessagingException {
byte[] headerBytes = getHeaderBytes(part);
cv.put("mime_type", part.getMimeType());
cv.put("header", headerBytes);
cv.put("type", MessagePartType.UNKNOWN);
File file = null;
Body body = part.getBody();
if (body instanceof Multipart) {
multipartToContentValues(cv, (Multipart) body);
} else if (body == null) {
missingPartToContentValues(cv, part);
} else if (body instanceof Message) {
messageMarkerToContentValues(cv);
} else {
file = leafPartToContentValues(cv, part, body);
}
long messagePartId;
if (existingMessagePartId != INVALID_MESSAGE_PART_ID) {
messagePartId = existingMessagePartId;
db.update("message_parts", cv, "id = ?", new String[] { Long.toString(messagePartId) });
} else {
messagePartId = db.insertOrThrow("message_parts", null, cv);
}
if (file != null) {
moveTemporaryFile(file, Long.toString(messagePartId));
}
return messagePartId;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class LocalFolder method writeBodyToDisk.
private File writeBodyToDisk(Body body) throws IOException, MessagingException {
File file = File.createTempFile("body", null, BinaryTempFileBody.getTempDirectory());
OutputStream out = new FileOutputStream(file);
try {
body.writeTo(out);
} finally {
out.close();
}
return file;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class LocalFolder method leafPartToContentValues.
private File leafPartToContentValues(ContentValues cv, Part part, Body body) throws MessagingException, IOException {
AttachmentViewInfo attachment = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
cv.put("display_name", attachment.displayName);
String encoding = getTransferEncoding(part);
if (!(body instanceof SizeAware)) {
throw new IllegalStateException("Body needs to implement SizeAware");
}
SizeAware sizeAwareBody = (SizeAware) body;
long fileSize = sizeAwareBody.getSize();
File file = null;
int dataLocation;
if (fileSize > MAX_BODY_SIZE_FOR_DATABASE) {
dataLocation = DataLocation.ON_DISK;
file = writeBodyToDiskIfNecessary(part);
long size = decodeAndCountBytes(file, encoding, fileSize);
cv.put("decoded_body_size", size);
} else {
dataLocation = DataLocation.IN_DATABASE;
byte[] bodyData = getBodyBytes(body);
cv.put("data", bodyData);
long size = decodeAndCountBytes(bodyData, encoding, bodyData.length);
cv.put("decoded_body_size", size);
}
cv.put("data_location", dataLocation);
cv.put("encoding", encoding);
cv.put("content_id", part.getContentId());
return file;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageCryptoStructureDetector method findPgpInlineParts.
public static List<Part> findPgpInlineParts(Part startPart) {
List<Part> inlineParts = new ArrayList<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(startPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (isPartPgpInlineEncryptedOrSigned(part)) {
inlineParts.add(part);
continue;
}
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (int i = multipart.getCount() - 1; i >= 0; i--) {
BodyPart bodyPart = multipart.getBodyPart(i);
partsToCheck.push(bodyPart);
}
}
}
return inlineParts;
}
Aggregations