mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-20 04:31:47 -05:00
split apart attachment view creation a bit
This commit is contained in:
parent
3c9eb2c004
commit
b166cf03e8
@ -1839,9 +1839,17 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
|
||||
private void renderAttachments(Part part, int depth) throws MessagingException
|
||||
{
|
||||
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
||||
if (part.getBody() instanceof Multipart)
|
||||
{
|
||||
Multipart mp = (Multipart) part.getBody();
|
||||
for (int i = 0; i < mp.getCount(); i++)
|
||||
{
|
||||
renderAttachments(mp.getBodyPart(i), depth + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||
String name = MimeUtility.getHeaderParameter(contentType, "name");
|
||||
// Inline parts with a content-id are almost certainly components of an HTML message
|
||||
// not attachments. Don't show attachment download buttons for them.
|
||||
if (contentDisposition != null &&
|
||||
@ -1850,24 +1858,30 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
{
|
||||
return;
|
||||
}
|
||||
renderPartAsAttachment(part);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPartAsAttachment(Part part) throws MessagingException
|
||||
{
|
||||
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
|
||||
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
|
||||
String name = MimeUtility.getHeaderParameter(contentType, "name");
|
||||
if (name == null)
|
||||
{
|
||||
name = MimeUtility.getHeaderParameter(contentDisposition, "filename");
|
||||
}
|
||||
if (name != null)
|
||||
if (name == null)
|
||||
{
|
||||
/*
|
||||
* We're guaranteed size because LocalStore.fetch puts it there.
|
||||
*/
|
||||
int size = Integer.parseInt(MimeUtility.getHeaderParameter(contentDisposition, "size"));
|
||||
AttachmentViewHolder attachment = new AttachmentViewHolder();
|
||||
attachment.size = size;
|
||||
String mimeType = part.getMimeType();
|
||||
if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equals(mimeType))
|
||||
{
|
||||
mimeType = MimeUtility.getMimeTypeByExtension(name);
|
||||
return;
|
||||
}
|
||||
AttachmentViewHolder attachment = new AttachmentViewHolder();
|
||||
attachment.size = Integer.parseInt(MimeUtility.getHeaderParameter(contentDisposition, "size"));
|
||||
attachment.contentType = part.getMimeType();
|
||||
if (MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE.equals(attachment.contentType))
|
||||
{
|
||||
attachment.contentType = MimeUtility.getMimeTypeByExtension(name);
|
||||
}
|
||||
attachment.contentType = mimeType;
|
||||
attachment.name = name;
|
||||
attachment.part = (LocalAttachmentBodyPart) part;
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@ -1877,17 +1891,13 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
ImageView attachmentIcon = (ImageView) view.findViewById(R.id.attachment_icon);
|
||||
Button attachmentView = (Button) view.findViewById(R.id.view);
|
||||
Button attachmentDownload = (Button) view.findViewById(R.id.download);
|
||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType,
|
||||
K9.ACCEPTABLE_ATTACHMENT_VIEW_TYPES))
|
||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType,
|
||||
K9.UNACCEPTABLE_ATTACHMENT_VIEW_TYPES)))
|
||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType, K9.ACCEPTABLE_ATTACHMENT_VIEW_TYPES))
|
||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType, K9.UNACCEPTABLE_ATTACHMENT_VIEW_TYPES)))
|
||||
{
|
||||
attachmentView.setVisibility(View.GONE);
|
||||
}
|
||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType,
|
||||
K9.ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES))
|
||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType,
|
||||
K9.UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES)))
|
||||
if ((!MimeUtility.mimeTypeMatches(attachment.contentType, K9.ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES))
|
||||
|| (MimeUtility.mimeTypeMatches(attachment.contentType, K9.UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES)))
|
||||
{
|
||||
attachmentDownload.setVisibility(View.GONE);
|
||||
}
|
||||
@ -1905,7 +1915,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
attachmentDownload.setOnClickListener(this);
|
||||
attachmentDownload.setTag(attachment);
|
||||
attachmentName.setText(name);
|
||||
attachmentInfo.setText(SizeFormatter.formatSize(getApplication(), size));
|
||||
attachmentInfo.setText(SizeFormatter.formatSize(getApplication(), attachment.size));
|
||||
Bitmap previewIcon = getPreviewIcon(attachment);
|
||||
if (previewIcon != null)
|
||||
{
|
||||
@ -1916,15 +1926,7 @@ public class MessageView extends K9Activity implements OnClickListener
|
||||
attachmentIcon.setImageResource(R.drawable.attached_image_placeholder);
|
||||
}
|
||||
mHandler.addAttachment(view);
|
||||
}
|
||||
if (part.getBody() instanceof Multipart)
|
||||
{
|
||||
Multipart mp = (Multipart) part.getBody();
|
||||
for (int i = 0; i < mp.getCount(); i++)
|
||||
{
|
||||
renderAttachments(mp.getBodyPart(i), depth + 1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
class Listener extends MessagingListener
|
||||
|
Loading…
x
Reference in New Issue
Block a user