1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

Factor out the decision about whether a part is "viewable" for purposes

of fetching ; remove broken "inline" check from the same.
This commit is contained in:
Jesse Vincent 2010-07-30 00:58:33 +00:00
parent 0c67f1f4cf
commit d8a73b195d

View File

@ -497,22 +497,6 @@ 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");
}
/*
* 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