Search in sources :

Example 21 with LocalMessage

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

the class MessagingController method downloadPartial.

private void downloadPartial(Folder remoteFolder, LocalFolder localFolder, Message message) throws MessagingException {
    /*
         * We have a structure to deal with, from which
         * we can pull down the parts we want to actually store.
         * Build a list of parts we are interested in. Text parts will be downloaded
         * right now, attachments will be left for later.
         */
    Set<Part> viewables = MessageExtractor.collectTextParts(message);
    /*
         * Now download the parts we're interested in storing.
         */
    for (Part part : viewables) {
        remoteFolder.fetchPart(message, part, null);
    }
    // Store the updated message locally
    localFolder.appendMessages(Collections.singletonList(message));
    Message localMessage = localFolder.getMessage(message.getUid());
    // Set a flag indicating this message has been fully downloaded and can be
    // viewed.
    localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) Part(com.fsck.k9.mail.Part)

Example 22 with LocalMessage

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

the class MessagingController method isMessageSuppressed.

private boolean isMessageSuppressed(LocalMessage message) {
    long messageId = message.getId();
    long folderId = message.getFolder().getId();
    EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context);
    return cache.isMessageHidden(messageId, folderId);
}
Also used : EmailProviderCache(com.fsck.k9.cache.EmailProviderCache)

Example 23 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage 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 24 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage 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 25 with LocalMessage

use of com.fsck.k9.mailstore.LocalMessage 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

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