use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.
the class MessagingController method downloadSmallMessages.
private <T extends Message> void downloadSmallMessages(final Account account, final Folder<T> remoteFolder, final LocalFolder localFolder, List<T> smallMessages, final AtomicInteger progress, final int unreadBeforeStart, final AtomicInteger newMessages, final int todo, FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
remoteFolder.fetch(smallMessages, fp, new MessageRetrievalListener<T>() {
@Override
public void messageFinished(final T message, int number, int ofTotal) {
try {
if (!shouldImportMessage(account, message, earliestDate)) {
progress.incrementAndGet();
return;
}
// Store the updated message locally
final LocalMessage localMessage = localFolder.storeSmallMessage(message, new Runnable() {
@Override
public void run() {
progress.incrementAndGet();
}
});
// not marked as read.
if (!localMessage.isSet(Flag.SEEN)) {
newMessages.incrementAndGet();
}
Timber.v("About to notify listeners that we got a new small message %s:%s:%s", account, folder, message.getUid());
// Update the listener with what we've found
for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
if (shouldNotifyForMessage(account, localFolder, message)) {
// Notify with the localMessage so that we don't have to recalculate the content preview.
notificationController.addNewMailNotification(account, localMessage, unreadBeforeStart);
}
} catch (MessagingException me) {
addErrorMessage(account, null, me);
Timber.e(me, "SYNC: fetch small messages");
}
}
@Override
public void messageStarted(String uid, int number, int ofTotal) {
}
@Override
public void messagesFinished(int total) {
}
});
Timber.d("SYNC: Done fetching small messages for folder %s", folder);
}
use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.
the class MessagingController method fetchUnsyncedMessages.
private <T extends Message> void fetchUnsyncedMessages(final Account account, final Folder<T> remoteFolder, List<T> unsyncedMessages, final List<Message> smallMessages, final List<Message> largeMessages, final AtomicInteger progress, final int todo, FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
remoteFolder.fetch(unsyncedMessages, fp, new MessageRetrievalListener<T>() {
@Override
public void messageFinished(T message, int number, int ofTotal) {
try {
if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
if (K9.isDebug()) {
if (message.isSet(Flag.DELETED)) {
Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, " + "skipping", account, folder, message.getUid());
} else {
Timber.d("Newly downloaded message %s is older than %s, skipping", message.getUid(), earliestDate);
}
}
progress.incrementAndGet();
for (MessagingListener l : getListeners()) {
//TODO: This might be the source of poll count errors in the UI. Is todo always the same as ofTotal
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
}
return;
}
if (account.getMaximumAutoDownloadMessageSize() > 0 && message.getSize() > account.getMaximumAutoDownloadMessageSize()) {
largeMessages.add(message);
} else {
smallMessages.add(message);
}
} catch (Exception e) {
Timber.e(e, "Error while storing downloaded message.");
addErrorMessage(account, null, e);
}
}
@Override
public void messageStarted(String uid, int number, int ofTotal) {
}
@Override
public void messagesFinished(int total) {
// FIXME this method is almost never invoked by various Stores! Don't rely on it unless fixed!!
}
});
}
use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.
the class ImapFolderTest method fetch_withBodySaneFetchProfile_shouldIssueRespectiveCommand.
@Test
public void fetch_withBodySaneFetchProfile_shouldIssueRespectiveCommand() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.BODY_SANE);
when(storeConfig.getMaximumAutoDownloadMessageSize()).thenReturn(4096);
folder.fetch(messages, fetchProfile, null);
verify(imapConnection).sendCommand("UID FETCH 1 (UID BODY.PEEK[]<0.4096>)", false);
}
use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.
the class ImapFolderTest method fetch_withFlagsFetchProfile_shouldSetFlags.
@Test
public void fetch_withFlagsFetchProfile_shouldSetFlags() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.FLAGS);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("* 1 FETCH (FLAGS (\\Seen) UID 1)")).thenReturn(createImapResponse("x OK"));
folder.fetch(messages, fetchProfile, null);
ImapMessage imapMessage = messages.get(0);
verify(imapMessage).setFlagInternal(Flag.SEEN, true);
}
use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.
the class ImapFolderTest method fetch_withStructureFetchProfile_shouldIssueRespectiveCommand.
@Test
public void fetch_withStructureFetchProfile_shouldIssueRespectiveCommand() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
when(imapConnection.readResponse(any(ImapResponseCallback.class))).thenReturn(createImapResponse("x OK"));
List<ImapMessage> messages = createImapMessages("1");
FetchProfile fetchProfile = createFetchProfile(Item.STRUCTURE);
folder.fetch(messages, fetchProfile, null);
verify(imapConnection).sendCommand("UID FETCH 1 (UID BODYSTRUCTURE)", false);
}
Aggregations