use of com.android.voicemail.impl.mail.Multipart in project android_packages_apps_Dialer by LineageOS.
the class MimeMessage method setBody.
@Override
public void setBody(Body body) throws MessagingException {
this.body = body;
if (body instanceof Multipart) {
final Multipart multipart = ((Multipart) body);
multipart.setParent(this);
setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
setHeader("MIME-Version", "1.0");
} else if (body instanceof TextBody) {
setHeader(MimeHeader.HEADER_CONTENT_TYPE, String.format("%s;\n charset=utf-8", getMimeType()));
setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
}
}
use of com.android.voicemail.impl.mail.Multipart in project android_packages_apps_Dialer by LineageOS.
the class MimeUtility method collectParts.
/**
* Recursively scan a Part (usually a Message) and sort out which of its children will be
* "viewable" and which will be attachments.
*
* @param part The part to be broken down
* @param viewables This arraylist will be populated with all parts that appear to be the
* "message" (e.g. text/plain & text/html)
* @param attachments This arraylist will be populated with all parts that appear to be
* attachments (including inlines)
* @throws MessagingException
*/
public static void collectParts(Part part, ArrayList<Part> viewables, ArrayList<Part> attachments) throws MessagingException {
String disposition = part.getDisposition();
String dispositionType = MimeUtility.getHeaderParameter(disposition, null);
// If a disposition is not specified, default to "inline"
boolean inline = TextUtils.isEmpty(dispositionType) || "inline".equalsIgnoreCase(dispositionType);
// The lower-case mime type
String mimeType = part.getMimeType().toLowerCase();
if (part.getBody() instanceof Multipart) {
// If the part is Multipart but not alternative it's either mixed or
// something we don't know about, which means we treat it as mixed
// per the spec. We just process its pieces recursively.
MimeMultipart mp = (MimeMultipart) part.getBody();
boolean foundHtml = false;
if (mp.getSubTypeForTest().equals("alternative")) {
for (int i = 0; i < mp.getCount(); i++) {
if (mp.getBodyPart(i).isMimeType("text/html")) {
foundHtml = true;
break;
}
}
}
for (int i = 0; i < mp.getCount(); i++) {
// See if we have text and html
BodyPart bp = mp.getBodyPart(i);
// If there's html, don't bother loading text
if (foundHtml && bp.isMimeType("text/plain")) {
continue;
}
collectParts(bp, viewables, attachments);
}
} else if (part.getBody() instanceof Message) {
// If the part is an embedded message we just continue to process
// it, pulling any viewables or attachments into the running list.
Message message = (Message) part.getBody();
collectParts(message, viewables, attachments);
} else if (inline && (mimeType.startsWith("text") || (mimeType.startsWith("image")))) {
// We'll treat text and images as viewables
viewables.add(part);
} else {
// Everything else is an attachment.
attachments.add(part);
}
}
use of com.android.voicemail.impl.mail.Multipart in project android_packages_apps_Dialer by LineageOS.
the class MimeBodyPart method setBody.
@Override
public void setBody(Body body) throws MessagingException {
this.body = body;
if (body instanceof Multipart) {
Multipart multipart = ((Multipart) body);
multipart.setParent(this);
setHeader(MimeHeader.HEADER_CONTENT_TYPE, multipart.getContentType());
} else if (body instanceof TextBody) {
String contentType = String.format("%s;\n charset=utf-8", getMimeType());
String name = MimeUtility.getHeaderParameter(getContentType(), "name");
if (name != null) {
contentType += String.format(";\n name=\"%s\"", name);
}
setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
}
}