use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageCryptoStructureDetector method getSignatureData.
public static byte[] getSignatureData(Part part) throws IOException, MessagingException {
if (isPartMultipartSigned(part)) {
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multi = (Multipart) body;
BodyPart signatureBody = multi.getBodyPart(1);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
signatureBody.getBody().writeTo(bos);
return bos.toByteArray();
}
}
return null;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MessageCryptoStructureDetector method findMultipartSignedParts.
public static List<Part> findMultipartSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations) {
List<Part> signedParts = new ArrayList<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(startPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
if (messageCryptoAnnotations.has(part)) {
CryptoResultAnnotation resultAnnotation = messageCryptoAnnotations.get(part);
MimeBodyPart replacementData = resultAnnotation.getReplacementData();
if (replacementData != null) {
part = replacementData;
}
}
Body body = part.getBody();
if (isPartMultipartSigned(part)) {
signedParts.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 signedParts;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class AttachmentResolver method buildCidToAttachmentUriMap.
@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
HashMap<String, Uri> result = new HashMap<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(rootPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (Part bodyPart : multipart.getBodyParts()) {
partsToCheck.push(bodyPart);
}
} else {
try {
String contentId = part.getContentId();
if (contentId != null) {
AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
result.put(contentId, attachmentInfo.internalUri);
}
} catch (MessagingException e) {
Timber.e(e, "Error extracting attachment info");
}
}
}
return Collections.unmodifiableMap(result);
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class DeferredFileBody method writeMemoryToFile.
private void writeMemoryToFile() throws IOException {
if (file != null) {
throw new IllegalStateException("Body is already file-backed!");
}
if (data == null) {
throw new IllegalStateException("Data must be fully written before it can be read!");
}
Timber.d("Writing body to file for attachment access");
file = fileFactory.createFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.close();
data = null;
}
use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class MimeMessageHelper method setBody.
public static void setBody(Part part, Body body) throws MessagingException {
part.setBody(body);
if (part instanceof Message) {
part.setHeader("MIME-Version", "1.0");
}
if (body instanceof Multipart) {
Multipart multipart = ((Multipart) body);
multipart.setParent(part);
String contentType = Headers.contentTypeForMultipart(multipart.getMimeType(), multipart.getBoundary());
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
// note: if this is ever changed to 8bit, multipart/signed parts must always be 7bit!
setEncoding(part, MimeUtil.ENC_7BIT);
} else if (body instanceof TextBody) {
MimeValue contentTypeHeader = MimeParameterDecoder.decode(part.getContentType());
String mimeType = contentTypeHeader.getValue();
if (MimeUtility.mimeTypeMatches(mimeType, "text/*")) {
String name = contentTypeHeader.getParameters().get("name");
String contentType = Headers.contentType(mimeType, "utf-8", name);
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
} else {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, mimeType);
}
setEncoding(part, MimeUtil.ENC_QUOTED_PRINTABLE);
} else if (body instanceof RawDataBody) {
String encoding = ((RawDataBody) body).getEncoding();
part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
}
}
Aggregations