diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 03267f2a2..e6e26aae5 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -285,6 +285,8 @@ Willkommen zum \"K-9 Mail\"-Setup. K-9 ist eine quelloffene E-Mail-Anwendung fü Anhang konnte nicht auf SD-Karte gespeichert werden. Wählen Sie \"Bilder anzeigen\", um eingebettete Bilder abzurufen. Bilder anzeigen + Zeige Anhänge + Mehr… Lade Anhang. Es wurde kein Anzeigeprogramm für %s gefunden. diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 5fd3c047d..405243d4b 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -2040,6 +2040,17 @@ public class MimeUtility { return DEFAULT_ATTACHMENT_MIME_TYPE; } + public static String getExtensionByMimeType(String mimeType) { + String lowerCaseMimeType = mimeType.toLowerCase(Locale.US); + for (String[] contentTypeMapEntry : MIME_TYPE_BY_EXTENSION_MAP) { + if (contentTypeMapEntry[1].equals(lowerCaseMimeType)) { + return contentTypeMapEntry[0]; + } + } + + return null; + } + /** * Convert some wrong MIME types encountered in the wild to canonical MIME types. * diff --git a/src/com/fsck/k9/view/AttachmentView.java b/src/com/fsck/k9/view/AttachmentView.java index f581c3db2..316668a4f 100644 --- a/src/com/fsck/k9/view/AttachmentView.java +++ b/src/com/fsck/k9/view/AttachmentView.java @@ -34,6 +34,7 @@ import com.fsck.k9.helper.SizeFormatter; import com.fsck.k9.helper.Utility; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.Part; +import com.fsck.k9.mail.internet.MimeHeader; import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBodyPart; import com.fsck.k9.provider.AttachmentProvider; @@ -101,7 +102,28 @@ public class AttachmentView extends FrameLayout { */ public void showFileBrowser(AttachmentView caller); } - public boolean populateFromPart(Part inputPart, Message message, Account account, MessagingController controller, MessagingListener listener) { + + /** + * Populates this view with information about the attachment. + * + *

+ * This method also decides which attachments are displayed when the "show attachments" button + * is pressed, and which attachments are only displayed after the "show more attachments" + * button was pressed.
+ * Inline attachments with content ID and unnamed attachments fall into the second category. + *

+ * + * @param inputPart + * @param message + * @param account + * @param controller + * @param listener + * + * @return {@code true} for a regular attachment. {@code false}, otherwise. + */ + public boolean populateFromPart(Part inputPart, Message message, Account account, + MessagingController controller, MessagingListener listener) { + boolean firstClassAttachment = true; try { part = (LocalAttachmentBodyPart) inputPart; @@ -112,8 +134,20 @@ public class AttachmentView extends FrameLayout { if (name == null) { name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } + if (name == null) { - return false; + firstClassAttachment = false; + String extension = MimeUtility.getExtensionByMimeType(contentType); + name = "noname" + ((extension != null) ? "." + extension : ""); + } + + // Inline parts with a content-id are almost certainly components of an HTML message + // not attachments. Only show them if the user pressed the button to show more + // attachments. + if (contentDisposition != null && + MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") + && part.getHeader(MimeHeader.HEADER_CONTENT_ID) != null) { + firstClassAttachment = false; } mAccount = account; @@ -180,7 +214,7 @@ public class AttachmentView extends FrameLayout { Log.e(K9.LOG_TAG, "error ", e); } - return true; + return firstClassAttachment; } private Bitmap getPreviewIcon() {