From d8a73b195d621fdb6abea0d48553b1209b8794b0 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 30 Jul 2010 00:58:33 +0000 Subject: [PATCH] Factor out the decision about whether a part is "viewable" for purposes of fetching ; remove broken "inline" check from the same. --- .../fsck/k9/mail/internet/MimeUtility.java | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index d114040d3..29e543275 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -497,22 +497,6 @@ public class MimeUtility public static void collectParts(Part part, ArrayList viewables, ArrayList 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"); - } - - /* - * A best guess that this part is intended to be an attachment and not inline. - */ - boolean attachment = ("attachment".equalsIgnoreCase(dispositionType)) - || (dispositionFilename != null) - && (!"inline".equalsIgnoreCase(dispositionType)); - /* * 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 @@ -539,27 +523,56 @@ public class MimeUtility * If the part is HTML and it got this far it's part of a mixed (et * al) and should be rendered inline. */ - else if ((!attachment) && (part.getMimeType().equalsIgnoreCase("text/html"))) - { + else if (isPartTextualBody(part)) { viewables.add(part); } + else + { + attachments.add(part); + } + + } + + + public static Boolean isPartTextualBody (Part part) 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"); + } + + /* + * A best guess that this part is intended to be an attachment and not inline. + */ + boolean attachment = ("attachment".equalsIgnoreCase(dispositionType) + || (dispositionFilename != null)); + + if ((!attachment) && (part.getMimeType().equalsIgnoreCase("text/html"))) + { + return true; + } /* * If the part is plain text and it got this far it's part of a * mixed (et al) and should be rendered inline. */ else if ((!attachment) && (part.getMimeType().equalsIgnoreCase("text/plain"))) { - viewables.add(part); + return true; } /* * Finally, if it's nothing else we will include it as an attachment. */ else { - attachments.add(part); + return false; } } + public static String getMimeTypeByExtension(String filename) { if (filename!=null