Search in sources :

Example 71 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.

the class NewMailNotificationsTest method testRemoveNewMailNotificationWithCreateNotification.

@Test
public void testRemoveNewMailNotificationWithCreateNotification() throws Exception {
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
    LocalMessage message = createLocalMessage();
    NotificationContent contentOne = createNotificationContent();
    NotificationContent contentTwo = createNotificationContent();
    NotificationHolder holderOne = createNotificationHolder(contentOne, notificationIndex);
    NotificationHolder holderTwo = createNotificationHolder(contentTwo, notificationIndex);
    addToNotificationContentCreator(message, contentOne);
    whenAddingContentReturn(contentOne, AddNotificationResult.newNotification(holderOne));
    Notification summaryNotification = createNotification();
    addToDeviceNotifications(summaryNotification);
    Notification wearNotificationOne = createNotification();
    Notification wearNotificationTwo = createNotification();
    addToWearNotifications(holderOne, wearNotificationOne);
    addToWearNotifications(holderTwo, wearNotificationTwo);
    newMailNotifications.addNewMailNotification(account, message, 23);
    whenRemovingContentReturn(messageReference, RemoveNotificationResult.createNotification(holderTwo));
    newMailNotifications.removeNewMailNotification(account, messageReference);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).cancel(notificationId);
    verify(notificationManager).notify(notificationId, wearNotificationTwo);
    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 72 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.

the class ReconstructMessageFromDatabaseTest method readMessageFromDatabase.

protected LocalMessage readMessageFromDatabase(LocalFolder folder, MimeMessage message) throws MessagingException {
    LocalMessage localMessage = folder.getMessage(message.getUid());
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.ENVELOPE);
    fp.add(FetchProfile.Item.BODY);
    folder.fetch(Collections.singletonList(localMessage), fp, null);
    folder.close();
    return localMessage;
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile)

Example 73 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage in project k-9 by k9mail.

the class ReconstructMessageFromDatabaseTest method testAddMissingPart.

public void testAddMissingPart() throws MessagingException, IOException {
    LocalFolder folder = createFolderInDatabase();
    MimeMessage message = new MimeMessage();
    message.addHeader("To", "to@example.com");
    message.addHeader("MIME-Version", "1.0");
    message.addHeader("Content-Type", "text/plain");
    message.setServerExtra("text");
    saveMessageToDatabase(folder, message);
    LocalMessage localMessage = readMessageFromDatabase(folder, message);
    assertEquals("to@example.com", localMessage.getHeader("To")[0]);
    assertEquals("text/plain", localMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]);
    assertEquals("text", localMessage.getServerExtra());
    assertNull(localMessage.getBody());
    Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
    localMessage.setBody(body);
    folder.addPartToMessage(localMessage, localMessage);
    LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
    String reconstructedMessage = writeMessageToString(completeLocalMessage);
    assertEquals("To: to@example.com\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Test message body", reconstructedMessage);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) Body(com.fsck.k9.mail.Body)

Aggregations

LocalMessage (com.fsck.k9.mailstore.LocalMessage)42 Test (org.junit.Test)23 FetchProfile (com.fsck.k9.mail.FetchProfile)19 Message (com.fsck.k9.mail.Message)19 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)19 MessagingException (com.fsck.k9.mail.MessagingException)15 LocalFolder (com.fsck.k9.mailstore.LocalFolder)13 LocalStore (com.fsck.k9.mailstore.LocalStore)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)10 ArrayList (java.util.ArrayList)9 Notification (android.app.Notification)8 Part (com.fsck.k9.mail.Part)8 MessageReference (com.fsck.k9.activity.MessageReference)7 Multipart (com.fsck.k9.mail.Multipart)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 SuppressLint (android.annotation.SuppressLint)6 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)6 IOException (java.io.IOException)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5