Search in sources :

Example 81 with Message

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

the class MessageBuilderTest method build_withMessageAttachment_shouldAttachAsApplicationOctetStream.

@Test
public void build_withMessageAttachment_shouldAttachAsApplicationOctetStream() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    Attachment attachment = createAttachmentWithContent("message/rfc822", "attach.txt", TEST_ATTACHMENT_TEXT);
    messageBuilder.setAttachments(Collections.singletonList(attachment));
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_MESSAGE_ATTACH, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Attachment(com.fsck.k9.activity.misc.Attachment) Test(org.junit.Test)

Example 82 with Message

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

the class MessageBuilderTest method build_shouldSucceed.

@Test
public void build_shouldSucceed() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals("text/plain", message.getMimeType());
    assertEquals(TEST_SUBJECT, message.getSubject());
    assertEquals(TEST_IDENTITY_ADDRESS, message.getFrom()[0]);
    assertArrayEquals(TEST_TO, message.getRecipients(RecipientType.TO));
    assertArrayEquals(TEST_CC, message.getRecipients(RecipientType.CC));
    assertArrayEquals(TEST_BCC, message.getRecipients(RecipientType.BCC));
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 83 with Message

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

the class EncryptionDetectorTest method isEncrypted_withPlainTextAndPreambleWithInlinePgp_shouldReturnFalse.

@Test
public void isEncrypted_withPlainTextAndPreambleWithInlinePgp_shouldReturnFalse() throws Exception {
    Message message = createTextMessage("text/plain", "" + "preamble" + CRLF + "-----BEGIN PGP MESSAGE-----" + CRLF + "some encrypted stuff here" + CRLF + "-----END PGP MESSAGE-----" + CRLF + "epilogue");
    when(textPartFinder.findFirstTextPart(message)).thenReturn(message);
    boolean encrypted = encryptionDetector.isEncrypted(message);
    assertFalse(encrypted);
}
Also used : MessageCreationHelper.createMultipartMessage(com.fsck.k9.message.MessageCreationHelper.createMultipartMessage) MessageCreationHelper.createMessage(com.fsck.k9.message.MessageCreationHelper.createMessage) MessageCreationHelper.createTextMessage(com.fsck.k9.message.MessageCreationHelper.createTextMessage) Message(com.fsck.k9.mail.Message) Test(org.junit.Test)

Example 84 with Message

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

the class EncryptionDetectorTest method isEncrypted_withQuotedInlinePgp_shouldReturnFalse.

@Test
public void isEncrypted_withQuotedInlinePgp_shouldReturnFalse() throws Exception {
    Message message = createTextMessage("text/plain", "" + "good talk!" + CRLF + CRLF + "> -----BEGIN PGP MESSAGE-----" + CRLF + "> some encrypted stuff here" + CRLF + "> -----END PGP MESSAGE-----" + CRLF + CRLF + "-- " + CRLF + "my signature");
    when(textPartFinder.findFirstTextPart(message)).thenReturn(message);
    boolean encrypted = encryptionDetector.isEncrypted(message);
    assertFalse(encrypted);
}
Also used : MessageCreationHelper.createMultipartMessage(com.fsck.k9.message.MessageCreationHelper.createMultipartMessage) MessageCreationHelper.createMessage(com.fsck.k9.message.MessageCreationHelper.createMessage) MessageCreationHelper.createTextMessage(com.fsck.k9.message.MessageCreationHelper.createTextMessage) Message(com.fsck.k9.mail.Message) Test(org.junit.Test)

Example 85 with Message

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

the class MessagePreviewCreatorTest method createPreview_withTextPart.

@Test
public void createPreview_withTextPart() throws Exception {
    Message message = createDummyMessage();
    Part textPart = createTextPart("text/plain");
    when(encryptionDetector.isEncrypted(message)).thenReturn(false);
    when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
    when(previewTextExtractor.extractPreview(textPart)).thenReturn("expected");
    PreviewResult result = previewCreator.createPreview(message);
    assertTrue(result.isPreviewTextAvailable());
    assertEquals(PreviewType.TEXT, result.getPreviewType());
    assertEquals("expected", result.getPreviewText());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MessageCreationHelper.createEmptyPart(com.fsck.k9.message.MessageCreationHelper.createEmptyPart) Part(com.fsck.k9.mail.Part) MessageCreationHelper.createTextPart(com.fsck.k9.message.MessageCreationHelper.createTextPart) 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