Search in sources :

Example 16 with FetchProfile

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

the class WebDavSync method downloadLargeMessages.

private void downloadLargeMessages(final SyncConfig syncConfig, final WebDavFolder remoteFolder, final BackendFolder backendFolder, List<WebDavMessage> largeMessages, final AtomicInteger progress, final AtomicInteger newMessages, final int todo, FetchProfile fp, SyncListener listener) throws MessagingException {
    final String folder = remoteFolder.getServerId();
    Timber.d("SYNC: Fetching large messages for folder %s", folder);
    int maxDownloadSize = syncConfig.getMaximumAutoDownloadMessageSize();
    remoteFolder.fetch(largeMessages, fp, null, maxDownloadSize);
    for (WebDavMessage message : largeMessages) {
        downloadSaneBody(syncConfig, remoteFolder, backendFolder, message);
        String messageServerId = message.getUid();
        Timber.v("About to notify listeners that we got a new large message %s:%s:%s", accountName, folder, messageServerId);
        // Update the listener with what we've found
        progress.incrementAndGet();
        // TODO do we need to re-fetch this here?
        Set<Flag> flags = backendFolder.getMessageFlags(messageServerId);
        // not marked as read.
        if (!flags.contains(Flag.SEEN)) {
            newMessages.incrementAndGet();
        }
        listener.syncProgress(folder, progress.get(), todo);
        listener.syncNewMessage(folder, messageServerId, false);
    }
    Timber.d("SYNC: Done fetching large messages for folder %s", folder);
}
Also used : WebDavMessage(com.fsck.k9.mail.store.webdav.WebDavMessage) Flag(com.fsck.k9.mail.Flag)

Example 17 with FetchProfile

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

the class WebDavSync method refreshLocalMessageFlags.

private void refreshLocalMessageFlags(final SyncConfig syncConfig, final WebDavFolder remoteFolder, final BackendFolder backendFolder, List<WebDavMessage> syncFlagMessages, final AtomicInteger progress, final int todo, SyncListener listener) throws MessagingException {
    final String folder = remoteFolder.getServerId();
    Timber.d("SYNC: About to sync flags for %d remote messages for folder %s", syncFlagMessages.size(), folder);
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.FLAGS);
    List<WebDavMessage> undeletedMessages = new LinkedList<>();
    for (WebDavMessage message : syncFlagMessages) {
        if (!message.isSet(Flag.DELETED)) {
            undeletedMessages.add(message);
        }
    }
    int maxDownloadSize = syncConfig.getMaximumAutoDownloadMessageSize();
    remoteFolder.fetch(undeletedMessages, fp, null, maxDownloadSize);
    for (WebDavMessage remoteMessage : syncFlagMessages) {
        boolean messageChanged = syncFlags(syncConfig, backendFolder, remoteMessage);
        if (messageChanged) {
            listener.syncFlagChanged(folder, remoteMessage.getUid());
        }
        progress.incrementAndGet();
        listener.syncProgress(folder, progress.get(), todo);
    }
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) WebDavMessage(com.fsck.k9.mail.store.webdav.WebDavMessage) LinkedList(java.util.LinkedList)

Example 18 with FetchProfile

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

the class WebDavFolderTest method folder_can_fetch_less_than_10_envelopes.

@Test
public void folder_can_fetch_less_than_10_envelopes() throws MessagingException {
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        WebDavMessage mockMessage = createWebDavMessage(i);
        messages.add(mockMessage);
    }
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with FetchProfile

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

the class WebDavFolderTest method folder_can_handle_empty_response_to_body_request.

@Test
public void folder_can_handle_empty_response_to_body_request() throws MessagingException, IOException {
    setupStoreForMessageFetching();
    List<WebDavMessage> messages = setup25MessagesToFetch();
    when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(new Answer<HttpResponse>() {

        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpResponse httpResponse = mock(HttpResponse.class);
            StatusLine statusLine = mock(StatusLine.class);
            when(httpResponse.getStatusLine()).thenReturn(statusLine);
            when(statusLine.getStatusCode()).thenReturn(200);
            return httpResponse;
        }
    });
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.BODY_SANE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
    verify(listener, times(25)).messageStarted(any(String.class), anyInt(), eq(25));
    verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), eq(25));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) StatusLine(org.apache.http.StatusLine) FetchProfile(com.fsck.k9.mail.FetchProfile) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 20 with FetchProfile

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

the class WebDavFolderTest method folder_can_fetch_more_than_10_envelopes.

@Test
public void folder_can_fetch_more_than_10_envelopes() throws MessagingException {
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        WebDavMessage mockMessage = createWebDavMessage(i);
        messages.add(mockMessage);
    }
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

FetchProfile (com.fsck.k9.mail.FetchProfile)49 Test (org.junit.Test)27 LocalMessage (com.fsck.k9.mailstore.LocalMessage)15 MessagingException (com.fsck.k9.mail.MessagingException)12 ArrayList (java.util.ArrayList)10 LocalFolder (com.fsck.k9.mailstore.LocalFolder)9 LocalStore (com.fsck.k9.mailstore.LocalStore)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 Date (java.util.Date)8 Message (com.fsck.k9.mail.Message)7 SuppressLint (android.annotation.SuppressLint)6 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5 Multipart (com.fsck.k9.mail.Multipart)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 WebDavMessage (com.fsck.k9.mail.store.webdav.WebDavMessage)4 LinkedList (java.util.LinkedList)4 HttpResponse (org.apache.http.HttpResponse)4 StatusLine (org.apache.http.StatusLine)4