Search in sources :

Example 56 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findEncryptedPartsShouldReturnEmptyListForSimpleMessage.

@Test
public void findEncryptedPartsShouldReturnEmptyListForSimpleMessage() throws Exception {
    MimeMessage message = new MimeMessage();
    message.setBody(new TextBody("message text"));
    List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
    assertEquals(0, encryptedParts.size());
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 57 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findPrimaryCryptoPart_withEmptyMultipartMixed_shouldReturnNull.

@Test
public void findPrimaryCryptoPart_withEmptyMultipartMixed_shouldReturnNull() throws Exception {
    List<Part> outputExtraParts = new ArrayList<>();
    Message message = messageFromBody(multipart("mixed"));
    Part cryptoPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, outputExtraParts);
    assertNull(cryptoPart);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class MessageDecryptVerifierTest method findSigned__withComplexMultipartSigned__shouldReturnRoot.

@Test
public void findSigned__withComplexMultipartSigned__shouldReturnRoot() throws Exception {
    Message message = messageFromBody(multipart("signed", multipart("mixed", bodypart("text/plain"), bodypart("application/pdf")), bodypart("application/pgp-signature")));
    List<Part> signedParts = MessageDecryptVerifier.findSignedParts(message, messageCryptoAnnotations);
    assertEquals(1, signedParts.size());
    assertSame(message, signedParts.get(0));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 59 with Message

use of com.fsck.k9.mail.Message 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));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 60 with Message

use of com.fsck.k9.mail.Message in project k-9 by k9mail.

the class UidReverseComparatorTest method compare_withMessageWithInvalidUidAndNullArgument_shouldReturnZero.

@Test
public void compare_withMessageWithInvalidUidAndNullArgument_shouldReturnZero() throws Exception {
    Message messageLeft = createMessageWithInvalidUid();
    Message messageRight = null;
    int result = comparator.compare(messageLeft, messageRight);
    assertEquals("result must be 0 when both arguments are not a message with valid UID", 0, result);
}
Also used : Message(com.fsck.k9.mail.Message) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)127 Message (com.fsck.k9.mail.Message)111 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)102 Part (com.fsck.k9.mail.Part)47 LocalMessage (com.fsck.k9.mailstore.LocalMessage)46 MessagingException (com.fsck.k9.mail.MessagingException)41 ArrayList (java.util.ArrayList)41 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)33 BodyPart (com.fsck.k9.mail.BodyPart)32 Account (com.fsck.k9.Account)27 LocalFolder (com.fsck.k9.mailstore.LocalFolder)24 TextBody (com.fsck.k9.mail.internet.TextBody)23 IOException (java.io.IOException)22 Address (com.fsck.k9.mail.Address)21 LocalStore (com.fsck.k9.mailstore.LocalStore)21 Date (java.util.Date)20 MessageReference (com.fsck.k9.activity.MessageReference)16 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)16 Folder (com.fsck.k9.mail.Folder)14 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)13