Search in sources :

Example 86 with Message

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

the class MessagePreviewCreatorTest method createPreview_withEmptyTextPart.

@Test
public void createPreview_withEmptyTextPart() throws Exception {
    Message message = createDummyMessage();
    Part textPart = createEmptyPart("text/plain");
    when(encryptionDetector.isEncrypted(message)).thenReturn(false);
    when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
    PreviewResult result = previewCreator.createPreview(message);
    assertFalse(result.isPreviewTextAvailable());
    assertEquals(PreviewType.NONE, result.getPreviewType());
    verifyNoMoreInteractions(previewTextExtractor);
}
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)

Example 87 with Message

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

the class MessagePreviewCreatorTest method createPreview_withPreviewTextExtractorThrowing.

@Test
public void createPreview_withPreviewTextExtractorThrowing() 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)).thenThrow(new PreviewExtractionException(""));
    PreviewResult result = previewCreator.createPreview(message);
    assertFalse(result.isPreviewTextAvailable());
    assertEquals(PreviewType.ERROR, result.getPreviewType());
}
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)

Example 88 with Message

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

the class NewMailNotificationsTest method testRemoveNewMailNotification.

@Test
public void testRemoveNewMailNotification() throws Exception {
    enablePrivacyMode();
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    LocalMessage message = createLocalMessage();
    NotificationContent content = createNotificationContent();
    NotificationHolder holder = createNotificationHolder(content, notificationIndex);
    addToNotificationContentCreator(message, content);
    whenAddingContentReturn(content, AddNotificationResult.newNotification(holder));
    Notification summaryNotification = createNotification();
    addToDeviceNotifications(summaryNotification);
    newMailNotifications.addNewMailNotification(account, message, 23);
    whenRemovingContentReturn(messageReference, RemoveNotificationResult.cancelNotification(notificationId));
    newMailNotifications.removeNewMailNotification(account, messageReference);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).cancel(notificationId);
    verify(notificationManager, times(2)).notify(summaryNotificationId, summaryNotification);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessageReference(com.fsck.k9.activity.MessageReference) Notification(android.app.Notification) Test(org.junit.Test)

Example 89 with Message

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

the class NewMailNotificationsTest method testAddNewMailNotificationWithCancelingExistingNotification.

@Test
public void testAddNewMailNotificationWithCancelingExistingNotification() throws Exception {
    int notificationIndex = 0;
    LocalMessage message = createLocalMessage();
    NotificationContent content = createNotificationContent();
    NotificationHolder holder = createNotificationHolder(content, notificationIndex);
    addToNotificationContentCreator(message, content);
    whenAddingContentReturn(content, AddNotificationResult.replaceNotification(holder));
    Notification wearNotification = createNotification();
    Notification summaryNotification = createNotification();
    addToWearNotifications(holder, wearNotification);
    addToDeviceNotifications(summaryNotification);
    newMailNotifications.addNewMailNotification(account, message, 42);
    int wearNotificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).notify(wearNotificationId, wearNotification);
    verify(notificationManager).cancel(wearNotificationId);
    verify(notificationManager).notify(summaryNotificationId, summaryNotification);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Notification(android.app.Notification) Test(org.junit.Test)

Example 90 with Message

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

the class NotificationContentCreatorTest method createFakeLocalMessage.

private LocalMessage createFakeLocalMessage(MessageReference messageReference) throws Exception {
    LocalMessage message = mock(LocalMessage.class);
    when(message.makeMessageReference()).thenReturn(messageReference);
    when(message.getPreviewType()).thenReturn(PreviewType.TEXT);
    when(message.getPreview()).thenReturn(PREVIEW);
    when(message.getSubject()).thenReturn(SUBJECT);
    when(message.getFrom()).thenReturn(new Address[] { new Address(SENDER_ADDRESS, SENDER_NAME) });
    when(message.getRecipients(RecipientType.TO)).thenReturn(new Address[] { new Address(RECIPIENT_ADDRESS, RECIPIENT_NAME) });
    return message;
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Address(com.fsck.k9.mail.Address)

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