Make viewables handling more sensible in MimeUtility

* We had some relatively complicated rules for what was "viewable",
  but there are cases missed.
* It's simplest to consider all non-attachment images and text as
  viewable.

Bug: 6524411
Change-Id: I57844916af4ded683e69932b4effd5546ec42ad2
This commit is contained in:
Marc Blank 2012-05-21 13:01:46 -07:00
parent 0d296a66d8
commit 9037a64ead
1 changed files with 8 additions and 33 deletions

View File

@ -406,33 +406,11 @@ public class MimeUtility {
public static void collectParts(Part part, ArrayList<Part> viewables,
ArrayList<Part> attachments) throws MessagingException {
String disposition = part.getDisposition();
String dispositionType = null;
String dispositionFilename = null;
if (disposition != null) {
dispositionType = MimeUtility.getHeaderParameter(disposition, null);
dispositionFilename = MimeUtility.getHeaderParameter(disposition, "filename");
}
// An attachment filename can be defined in either the Content-Disposition header
// or the Content-Type header. Content-Disposition is preferred, so we only try
// the Content-Type header as a last resort.
if (dispositionFilename == null) {
String contentType = part.getContentType();
dispositionFilename = MimeUtility.getHeaderParameter(contentType, "name");
}
boolean attachmentDisposition = "attachment".equalsIgnoreCase(dispositionType);
String dispositionType = MimeUtility.getHeaderParameter(disposition, null);
// If a disposition is not specified, default to "inline"
boolean inlineDisposition = dispositionType == null
|| "inline".equalsIgnoreCase(dispositionType);
// A guess that this part is intended to be an attachment
boolean attachment = attachmentDisposition
|| (dispositionFilename != null && !inlineDisposition);
// A guess that this part is intended to be an inline.
boolean inline = inlineDisposition && (dispositionFilename != null);
// One or the other
boolean attachmentOrInline = attachment || inline;
boolean inline = dispositionType == null || "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
@ -462,14 +440,11 @@ public class MimeUtility {
// it, pulling any viewables or attachments into the running list.
Message message = (Message)part.getBody();
collectParts(message, viewables, attachments);
} else if ((!attachmentOrInline) && ("text/html".equalsIgnoreCase(part.getMimeType()))) {
// If the part is HTML and we got this far, it's a viewable part of a mixed
} else if (inline && (mimeType.startsWith("text") || (mimeType.startsWith("image")))) {
// We'll treat text and images as viewables
viewables.add(part);
} else if ((!attachmentOrInline) && ("text/plain".equalsIgnoreCase(part.getMimeType()))) {
// If the part is text and we got this far, it's a viewable part of a mixed
viewables.add(part);
} else if (attachmentOrInline) {
// Finally, if it's an attachment or an inline we will include it as an attachment.
} else {
// Everything else is an attachment.
attachments.add(part);
}
}