Search in sources :

Example 31 with LocalMessage

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

the class MessagingControllerTest method synchronizeMailboxSynchronous_withAccountSetToSyncRemoteDeletions_shouldDeleteLocalCopiesOfDeletedMessages.

@Test
public void synchronizeMailboxSynchronous_withAccountSetToSyncRemoteDeletions_shouldDeleteLocalCopiesOfDeletedMessages() throws Exception {
    messageCountInRemoteFolder(0);
    LocalMessage localCopyOfRemoteDeletedMessage = mock(LocalMessage.class);
    when(account.syncRemoteDeletions()).thenReturn(true);
    when(localFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
    when(localFolder.getMessagesByUids(any(List.class))).thenReturn(Collections.singletonList(localCopyOfRemoteDeletedMessage));
    controller.synchronizeMailboxSynchronous(account, FOLDER_NAME, listener, remoteFolder);
    verify(localFolder).destroyMessages(messageListCaptor.capture());
    assertEquals(localCopyOfRemoteDeletedMessage, messageListCaptor.getValue().get(0));
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 32 with LocalMessage

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

the class MessagingControllerTest method searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage.

@Test
public void searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage() throws Exception {
    setAccountsInPreferences(Collections.singletonMap("1", account));
    LocalMessage localMessage = mock(LocalMessage.class);
    when(localMessage.getFolder()).thenReturn(localFolder);
    when(search.getAccountUuids()).thenReturn(new String[] { "allAccounts" });
    when(localStore.searchForMessages(any(MessageRetrievalListener.class), eq(search))).thenThrow(new MessagingException("Test"));
    controller.searchLocalMessagesSynchronous(search, listener);
    verify(localStore).searchForMessages(messageRetrievalListenerCaptor.capture(), eq(search));
    messageRetrievalListenerCaptor.getValue().messageFinished(localMessage, 1, 1);
    verify(listener).listLocalMessagesAddMessages(eq(account), eq((String) null), eq(Collections.singletonList(localMessage)));
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException) Matchers.anyString(org.mockito.Matchers.anyString) MessageRetrievalListener(com.fsck.k9.mail.MessageRetrievalListener) Test(org.junit.Test)

Example 33 with LocalMessage

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

the class MessageViewFragment method delete.

private void delete() {
    if (mMessage != null) {
        // Disable the delete button after it's tapped (to try to prevent
        // accidental clicks)
        mFragmentListener.disableDeleteAction();
        LocalMessage messageToDelete = mMessage;
        mFragmentListener.showNextMessageOrReturn();
        mController.deleteMessage(mMessageReference, null);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage)

Example 34 with LocalMessage

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

the class MessagingController method moveOrDeleteSentMessage.

private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalFolder localFolder, LocalMessage message) throws MessagingException {
    if (!account.hasSentFolder()) {
        Timber.i("Account does not have a sent mail folder; deleting sent message");
        message.setFlag(Flag.DELETED, true);
    } else {
        LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName());
        Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
        localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
        Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
        PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid());
        queuePendingCommand(account, command);
        processPendingCommands(account);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 35 with LocalMessage

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

the class MessagingController method sendAlternate.

public void sendAlternate(Context context, Account account, LocalMessage message) {
    Timber.d("Got message %s:%s:%s for sendAlternate", account.getDescription(), message.getFolder(), message.getUid());
    Intent msg = new Intent(Intent.ACTION_SEND);
    String quotedText = null;
    Part part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
    if (part == null) {
        part = MimeUtility.findFirstPartByMimeType(message, "text/html");
    }
    if (part != null) {
        quotedText = MessageExtractor.getTextFromPart(part);
    }
    if (quotedText != null) {
        msg.putExtra(Intent.EXTRA_TEXT, quotedText);
    }
    msg.putExtra(Intent.EXTRA_SUBJECT, message.getSubject());
    Address[] from = message.getFrom();
    String[] senders = new String[from.length];
    for (int i = 0; i < from.length; i++) {
        senders[i] = from[i].toString();
    }
    msg.putExtra(Intents.Share.EXTRA_FROM, senders);
    Address[] to = message.getRecipients(RecipientType.TO);
    String[] recipientsTo = new String[to.length];
    for (int i = 0; i < to.length; i++) {
        recipientsTo[i] = to[i].toString();
    }
    msg.putExtra(Intent.EXTRA_EMAIL, recipientsTo);
    Address[] cc = message.getRecipients(RecipientType.CC);
    String[] recipientsCc = new String[cc.length];
    for (int i = 0; i < cc.length; i++) {
        recipientsCc[i] = cc[i].toString();
    }
    msg.putExtra(Intent.EXTRA_CC, recipientsCc);
    msg.setType("text/plain");
    context.startActivity(Intent.createChooser(msg, context.getString(R.string.send_alternate_chooser_title)));
}
Also used : Address(com.fsck.k9.mail.Address) Part(com.fsck.k9.mail.Part) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

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