Remove age checks when downloading messages

We already filter by age when deciding which messages to download.
This commit is contained in:
cketti 2019-12-17 02:59:14 +01:00
parent 615cad7414
commit b8b6b0497d

View file

@ -297,11 +297,6 @@ class ImapSync {
List<Message> inputMessages, boolean flagSyncOnly, Long lastUid, List<Message> inputMessages, boolean flagSyncOnly, Long lastUid,
final SyncListener listener) throws MessagingException { final SyncListener listener) throws MessagingException {
final Date earliestDate = syncConfig.getEarliestPollDate();
if (earliestDate != null) {
Timber.d("Only syncing messages after %s", earliestDate);
}
final String folder = remoteFolder.getServerId(); final String folder = remoteFolder.getServerId();
List<Message> syncFlagMessages = new ArrayList<>(); List<Message> syncFlagMessages = new ArrayList<>();
@ -368,7 +363,7 @@ class ImapSync {
fp.add(FetchProfile.Item.BODY); fp.add(FetchProfile.Item.BODY);
// fp.add(FetchProfile.Item.FLAGS); // fp.add(FetchProfile.Item.FLAGS);
// fp.add(FetchProfile.Item.ENVELOPE); // fp.add(FetchProfile.Item.ENVELOPE);
downloadSmallMessages(syncConfig, remoteFolder, backendFolder, smallMessages, progress, newMessages, todo, fp, downloadSmallMessages(remoteFolder, backendFolder, smallMessages, progress, newMessages, todo, fp,
lastUid, listener); lastUid, listener);
smallMessages.clear(); smallMessages.clear();
/* /*
@ -376,7 +371,7 @@ class ImapSync {
*/ */
fp = new FetchProfile(); fp = new FetchProfile();
fp.add(FetchProfile.Item.STRUCTURE); fp.add(FetchProfile.Item.STRUCTURE);
downloadLargeMessages(syncConfig, remoteFolder, backendFolder, largeMessages, progress, newMessages, todo, fp, downloadLargeMessages(remoteFolder, backendFolder, largeMessages, progress, newMessages, todo, fp,
lastUid, listener); lastUid, listener);
largeMessages.clear(); largeMessages.clear();
@ -460,20 +455,14 @@ class ImapSync {
final SyncListener listener) throws MessagingException { final SyncListener listener) throws MessagingException {
final String folder = remoteFolder.getServerId(); final String folder = remoteFolder.getServerId();
final Date earliestDate = syncConfig.getEarliestPollDate();
remoteFolder.fetch(unsyncedMessages, fp, remoteFolder.fetch(unsyncedMessages, fp,
new MessageRetrievalListener<T>() { new MessageRetrievalListener<T>() {
@Override @Override
public void messageFinished(T message, int number, int ofTotal) { public void messageFinished(T message, int number, int ofTotal) {
try { try {
if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) { if (message.isSet(Flag.DELETED)) {
if (message.isSet(Flag.DELETED)) { Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, skipping",
Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, " + accountName, folder, message.getUid());
"skipping", accountName, folder, message.getUid());
} else {
Timber.d("Newly downloaded message %s is older than %s, skipping",
message.getUid(), earliestDate);
}
progress.incrementAndGet(); progress.incrementAndGet();
@ -507,7 +496,6 @@ class ImapSync {
} }
private <T extends Message> void downloadSmallMessages( private <T extends Message> void downloadSmallMessages(
SyncConfig syncConfig,
final Folder<T> remoteFolder, final Folder<T> remoteFolder,
final BackendFolder backendFolder, final BackendFolder backendFolder,
List<T> smallMessages, List<T> smallMessages,
@ -519,8 +507,6 @@ class ImapSync {
final SyncListener listener) throws MessagingException { final SyncListener listener) throws MessagingException {
final String folder = remoteFolder.getServerId(); final String folder = remoteFolder.getServerId();
final Date earliestDate = syncConfig.getEarliestPollDate();
Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder); Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
remoteFolder.fetch(smallMessages, remoteFolder.fetch(smallMessages,
@ -528,12 +514,6 @@ class ImapSync {
@Override @Override
public void messageFinished(final T message, int number, int ofTotal) { public void messageFinished(final T message, int number, int ofTotal) {
try { try {
if (!shouldImportMessage(message, earliestDate)) {
progress.incrementAndGet();
return;
}
// Store the updated message locally // Store the updated message locally
backendFolder.saveCompleteMessage(message); backendFolder.saveCompleteMessage(message);
progress.incrementAndGet(); progress.incrementAndGet();
@ -572,7 +552,6 @@ class ImapSync {
} }
private <T extends Message> void downloadLargeMessages( private <T extends Message> void downloadLargeMessages(
SyncConfig syncConfig,
final Folder<T> remoteFolder, final Folder<T> remoteFolder,
final BackendFolder backendFolder, final BackendFolder backendFolder,
List<T> largeMessages, List<T> largeMessages,
@ -583,18 +562,11 @@ class ImapSync {
Long lastUid, Long lastUid,
SyncListener listener) throws MessagingException { SyncListener listener) throws MessagingException {
final String folder = remoteFolder.getServerId(); final String folder = remoteFolder.getServerId();
final Date earliestDate = syncConfig.getEarliestPollDate();
Timber.d("SYNC: Fetching large messages for folder %s", folder); Timber.d("SYNC: Fetching large messages for folder %s", folder);
remoteFolder.fetch(largeMessages, fp, null); remoteFolder.fetch(largeMessages, fp, null);
for (T message : largeMessages) { for (T message : largeMessages) {
if (!shouldImportMessage(message, earliestDate)) {
progress.incrementAndGet();
continue;
}
if (message.getBody() == null) { if (message.getBody() == null) {
downloadSaneBody(remoteFolder, backendFolder, message); downloadSaneBody(remoteFolder, backendFolder, message);
} else { } else {
@ -732,14 +704,6 @@ class ImapSync {
return messageChanged; return messageChanged;
} }
private boolean shouldImportMessage(Message message, Date earliestDate) {
if (message.olderThan(earliestDate)) {
Timber.d("Message %s is older than %s, hence not saving", message.getUid(), earliestDate);
return false;
}
return true;
}
private static void closeFolder(Folder folder) { private static void closeFolder(Folder folder) {
if (folder != null) { if (folder != null) {
folder.close(); folder.close();