Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f366e504 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #2892 from k9mail/GH-2891_display_inline_text_part_as_attachment

Only hide inline image parts with Content-Id header
parents 0a6ef2b7 9df026aa
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.net.Uri;
@@ -131,12 +132,12 @@ public class AttachmentInfoExtractor {
            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.
        // Inline parts with a Content-Id header and a MIME type of image/* are probably components of an HTML message,
        // not attachments.
        if (contentDisposition != null &&
                MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)") &&
                part.getHeader(MimeHeader.HEADER_CONTENT_ID).length > 0) {
                part.getHeader(MimeHeader.HEADER_CONTENT_ID).length > 0 &&
                mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("image/")) {
            inlineAttachment = true;
        }

+15 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public class AttachmentInfoExtractorTest {
    }

    @Test
    public void extractInfoForDb__withDispositionInlineAndContentId__shouldReturnInlineAttachment()
    public void extractInfoForDb__withDispositionInlineAndContentIdAndMissingMimeType__shouldNotReturnInlineAttachment()
            throws Exception {
        Part part = new MimeBodyPart();
        part.addRawHeader(MimeHeader.HEADER_CONTENT_ID, MimeHeader.HEADER_CONTENT_ID + ": " + TEST_CONTENT_ID);
@@ -139,6 +139,20 @@ public class AttachmentInfoExtractorTest {

        AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);

        assertFalse(attachmentViewInfo.inlineAttachment);
    }

    @Test
    public void extractInfoForDb__withDispositionInlineAndContentIdAndImageMimeType__shouldReturnInlineAttachment()
            throws Exception {
        Part part = new MimeBodyPart();
        part.addRawHeader(MimeHeader.HEADER_CONTENT_TYPE, MimeHeader.HEADER_CONTENT_TYPE + ": image/png");
        part.addRawHeader(MimeHeader.HEADER_CONTENT_ID, MimeHeader.HEADER_CONTENT_ID + ": " + TEST_CONTENT_ID);
        part.addRawHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, MimeHeader.HEADER_CONTENT_DISPOSITION + ": " +
                "inline" + ";\n  filename=\"filename.ext\";\n  meaningless=\"dummy\"");

        AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);

        assertTrue(attachmentViewInfo.inlineAttachment);
    }