am 39121c75: Fix display of inline images
* commit '39121c758dcc919b5fde4c893d488916e26d3140': Fix display of inline images
This commit is contained in:
commit
8e09307b27
|
@ -412,8 +412,17 @@ public class MimeUtility {
|
|||
dispositionType = MimeUtility.getHeaderParameter(disposition, null);
|
||||
dispositionFilename = MimeUtility.getHeaderParameter(disposition, "filename");
|
||||
}
|
||||
// An attachment filename can be defined in either the Content-Disposition header
|
||||
// or the Content-Type header. Content-Disposition is preferred, so we only try
|
||||
// the Content-Type header as a last resort.
|
||||
if (dispositionFilename == null) {
|
||||
String contentType = part.getContentType();
|
||||
dispositionFilename = MimeUtility.getHeaderParameter(contentType, "name");
|
||||
}
|
||||
boolean attachmentDisposition = "attachment".equalsIgnoreCase(dispositionType);
|
||||
boolean inlineDisposition = "inline".equalsIgnoreCase(dispositionType);
|
||||
// If a disposition is not specified, default to "inline"
|
||||
boolean inlineDisposition = dispositionType == null
|
||||
|| "inline".equalsIgnoreCase(dispositionType);
|
||||
|
||||
// A guess that this part is intended to be an attachment
|
||||
boolean attachment = attachmentDisposition
|
||||
|
|
|
@ -30,6 +30,8 @@ import com.android.emailcommon.mail.MessageTestUtils.MultipartBuilder;
|
|||
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
@ -345,6 +347,58 @@ public class MimeUtilityTest extends TestCase {
|
|||
final Part actual2_2 = MimeUtility.findPartByContentId(msg2, cid2);
|
||||
assertEquals("found part from mixed multipart", cid2bp, actual2_2);
|
||||
}
|
||||
|
||||
/** Tests for findPartByContentId(Part part, String contentId) */
|
||||
public void testCollectParts() throws MessagingException, Exception {
|
||||
// golden cases; these will marked as attachments
|
||||
final String cid1 = "<i_12e8248b4f0874cb>";
|
||||
final Part cid1bp = MessageTestUtils.bodyPart("image/gif; name=\"im1.gif\"", cid1);
|
||||
final String cid2 = "<ii_12e8248b4f0874cb>";
|
||||
final Part cid2bp = MessageTestUtils.bodyPart("image/gif", cid2);
|
||||
cid2bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "inline; filename=\"im2.gif\"");
|
||||
final String cid3 = "<iii_12e8248b4f0874cb>";
|
||||
final Part cid3bp = MessageTestUtils.bodyPart("image/gif", cid3);
|
||||
cid3bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"im3.gif\"");
|
||||
// error cases; these will NOT be marked as attachments
|
||||
final String cid4 = "<iv_12e8248b4f0874cb>";
|
||||
final Part cid4bp = MessageTestUtils.bodyPart("image/gif", cid4); // no name attr
|
||||
final String cid5 = "<v_12e8248b4f0874cb>";
|
||||
final Part cid5bp = MessageTestUtils.bodyPart("image/gif", cid5);
|
||||
cid5bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "inline"); // no filename attr
|
||||
|
||||
// Default content disposition
|
||||
final ArrayList<Part> view1 = new ArrayList<Part>();
|
||||
final ArrayList<Part> attach1 = new ArrayList<Part>();
|
||||
MimeUtility.collectParts(cid1bp, view1, attach1);
|
||||
assertEquals(1, attach1.size());
|
||||
assertEquals(attach1.get(0), cid1bp);
|
||||
|
||||
// Explicit content disposition of "inline"
|
||||
final ArrayList<Part> view2 = new ArrayList<Part>();
|
||||
final ArrayList<Part> attach2 = new ArrayList<Part>();
|
||||
MimeUtility.collectParts(cid2bp, view2, attach2);
|
||||
assertEquals(1, attach2.size());
|
||||
assertEquals(attach2.get(0), cid2bp);
|
||||
|
||||
// Explicit content disposition of "attachment"
|
||||
final ArrayList<Part> view3 = new ArrayList<Part>();
|
||||
final ArrayList<Part> attach3 = new ArrayList<Part>();
|
||||
MimeUtility.collectParts(cid3bp, view3, attach3);
|
||||
assertEquals(1, attach3.size());
|
||||
assertEquals(attach3.get(0), cid3bp);
|
||||
|
||||
// Default content disposition; missing name attribute on content-type
|
||||
final ArrayList<Part> view4 = new ArrayList<Part>();
|
||||
final ArrayList<Part> attach4 = new ArrayList<Part>();
|
||||
MimeUtility.collectParts(cid4bp, view4, attach4);
|
||||
assertEquals(0, attach4.size());
|
||||
|
||||
// Content disposition of "inline"; missing filename attribute
|
||||
final ArrayList<Part> view5 = new ArrayList<Part>();
|
||||
final ArrayList<Part> attach5 = new ArrayList<Part>();
|
||||
MimeUtility.collectParts(cid5bp, view5, attach5);
|
||||
assertEquals(0, attach5.size());
|
||||
}
|
||||
|
||||
/** Tests for getTextFromPart(Part part) */
|
||||
public void testGetTextFromPartContentTypeCase() throws MessagingException {
|
||||
|
|
Loading…
Reference in New Issue