use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class AttachmentResolverTest method buildCidMap__onTwoPart__shouldReturnBothUris.
@Test
public void buildCidMap__onTwoPart__shouldReturnBothUris() throws Exception {
Multipart multipartBody = MimeMultipart.newInstance();
Part multipartPart = new MimeBodyPart(multipartBody);
BodyPart subPart1 = new MimeBodyPart();
BodyPart subPart2 = new MimeBodyPart();
multipartBody.addBodyPart(subPart1);
multipartBody.addBodyPart(subPart2);
subPart1.setHeader(MimeHeader.HEADER_CONTENT_ID, "cid-1");
subPart2.setHeader(MimeHeader.HEADER_CONTENT_ID, "cid-2");
when(attachmentInfoExtractor.extractAttachmentInfo(subPart1)).thenReturn(new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_1, false, subPart1, true));
when(attachmentInfoExtractor.extractAttachmentInfo(subPart2)).thenReturn(new AttachmentViewInfo(null, null, AttachmentViewInfo.UNKNOWN_SIZE, ATTACHMENT_TEST_URI_2, false, subPart2, true));
Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
assertEquals(2, result.size());
assertEquals(ATTACHMENT_TEST_URI_1, result.get("cid-1"));
assertEquals(ATTACHMENT_TEST_URI_2, result.get("cid-2"));
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class AttachmentResolverTest method buildCidMap__onMultipartWithNoParts__shouldReturnEmptyMap.
@Test
public void buildCidMap__onMultipartWithNoParts__shouldReturnEmptyMap() throws Exception {
Multipart multipartBody = MimeMultipart.newInstance();
Part multipartPart = new MimeBodyPart(multipartBody);
Map<String, Uri> result = AttachmentResolver.buildCidToAttachmentUriMap(attachmentInfoExtractor, multipartPart);
assertTrue(result.isEmpty());
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findEncryptedPartsShouldReturnMultipleEncryptedParts.
@Test
public void findEncryptedPartsShouldReturnMultipleEncryptedParts() throws Exception {
MimeMessage message = new MimeMessage();
MimeMultipart multipartMixed = MimeMultipart.newInstance();
multipartMixed.setSubType("mixed");
MimeMessageHelper.setBody(message, multipartMixed);
MimeMultipart multipartEncryptedOne = MimeMultipart.newInstance();
multipartEncryptedOne.setSubType("encrypted");
MimeBodyPart bodyPartOne = new MimeBodyPart(multipartEncryptedOne);
setContentTypeWithProtocol(bodyPartOne, MIME_TYPE_MULTIPART_ENCRYPTED, PROTCOL_PGP_ENCRYPTED);
multipartMixed.addBodyPart(bodyPartOne);
MimeBodyPart bodyPartTwo = new MimeBodyPart(null, "text/plain");
multipartMixed.addBodyPart(bodyPartTwo);
MimeMultipart multipartEncryptedThree = MimeMultipart.newInstance();
multipartEncryptedThree.setSubType("encrypted");
MimeBodyPart bodyPartThree = new MimeBodyPart(multipartEncryptedThree);
setContentTypeWithProtocol(bodyPartThree, MIME_TYPE_MULTIPART_ENCRYPTED, PROTCOL_PGP_ENCRYPTED);
multipartMixed.addBodyPart(bodyPartThree);
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
assertEquals(2, encryptedParts.size());
assertSame(bodyPartOne, encryptedParts.get(0));
assertSame(bodyPartThree, encryptedParts.get(1));
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class MessageDecryptVerifierTest method multipart.
MimeBodyPart multipart(String type, BodyPart... subParts) throws MessagingException {
MimeMultipart multiPart = MimeMultipart.newInstance();
multiPart.setSubType(type);
for (BodyPart subPart : subParts) {
multiPart.addBodyPart(subPart);
}
return new MimeBodyPart(multiPart);
}
use of com.fsck.k9.mail.internet.MimeBodyPart in project k-9 by k9mail.
the class LocalStoreTest method findPartById__withTwoTimesNestedLocalMessagePart.
@Test
public void findPartById__withTwoTimesNestedLocalMessagePart() throws Exception {
LocalBodyPart searchRoot = new LocalBodyPart(null, null, 1L, -1L);
LocalMimeMessage needlePart = new LocalMimeMessage(null, null, 123L);
MimeMultipart mimeMultipartInner = new MimeMultipart("boundary");
mimeMultipartInner.addBodyPart(new MimeBodyPart(needlePart));
MimeMultipart mimeMultipart = new MimeMultipart("boundary");
mimeMultipart.addBodyPart(new MimeBodyPart(mimeMultipartInner));
searchRoot.setBody(mimeMultipart);
Part part = LocalStore.findPartById(searchRoot, 123L);
assertSame(needlePart, part);
}
Aggregations