Search in sources :

Example 66 with LocalMessage

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

the class MessageLoaderHelper method startOrResumeDecodeMessage.

// decode message
private void startOrResumeDecodeMessage() {
    LocalMessageExtractorLoader loader = (LocalMessageExtractorLoader) loaderManager.<MessageViewInfo>getLoader(DECODE_MESSAGE_LOADER_ID);
    boolean isLoaderStale = (loader == null) || !loader.isCreatedFor(localMessage, messageCryptoAnnotations);
    if (isLoaderStale) {
        Timber.d("Creating new decode message loader");
        loaderManager.restartLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
    } else {
        Timber.d("Reusing decode message loader");
        loaderManager.initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
    }
}
Also used : LocalMessageExtractorLoader(com.fsck.k9.ui.message.LocalMessageExtractorLoader)

Example 67 with LocalMessage

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

the class MessageLoaderHelper method startOrResumeLocalMessageLoader.

// load from database
private void startOrResumeLocalMessageLoader() {
    LocalMessageLoader loader = (LocalMessageLoader) loaderManager.<LocalMessage>getLoader(LOCAL_MESSAGE_LOADER_ID);
    boolean isLoaderStale = (loader == null) || !loader.isCreatedFor(messageReference);
    if (isLoaderStale) {
        Timber.d("Creating new local message loader");
        cancelAndClearCryptoOperation();
        cancelAndClearDecodeLoader();
        loaderManager.restartLoader(LOCAL_MESSAGE_LOADER_ID, null, localMessageLoaderCallback);
    } else {
        Timber.d("Reusing local message loader");
        loaderManager.initLoader(LOCAL_MESSAGE_LOADER_ID, null, localMessageLoaderCallback);
    }
}
Also used : LocalMessageLoader(com.fsck.k9.ui.message.LocalMessageLoader)

Example 68 with LocalMessage

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

the class NewMailNotificationsTest method testAddNewMailNotificationWithPrivacyModeEnabled.

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

Example 69 with LocalMessage

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

the class NewMailNotificationsTest method testAddNewMailNotificationTwice.

@Test
public void testAddNewMailNotificationTwice() throws Exception {
    int notificationIndexOne = 0;
    int notificationIndexTwo = 1;
    LocalMessage messageOne = createLocalMessage();
    LocalMessage messageTwo = createLocalMessage();
    NotificationContent contentOne = createNotificationContent();
    NotificationContent contentTwo = createNotificationContent();
    NotificationHolder holderOne = createNotificationHolder(contentOne, notificationIndexOne);
    NotificationHolder holderTwo = createNotificationHolder(contentTwo, notificationIndexTwo);
    addToNotificationContentCreator(messageOne, contentOne);
    addToNotificationContentCreator(messageTwo, contentTwo);
    whenAddingContentReturn(contentOne, AddNotificationResult.newNotification(holderOne));
    whenAddingContentReturn(contentTwo, AddNotificationResult.newNotification(holderTwo));
    Notification wearNotificationOne = createNotification();
    Notification wearNotificationTwo = createNotification();
    Notification summaryNotification = createNotification();
    addToWearNotifications(holderOne, wearNotificationOne);
    addToWearNotifications(holderTwo, wearNotificationTwo);
    addToDeviceNotifications(summaryNotification);
    newMailNotifications.addNewMailNotification(account, messageOne, 42);
    newMailNotifications.addNewMailNotification(account, messageTwo, 42);
    int wearNotificationIdOne = NotificationIds.getNewMailStackedNotificationId(account, notificationIndexOne);
    int wearNotificationIdTwo = NotificationIds.getNewMailStackedNotificationId(account, notificationIndexTwo);
    int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    verify(notificationManager).notify(wearNotificationIdOne, wearNotificationOne);
    verify(notificationManager).notify(wearNotificationIdTwo, wearNotificationTwo);
    verify(notificationManager, times(2)).notify(summaryNotificationId, summaryNotification);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Notification(android.app.Notification) Test(org.junit.Test)

Example 70 with LocalMessage

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

the class NewMailNotificationsTest method testRemoveNewMailNotificationWithUnknownMessageReference.

@Test
public void testRemoveNewMailNotificationWithUnknownMessageReference() throws Exception {
    enablePrivacyMode();
    MessageReference messageReference = createMessageReference(1);
    int notificationIndex = 0;
    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.unknownNotification());
    newMailNotifications.removeNewMailNotification(account, messageReference);
    verify(notificationManager, never()).cancel(anyInt());
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessageReference(com.fsck.k9.activity.MessageReference) Notification(android.app.Notification) Test(org.junit.Test)

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