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);
}
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);
}
}
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);
}
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));
}
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);
}
Aggregations