use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageCryptoStructureDetector method findPrimaryPartInAlternative.
private static Part findPrimaryPartInAlternative(Part part) {
Body body = part.getBody();
if (part.isMimeType("multipart/alternative") && body instanceof Multipart) {
Multipart multipart = (Multipart) body;
if (multipart.getCount() == 0) {
return null;
}
BodyPart firstBodyPart = multipart.getBodyPart(0);
if (isPartPgpInlineEncryptedOrSigned(firstBodyPart)) {
return firstBodyPart;
}
}
return null;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class LocalFolder method loadMessagePart.
private void loadMessagePart(LocalMessage message, Map<Long, Part> partById, Cursor cursor) throws MessagingException {
long id = cursor.getLong(0);
long parentId = cursor.getLong(2);
String mimeType = cursor.getString(3);
long size = cursor.getLong(4);
byte[] header = cursor.getBlob(6);
int dataLocation = cursor.getInt(9);
String serverExtra = cursor.getString(15);
// TODO we don't currently cache much of the part data which is computed with AttachmentInfoExtractor,
// TODO might want to do that at a later point?
// String displayName = cursor.getString(5);
// int type = cursor.getInt(1);
// boolean inlineAttachment = (type == MessagePartType.HIDDEN_ATTACHMENT);
final Part part;
if (id == message.getMessagePartId()) {
part = message;
} else {
Part parentPart = partById.get(parentId);
if (parentPart == null) {
throw new IllegalStateException("Parent part not found");
}
String parentMimeType = parentPart.getMimeType();
if (MimeUtility.isMultipart(parentMimeType)) {
BodyPart bodyPart = new LocalBodyPart(getAccountUuid(), message, id, size);
((Multipart) parentPart.getBody()).addBodyPart(bodyPart);
part = bodyPart;
} else if (MimeUtility.isMessage(parentMimeType)) {
Message innerMessage = new LocalMimeMessage(getAccountUuid(), message, id);
parentPart.setBody(innerMessage);
part = innerMessage;
} else {
throw new IllegalStateException("Parent is neither a multipart nor a message");
}
parseHeaderBytes(part, header);
}
partById.put(id, part);
part.setServerExtra(serverExtra);
if (MimeUtility.isMultipart(mimeType)) {
byte[] preamble = cursor.getBlob(11);
byte[] epilogue = cursor.getBlob(12);
String boundary = cursor.getString(13);
MimeMultipart multipart = new MimeMultipart(mimeType, boundary);
part.setBody(multipart);
multipart.setPreamble(preamble);
multipart.setEpilogue(epilogue);
} else if (dataLocation == DataLocation.IN_DATABASE) {
String encoding = cursor.getString(7);
byte[] data = cursor.getBlob(10);
Body body = new BinaryMemoryBody(data, encoding);
part.setBody(body);
} else if (dataLocation == DataLocation.ON_DISK) {
String encoding = cursor.getString(7);
File file = localStore.getAttachmentFile(Long.toString(id));
if (file.exists()) {
Body body = new FileBackedBody(file, encoding);
part.setBody(body);
}
}
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class PgpMessageBuilder method createBodyPartFromMessageContent.
private MimeBodyPart createBodyPartFromMessageContent() throws MessagingException {
MimeBodyPart bodyPart = currentProcessedMimeMessage.toBodyPart();
String[] contentType = currentProcessedMimeMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE);
if (contentType.length > 0) {
bodyPart.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType[0]);
}
if (isDraft()) {
String[] identityHeader = currentProcessedMimeMessage.getHeader(K9.IDENTITY_HEADER);
bodyPart.setHeader(K9.IDENTITY_HEADER, identityHeader[0]);
currentProcessedMimeMessage.removeHeader(K9.IDENTITY_HEADER);
}
return bodyPart;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class LocalStore method findPartById.
static Part findPartById(Part searchRoot, long partId) {
if (searchRoot instanceof LocalMessage) {
LocalMessage localMessage = (LocalMessage) searchRoot;
if (localMessage.getMessagePartId() == partId) {
return localMessage;
}
}
Stack<Part> partStack = new Stack<>();
partStack.add(searchRoot);
while (!partStack.empty()) {
Part part = partStack.pop();
if (part instanceof LocalPart) {
LocalPart localBodyPart = (LocalPart) part;
if (localBodyPart.getPartId() == partId) {
return part;
}
}
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body;
for (BodyPart innerPart : innerMultipart.getBodyParts()) {
partStack.add(innerPart);
}
}
if (body instanceof Part) {
partStack.add((Part) body);
}
}
return null;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class TextPartFinder method findTextPartInMultipartAlternative.
private Part findTextPartInMultipartAlternative(Multipart multipart) {
Part htmlPart = null;
for (BodyPart bodyPart : multipart.getBodyParts()) {
String mimeType = bodyPart.getMimeType();
Body body = bodyPart.getBody();
if (body instanceof Multipart) {
Part candidatePart = findFirstTextPart(bodyPart);
if (candidatePart != null) {
if (isSameMimeType(candidatePart.getMimeType(), "text/html")) {
htmlPart = candidatePart;
} else {
return candidatePart;
}
}
} else if (isSameMimeType(mimeType, "text/plain")) {
return bodyPart;
} else if (isSameMimeType(mimeType, "text/html") && htmlPart == null) {
htmlPart = bodyPart;
}
}
if (htmlPart != null) {
return htmlPart;
}
return null;
}
Aggregations