Make Pop3Folder no longer extend Folder
This highlighted that a bunch of code in backend-pop3 was unused.
This commit is contained in:
parent
76bc52beef
commit
579027e66c
9 changed files with 115 additions and 384 deletions
|
@ -1,24 +0,0 @@
|
|||
package com.fsck.k9.backend.pop3
|
||||
|
||||
import com.fsck.k9.mail.Flag
|
||||
import com.fsck.k9.mail.Folder
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store
|
||||
|
||||
internal class CommandDeleteAll(private val pop3Store: Pop3Store) {
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun deleteAll(folderServerId: String) {
|
||||
val remoteFolder = pop3Store.getFolder(folderServerId)
|
||||
if (!remoteFolder.exists()) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW)
|
||||
remoteFolder.setFlags(setOf(Flag.DELETED), true)
|
||||
} finally {
|
||||
remoteFolder.close()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.fsck.k9.backend.pop3
|
||||
|
||||
import com.fsck.k9.mail.FetchProfile
|
||||
import com.fsck.k9.mail.Folder.OPEN_MODE_RW
|
||||
import com.fsck.k9.mail.Message
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store
|
||||
|
||||
|
@ -10,7 +9,7 @@ internal class CommandFetchMessage(private val pop3Store: Pop3Store) {
|
|||
fun fetchMessage(folderServerId: String, messageServerId: String, fetchProfile: FetchProfile): Message {
|
||||
val folder = pop3Store.getFolder(folderServerId)
|
||||
try {
|
||||
folder.open(OPEN_MODE_RW)
|
||||
folder.open()
|
||||
|
||||
val message = folder.getMessage(messageServerId)
|
||||
folder.fetch(listOf(message), fetchProfile, null)
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.List;
|
|||
|
||||
import com.fsck.k9.backend.api.BackendFolder;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Folder;
|
||||
|
@ -27,15 +26,12 @@ class CommandSetFlag {
|
|||
boolean newState) throws MessagingException {
|
||||
|
||||
Pop3Folder remoteFolder = pop3Store.getFolder(folderServerId);
|
||||
if (!remoteFolder.exists() || !remoteFolder.isFlagSupported(flag)) {
|
||||
if (!remoteFolder.isFlagSupported(flag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW);
|
||||
if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
|
||||
return;
|
||||
}
|
||||
remoteFolder.open();
|
||||
List<Message> messages = new ArrayList<>();
|
||||
for (String uid : messageServerIds) {
|
||||
if (!uid.startsWith(BackendFolder.LOCAL_UID_PREFIX)) {
|
||||
|
|
|
@ -23,7 +23,6 @@ class Pop3Backend(
|
|||
private val pop3Sync: Pop3Sync = Pop3Sync(accountName, backendStorage, pop3Store)
|
||||
private val commandRefreshFolderList = CommandRefreshFolderList(backendStorage)
|
||||
private val commandSetFlag = CommandSetFlag(pop3Store)
|
||||
private val commandDeleteAll = CommandDeleteAll(pop3Store)
|
||||
private val commandFetchMessage = CommandFetchMessage(pop3Store)
|
||||
|
||||
override val supportsSeenFlag = false
|
||||
|
@ -69,7 +68,7 @@ class Pop3Backend(
|
|||
}
|
||||
|
||||
override fun deleteAllMessages(folderServerId: String) {
|
||||
commandDeleteAll.deleteAll(folderServerId)
|
||||
throw UnsupportedOperationException("not supported")
|
||||
}
|
||||
|
||||
override fun moveMessages(
|
||||
|
|
|
@ -1,17 +1,6 @@
|
|||
package com.fsck.k9.backend.pop3;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.fsck.k9.backend.api.BackendFolder;
|
||||
import com.fsck.k9.backend.api.BackendFolder.MoreMessages;
|
||||
import com.fsck.k9.backend.api.BackendStorage;
|
||||
|
@ -19,17 +8,23 @@ import com.fsck.k9.backend.api.SyncConfig;
|
|||
import com.fsck.k9.backend.api.SyncListener;
|
||||
import com.fsck.k9.helper.ExceptionHelper;
|
||||
import com.fsck.k9.mail.AuthenticationFailedException;
|
||||
import com.fsck.k9.mail.BodyFactory;
|
||||
import com.fsck.k9.mail.DefaultBodyFactory;
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.Part;
|
||||
import com.fsck.k9.mail.internet.MessageExtractor;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Folder;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Message;
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
|
@ -50,7 +45,7 @@ class Pop3Sync {
|
|||
}
|
||||
|
||||
void synchronizeMailboxSynchronous(String folder, SyncConfig syncConfig, SyncListener listener) {
|
||||
Folder remoteFolder = null;
|
||||
Pop3Folder remoteFolder = null;
|
||||
|
||||
Timber.i("Synchronizing folder %s:%s", accountName, folder);
|
||||
|
||||
|
@ -97,7 +92,7 @@ class Pop3Sync {
|
|||
*/
|
||||
Timber.v("SYNC: About to open remote folder %s", folder);
|
||||
|
||||
remoteFolder.open(Folder.OPEN_MODE_RO);
|
||||
remoteFolder.open();
|
||||
|
||||
listener.syncAuthenticationSuccess();
|
||||
|
||||
|
@ -112,8 +107,8 @@ class Pop3Sync {
|
|||
visibleLimit = syncConfig.getDefaultVisibleLimit();
|
||||
}
|
||||
|
||||
final List<Message> remoteMessages = new ArrayList<>();
|
||||
Map<String, Message> remoteUidMap = new HashMap<>();
|
||||
final List<Pop3Message> remoteMessages = new ArrayList<>();
|
||||
Map<String, Pop3Message> remoteUidMap = new HashMap<>();
|
||||
|
||||
Timber.v("SYNC: Remote message count for folder %s is %d", folder, remoteMessageCount);
|
||||
|
||||
|
@ -137,12 +132,12 @@ class Pop3Sync {
|
|||
listener.syncHeadersStarted(folder, folderName);
|
||||
|
||||
|
||||
List<? extends Message> remoteMessageArray =
|
||||
remoteFolder.getMessages(remoteStart, remoteMessageCount, earliestDate, null);
|
||||
List<Pop3Message> remoteMessageArray =
|
||||
remoteFolder.getMessages(remoteStart, remoteMessageCount, null);
|
||||
|
||||
int messageCount = remoteMessageArray.size();
|
||||
|
||||
for (Message thisMess : remoteMessageArray) {
|
||||
for (Pop3Message thisMess : remoteMessageArray) {
|
||||
headerProgress.incrementAndGet();
|
||||
listener.syncHeadersProgress(folder, headerProgress.get(), messageCount);
|
||||
|
||||
|
@ -187,13 +182,13 @@ class Pop3Sync {
|
|||
localUidMap = null;
|
||||
|
||||
if (moreMessages == MoreMessages.UNKNOWN) {
|
||||
updateMoreMessages(remoteFolder, backendFolder, earliestDate, remoteStart);
|
||||
updateMoreMessages(remoteFolder, backendFolder, remoteStart);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now we download the actual content of messages.
|
||||
*/
|
||||
int newMessages = downloadMessages(syncConfig, remoteFolder, backendFolder, remoteMessages, false,
|
||||
int newMessages = downloadMessages(syncConfig, remoteFolder, backendFolder, remoteMessages,
|
||||
listener);
|
||||
|
||||
listener.folderStatusChanged(folder);
|
||||
|
@ -241,21 +236,21 @@ class Pop3Sync {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateMoreMessages(Folder remoteFolder, BackendFolder backendFolder, Date earliestDate,
|
||||
int remoteStart) throws MessagingException, IOException {
|
||||
private void updateMoreMessages(Pop3Folder remoteFolder, BackendFolder backendFolder,
|
||||
int remoteStart) {
|
||||
|
||||
if (remoteStart == 1) {
|
||||
backendFolder.setMoreMessages(MoreMessages.FALSE);
|
||||
} else {
|
||||
boolean moreMessagesAvailable = remoteFolder.areMoreMessagesAvailable(remoteStart, earliestDate);
|
||||
boolean moreMessagesAvailable = remoteFolder.areMoreMessagesAvailable(remoteStart);
|
||||
|
||||
MoreMessages newMoreMessages = (moreMessagesAvailable) ? MoreMessages.TRUE : MoreMessages.FALSE;
|
||||
backendFolder.setMoreMessages(newMoreMessages);
|
||||
}
|
||||
}
|
||||
|
||||
private int downloadMessages(final SyncConfig syncConfig, final Folder remoteFolder,
|
||||
final BackendFolder backendFolder, List<Message> inputMessages, boolean flagSyncOnly,
|
||||
private int downloadMessages(final SyncConfig syncConfig, final Pop3Folder remoteFolder,
|
||||
final BackendFolder backendFolder, List<Pop3Message> inputMessages,
|
||||
final SyncListener listener) throws MessagingException {
|
||||
|
||||
final Date earliestDate = syncConfig.getEarliestPollDate();
|
||||
|
@ -266,15 +261,14 @@ class Pop3Sync {
|
|||
}
|
||||
final String folder = remoteFolder.getServerId();
|
||||
|
||||
List<Message> syncFlagMessages = new ArrayList<>();
|
||||
List<Message> unsyncedMessages = new ArrayList<>();
|
||||
List<Pop3Message> syncFlagMessages = new ArrayList<>();
|
||||
List<Pop3Message> unsyncedMessages = new ArrayList<>();
|
||||
final AtomicInteger newMessages = new AtomicInteger(0);
|
||||
|
||||
List<Message> messages = new ArrayList<>(inputMessages);
|
||||
List<Pop3Message> messages = new ArrayList<>(inputMessages);
|
||||
|
||||
for (Message message : messages) {
|
||||
evaluateMessageForDownload(message, folder, backendFolder, remoteFolder, unsyncedMessages,
|
||||
syncFlagMessages, flagSyncOnly, listener);
|
||||
for (Pop3Message message : messages) {
|
||||
evaluateMessageForDownload(message, folder, backendFolder, unsyncedMessages, syncFlagMessages, listener);
|
||||
}
|
||||
|
||||
final AtomicInteger progress = new AtomicInteger(0);
|
||||
|
@ -284,8 +278,8 @@ class Pop3Sync {
|
|||
Timber.d("SYNC: Have %d unsynced messages", unsyncedMessages.size());
|
||||
|
||||
messages.clear();
|
||||
final List<Message> largeMessages = new ArrayList<>();
|
||||
final List<Message> smallMessages = new ArrayList<>();
|
||||
final List<Pop3Message> largeMessages = new ArrayList<>();
|
||||
final List<Pop3Message> smallMessages = new ArrayList<>();
|
||||
if (!unsyncedMessages.isEmpty()) {
|
||||
int visibleLimit = backendFolder.getVisibleLimit();
|
||||
int listSize = unsyncedMessages.size();
|
||||
|
@ -295,9 +289,6 @@ class Pop3Sync {
|
|||
}
|
||||
|
||||
FetchProfile fp = new FetchProfile();
|
||||
if (remoteFolder.supportsFetchingFlags()) {
|
||||
fp.add(FetchProfile.Item.FLAGS);
|
||||
}
|
||||
fp.add(FetchProfile.Item.ENVELOPE);
|
||||
|
||||
Timber.d("SYNC: About to fetch %d unsynced messages for folder %s", unsyncedMessages.size(), folder);
|
||||
|
@ -332,13 +323,6 @@ class Pop3Sync {
|
|||
downloadLargeMessages(syncConfig, remoteFolder, backendFolder, largeMessages, progress, newMessages, todo, fp, listener);
|
||||
largeMessages.clear();
|
||||
|
||||
/*
|
||||
* Refresh the flags for any messages in the local store that we didn't just
|
||||
* download.
|
||||
*/
|
||||
|
||||
refreshLocalMessageFlags(syncConfig, remoteFolder, backendFolder, syncFlagMessages, progress, todo, listener);
|
||||
|
||||
Timber.d("SYNC: Synced remote messages for folder %s, %d new messages", folder, newMessages.get());
|
||||
|
||||
// If the oldest message seen on this sync is newer than
|
||||
|
@ -360,13 +344,11 @@ class Pop3Sync {
|
|||
}
|
||||
|
||||
private void evaluateMessageForDownload(
|
||||
final Message message,
|
||||
final Pop3Message message,
|
||||
final String folder,
|
||||
final BackendFolder backendFolder,
|
||||
final Folder remoteFolder,
|
||||
final List<Message> unsyncedMessages,
|
||||
final List<Message> syncFlagMessages,
|
||||
boolean flagSyncOnly,
|
||||
final List<Pop3Message> unsyncedMessages,
|
||||
final List<Pop3Message> syncFlagMessages,
|
||||
SyncListener listener) {
|
||||
|
||||
String messageServerId = message.getUid();
|
||||
|
@ -380,25 +362,23 @@ class Pop3Sync {
|
|||
boolean messagePresentLocally = backendFolder.isMessagePresent(messageServerId);
|
||||
|
||||
if (!messagePresentLocally) {
|
||||
if (!flagSyncOnly) {
|
||||
if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
|
||||
Timber.v("Message with uid %s has not yet been downloaded", messageServerId);
|
||||
if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
|
||||
Timber.v("Message with uid %s has not yet been downloaded", messageServerId);
|
||||
|
||||
unsyncedMessages.add(message);
|
||||
unsyncedMessages.add(message);
|
||||
} else {
|
||||
Timber.v("Message with uid %s is partially or fully downloaded", messageServerId);
|
||||
|
||||
// Store the updated message locally
|
||||
boolean completeMessage = message.isSet(Flag.X_DOWNLOADED_FULL);
|
||||
if (completeMessage) {
|
||||
backendFolder.saveCompleteMessage(message);
|
||||
} else {
|
||||
Timber.v("Message with uid %s is partially or fully downloaded", messageServerId);
|
||||
|
||||
// Store the updated message locally
|
||||
boolean completeMessage = message.isSet(Flag.X_DOWNLOADED_FULL);
|
||||
if (completeMessage) {
|
||||
backendFolder.saveCompleteMessage(message);
|
||||
} else {
|
||||
backendFolder.savePartialMessage(message);
|
||||
}
|
||||
|
||||
boolean isOldMessage = isOldMessage(backendFolder, message);
|
||||
listener.syncNewMessage(folder, messageServerId, isOldMessage);
|
||||
backendFolder.savePartialMessage(message);
|
||||
}
|
||||
|
||||
boolean isOldMessage = isOldMessage(backendFolder, message);
|
||||
listener.syncNewMessage(folder, messageServerId, isOldMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -412,10 +392,6 @@ class Pop3Sync {
|
|||
|
||||
unsyncedMessages.add(message);
|
||||
} else {
|
||||
String newPushState = remoteFolder.getNewPushState(backendFolder.getPushState(), message);
|
||||
if (newPushState != null) {
|
||||
backendFolder.setPushState(newPushState);
|
||||
}
|
||||
syncFlagMessages.add(message);
|
||||
}
|
||||
} else {
|
||||
|
@ -423,10 +399,10 @@ class Pop3Sync {
|
|||
}
|
||||
}
|
||||
|
||||
private <T extends Message> void fetchUnsyncedMessages(final SyncConfig syncConfig, final Folder<T> remoteFolder,
|
||||
List<T> unsyncedMessages,
|
||||
final List<Message> smallMessages,
|
||||
final List<Message> largeMessages,
|
||||
private void fetchUnsyncedMessages(final SyncConfig syncConfig, final Pop3Folder remoteFolder,
|
||||
List<Pop3Message> unsyncedMessages,
|
||||
final List<Pop3Message> smallMessages,
|
||||
final List<Pop3Message> largeMessages,
|
||||
final AtomicInteger progress,
|
||||
final int todo,
|
||||
FetchProfile fp,
|
||||
|
@ -435,9 +411,9 @@ class Pop3Sync {
|
|||
|
||||
final Date earliestDate = syncConfig.getEarliestPollDate();
|
||||
remoteFolder.fetch(unsyncedMessages, fp,
|
||||
new MessageRetrievalListener<T>() {
|
||||
new MessageRetrievalListener<Pop3Message>() {
|
||||
@Override
|
||||
public void messageFinished(T message, int number, int ofTotal) {
|
||||
public void messageFinished(Pop3Message message, int number, int ofTotal) {
|
||||
try {
|
||||
if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
|
||||
if (message.isSet(Flag.DELETED)) {
|
||||
|
@ -478,10 +454,10 @@ class Pop3Sync {
|
|||
});
|
||||
}
|
||||
|
||||
private <T extends Message> void downloadSmallMessages(
|
||||
final Folder<T> remoteFolder,
|
||||
private void downloadSmallMessages(
|
||||
final Pop3Folder remoteFolder,
|
||||
final BackendFolder backendFolder,
|
||||
List<T> smallMessages,
|
||||
List<Pop3Message> smallMessages,
|
||||
final AtomicInteger progress,
|
||||
final AtomicInteger newMessages,
|
||||
final int todo,
|
||||
|
@ -492,9 +468,9 @@ class Pop3Sync {
|
|||
Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
|
||||
|
||||
remoteFolder.fetch(smallMessages,
|
||||
fp, new MessageRetrievalListener<T>() {
|
||||
fp, new MessageRetrievalListener<Pop3Message>() {
|
||||
@Override
|
||||
public void messageFinished(final T message, int number, int ofTotal) {
|
||||
public void messageFinished(final Pop3Message message, int number, int ofTotal) {
|
||||
try {
|
||||
|
||||
// Store the updated message locally
|
||||
|
@ -533,15 +509,15 @@ class Pop3Sync {
|
|||
Timber.d("SYNC: Done fetching small messages for folder %s", folder);
|
||||
}
|
||||
|
||||
private boolean isOldMessage(BackendFolder backendFolder, Message message) {
|
||||
private boolean isOldMessage(BackendFolder backendFolder, Pop3Message message) {
|
||||
return message.olderThan(backendFolder.getLatestOldMessageSeenTime());
|
||||
}
|
||||
|
||||
private <T extends Message> void downloadLargeMessages(
|
||||
private void downloadLargeMessages(
|
||||
final SyncConfig syncConfig,
|
||||
final Folder<T> remoteFolder,
|
||||
final Pop3Folder remoteFolder,
|
||||
final BackendFolder backendFolder,
|
||||
List<T> largeMessages,
|
||||
List<Pop3Message> largeMessages,
|
||||
final AtomicInteger progress,
|
||||
final AtomicInteger newMessages,
|
||||
final int todo,
|
||||
|
@ -552,13 +528,9 @@ class Pop3Sync {
|
|||
Timber.d("SYNC: Fetching large messages for folder %s", folder);
|
||||
|
||||
remoteFolder.fetch(largeMessages, fp, null);
|
||||
for (T message : largeMessages) {
|
||||
for (Pop3Message message : largeMessages) {
|
||||
|
||||
if (message.getBody() == null) {
|
||||
downloadSaneBody(syncConfig, remoteFolder, backendFolder, message);
|
||||
} else {
|
||||
downloadPartial(remoteFolder, backendFolder, message);
|
||||
}
|
||||
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",
|
||||
|
@ -584,8 +556,8 @@ class Pop3Sync {
|
|||
Timber.d("SYNC: Done fetching large messages for folder %s", folder);
|
||||
}
|
||||
|
||||
private void downloadSaneBody(SyncConfig syncConfig, Folder remoteFolder, BackendFolder backendFolder,
|
||||
Message message) throws MessagingException {
|
||||
private void downloadSaneBody(SyncConfig syncConfig, Pop3Folder remoteFolder, BackendFolder backendFolder,
|
||||
Pop3Message message) throws MessagingException {
|
||||
/*
|
||||
* The provider was unable to get the structure of the message, so
|
||||
* we'll download a reasonable portion of the messge and mark it as
|
||||
|
@ -627,92 +599,4 @@ class Pop3Sync {
|
|||
backendFolder.savePartialMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadPartial(Folder remoteFolder, BackendFolder backendFolder, Message message)
|
||||
throws MessagingException {
|
||||
/*
|
||||
* We have a structure to deal with, from which
|
||||
* we can pull down the parts we want to actually store.
|
||||
* Build a list of parts we are interested in. Text parts will be downloaded
|
||||
* right now, attachments will be left for later.
|
||||
*/
|
||||
|
||||
Set<Part> viewables = MessageExtractor.collectTextParts(message);
|
||||
|
||||
/*
|
||||
* Now download the parts we're interested in storing.
|
||||
*/
|
||||
BodyFactory bodyFactory = new DefaultBodyFactory();
|
||||
for (Part part : viewables) {
|
||||
remoteFolder.fetchPart(message, part, null, bodyFactory);
|
||||
}
|
||||
|
||||
// Store the updated message locally
|
||||
backendFolder.savePartialMessage(message);
|
||||
}
|
||||
|
||||
private void refreshLocalMessageFlags(
|
||||
final SyncConfig syncConfig,
|
||||
final Folder remoteFolder,
|
||||
final BackendFolder backendFolder,
|
||||
List<Message> syncFlagMessages,
|
||||
final AtomicInteger progress,
|
||||
final int todo,
|
||||
SyncListener listener
|
||||
) throws MessagingException {
|
||||
|
||||
final String folder = remoteFolder.getServerId();
|
||||
if (remoteFolder.supportsFetchingFlags()) {
|
||||
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<Message> undeletedMessages = new LinkedList<>();
|
||||
for (Message message : syncFlagMessages) {
|
||||
if (!message.isSet(Flag.DELETED)) {
|
||||
undeletedMessages.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
remoteFolder.fetch(undeletedMessages, fp, null);
|
||||
for (Message remoteMessage : syncFlagMessages) {
|
||||
boolean messageChanged = syncFlags(syncConfig, backendFolder, remoteMessage);
|
||||
if (messageChanged) {
|
||||
listener.syncFlagChanged(folder, remoteMessage.getUid());
|
||||
}
|
||||
progress.incrementAndGet();
|
||||
listener.syncProgress(folder, progress.get(), todo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean syncFlags(SyncConfig syncConfig, BackendFolder backendFolder, Message remoteMessage) {
|
||||
String messageServerId = remoteMessage.getUid();
|
||||
|
||||
if (!backendFolder.isMessagePresent(messageServerId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Flag> localMessageFlags = backendFolder.getMessageFlags(messageServerId);
|
||||
if (localMessageFlags.contains(Flag.DELETED)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean messageChanged = false;
|
||||
if (remoteMessage.isSet(Flag.DELETED)) {
|
||||
if (syncConfig.getSyncRemoteDeletions()) {
|
||||
backendFolder.setMessageFlag(messageServerId, Flag.DELETED, true);
|
||||
messageChanged = true;
|
||||
}
|
||||
} else {
|
||||
for (Flag flag : syncConfig.getSyncFlags()) {
|
||||
if (remoteMessage.isSet(flag) != localMessageFlags.contains(flag)) {
|
||||
backendFolder.setMessageFlag(messageServerId, flag, remoteMessage.isSet(flag));
|
||||
messageChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageChanged;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.fsck.k9.mail.store.pop3;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -15,7 +14,6 @@ import android.annotation.SuppressLint;
|
|||
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.K9MailLib;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
|
@ -29,7 +27,7 @@ import static com.fsck.k9.mail.store.pop3.Pop3Commands.*;
|
|||
/**
|
||||
* POP3 only supports one folder, "Inbox". So the folder name is the ID here.
|
||||
*/
|
||||
public class Pop3Folder extends Folder<Pop3Message> {
|
||||
public class Pop3Folder {
|
||||
public static final String INBOX = "INBOX";
|
||||
|
||||
|
||||
|
@ -48,8 +46,7 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void open(int mode) throws MessagingException {
|
||||
public synchronized void open() throws MessagingException {
|
||||
if (isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,17 +67,10 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
uidToMsgNumMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return connection != null && connection.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMode() {
|
||||
return Folder.OPEN_MODE_RW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
if (isOpen()) {
|
||||
|
@ -99,42 +89,19 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerId() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean create() throws MessagingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() throws MessagingException {
|
||||
return INBOX.equals(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMessageCount() {
|
||||
return messageCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnreadMessageCount() throws MessagingException {
|
||||
return -1;
|
||||
}
|
||||
@Override
|
||||
public int getFlaggedMessageCount() throws MessagingException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pop3Message getMessage(String uid) throws MessagingException {
|
||||
public Pop3Message getMessage(String uid) {
|
||||
Pop3Message message = uidToMsgMap.get(uid);
|
||||
if (message == null) {
|
||||
message = new Pop3Message(uid);
|
||||
|
@ -142,8 +109,7 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pop3Message> getMessages(int start, int end, Date earliestDate, MessageRetrievalListener<Pop3Message> listener)
|
||||
public List<Pop3Message> getMessages(int start, int end, MessageRetrievalListener<Pop3Message> listener)
|
||||
throws MessagingException {
|
||||
if (start < 1 || end < 1 || end < start) {
|
||||
throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d",
|
||||
|
@ -179,8 +145,7 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate) {
|
||||
public boolean areMoreMessagesAvailable(int indexOfOldestMessage) {
|
||||
return indexOfOldestMessage > 1;
|
||||
}
|
||||
|
||||
|
@ -325,7 +290,6 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
* @param messages Messages to populate
|
||||
* @param fp The contents to populate
|
||||
*/
|
||||
@Override
|
||||
public void fetch(List<Pop3Message> messages, FetchProfile fp,
|
||||
MessageRetrievalListener<Pop3Message> listener)
|
||||
throws MessagingException {
|
||||
|
@ -517,22 +481,6 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUidFromMessageId(String messageId) throws MessagingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(final Set<Flag> flags, boolean value) throws MessagingException {
|
||||
throw new UnsupportedOperationException("POP3: No setFlags(Set<Flag>,boolean)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value)
|
||||
throws MessagingException {
|
||||
if (!value || !flags.contains(Flag.DELETED)) {
|
||||
|
@ -560,21 +508,15 @@ public class Pop3Folder extends Folder<Pop3Message> {
|
|||
true
|
||||
);
|
||||
}
|
||||
open(Folder.OPEN_MODE_RW);
|
||||
open();
|
||||
connection.executeSimpleCommand(String.format(DELE_COMMAND + " %s", msgNum));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlagSupported(Flag flag) {
|
||||
return (flag == Flag.DELETED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFetchingFlags() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Pop3Folder) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||
|
@ -53,7 +52,7 @@ public class Pop3Store {
|
|||
public void checkSettings() throws MessagingException {
|
||||
Pop3Folder folder = new Pop3Folder(this, Pop3Folder.INBOX);
|
||||
try {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
folder.requestUidl();
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
package com.fsck.k9.mail.store.pop3;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.FetchProfile.Item;
|
||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.internet.BinaryTempFileBody;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -8,27 +18,14 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.FetchProfile.Item;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessageRetrievalListener;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.internet.BinaryTempFileBody;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
@ -53,68 +50,18 @@ public class Pop3FolderTest {
|
|||
BinaryTempFileBody.setTempDirectory(new File(System.getProperty("java.io.tmpdir")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_withHoldsFoldersArgument_shouldDoNothing() throws Exception {
|
||||
Pop3Folder folder = new Pop3Folder(mockStore, "TestFolder");
|
||||
|
||||
boolean result = folder.create();
|
||||
|
||||
assertFalse(result);
|
||||
verifyZeroInteractions(mockConnection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_withHoldsMessagesArgument_shouldDoNothing() throws Exception {
|
||||
Pop3Folder folder = new Pop3Folder(mockStore, "TestFolder");
|
||||
|
||||
boolean result = folder.create();
|
||||
|
||||
assertFalse(result);
|
||||
verifyZeroInteractions(mockConnection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exists_withInbox_shouldReturnTrue() throws Exception {
|
||||
boolean result = folder.exists();
|
||||
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exists_withNonInboxFolder_shouldReturnFalse() throws Exception {
|
||||
folder = new Pop3Folder(mockStore, "TestFolder");
|
||||
|
||||
boolean result = folder.exists();
|
||||
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnreadMessageCount_shouldBeMinusOne() throws Exception {
|
||||
int result = folder.getUnreadMessageCount();
|
||||
|
||||
assertEquals(-1, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFlaggedMessageCount_shouldBeMinusOne() throws Exception {
|
||||
int result = folder.getFlaggedMessageCount();
|
||||
|
||||
assertEquals(-1, result);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void open_withoutInboxFolder_shouldThrow() throws Exception {
|
||||
Pop3Folder folder = new Pop3Folder(mockStore, "TestFolder");
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void open_withoutInboxFolder_shouldNotTryAndCreateConnection() throws Exception {
|
||||
Pop3Folder folder = new Pop3Folder(mockStore, "TestFolder");
|
||||
try {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
} catch (Exception ignored) {}
|
||||
verify(mockStore, never()).createConnection();
|
||||
}
|
||||
|
@ -124,13 +71,13 @@ public class Pop3FolderTest {
|
|||
throws MessagingException {
|
||||
|
||||
when(mockStore.createConnection()).thenThrow(new MessagingException("Test"));
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void open_withInboxFolder_shouldSetMessageCountFromStatResponse()
|
||||
throws MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
int messageCount = folder.getMessageCount();
|
||||
|
||||
|
@ -143,13 +90,13 @@ public class Pop3FolderTest {
|
|||
when(mockConnection.executeSimpleCommand(Pop3Commands.STAT_COMMAND))
|
||||
.thenThrow(new MessagingException("Test"));
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void open_createsAndOpensConnection()
|
||||
throws MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
verify(mockStore, times(1)).createConnection();
|
||||
verify(mockConnection).open();
|
||||
|
@ -158,24 +105,14 @@ public class Pop3FolderTest {
|
|||
@Test
|
||||
public void open_whenAlreadyOpenWithValidConnection_doesNotCreateAnotherConnection()
|
||||
throws MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
when(mockConnection.isOpen()).thenReturn(true);
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
verify(mockStore, times(1)).createConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMode_withFolderOpenedInRO_isRW() throws MessagingException {
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RO);
|
||||
|
||||
int mode = folder.getMode();
|
||||
|
||||
assertEquals(Folder.OPEN_MODE_RW, mode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void close_onNonOpenedFolder_succeeds()
|
||||
throws MessagingException {
|
||||
|
@ -188,7 +125,7 @@ public class Pop3FolderTest {
|
|||
public void close_onOpenedFolder_succeeds()
|
||||
throws MessagingException {
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
folder.close();
|
||||
}
|
||||
|
@ -197,7 +134,7 @@ public class Pop3FolderTest {
|
|||
public void close_onOpenedFolder_sendsQUIT()
|
||||
throws MessagingException {
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
when(mockConnection.isOpen()).thenReturn(true);
|
||||
|
||||
folder.close();
|
||||
|
@ -209,7 +146,7 @@ public class Pop3FolderTest {
|
|||
public void close_withExceptionQuiting_ignoresException()
|
||||
throws MessagingException {
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
when(mockConnection.isOpen()).thenReturn(true);
|
||||
doThrow(new MessagingException("Test"))
|
||||
.when(mockConnection)
|
||||
|
@ -222,7 +159,7 @@ public class Pop3FolderTest {
|
|||
public void close_onOpenedFolder_closesConnection()
|
||||
throws MessagingException {
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
when(mockConnection.isOpen()).thenReturn(true);
|
||||
|
||||
folder.close();
|
||||
|
@ -232,35 +169,35 @@ public class Pop3FolderTest {
|
|||
|
||||
@Test
|
||||
public void getMessages_returnsListOfMessagesOnServer() throws IOException, MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
when(mockConnection.readLine()).thenReturn("1 abcd").thenReturn(".");
|
||||
|
||||
List<Pop3Message> result = folder.getMessages(1, 1, null, mockListener);
|
||||
List<Pop3Message> result = folder.getMessages(1, 1, mockListener);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void getMessages_withInvalidSet_throwsException() throws IOException, MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
folder.getMessages(2, 1, null, mockListener);
|
||||
folder.getMessages(2, 1, mockListener);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void getMessages_withIOExceptionReadingLine_throwsException() throws IOException, MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
when(mockConnection.readLine()).thenThrow(new IOException("Test"));
|
||||
|
||||
folder.getMessages(1, 1, null, mockListener);
|
||||
folder.getMessages(1, 1, mockListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessage_withPreviouslyFetchedMessage_returnsMessage()
|
||||
throws IOException, MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
List<Pop3Message> messageList = setupMessageFromServer();
|
||||
|
||||
|
@ -272,7 +209,7 @@ public class Pop3FolderTest {
|
|||
@Test
|
||||
public void getMessage_withNoPreviouslyFetchedMessage_returnsNewMessage()
|
||||
throws IOException, MessagingException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
Pop3Message message = folder.getMessage("abcd");
|
||||
|
||||
|
@ -282,7 +219,7 @@ public class Pop3FolderTest {
|
|||
|
||||
@Test
|
||||
public void fetch_withEnvelopeProfile_setsSizeOfMessage() throws MessagingException, IOException {
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
List<Pop3Message> messageList = setupMessageFromServer();
|
||||
FetchProfile fetchProfile = new FetchProfile();
|
||||
fetchProfile.add(Item.ENVELOPE);
|
||||
|
@ -304,7 +241,7 @@ public class Pop3FolderTest {
|
|||
"Content-Transfer-Encoding: 7bit\r\n" +
|
||||
"\r\n" +
|
||||
"this is some test text.").getBytes());
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
List<Pop3Message> messageList = setupMessageFromServer();
|
||||
FetchProfile fetchProfile = new FetchProfile();
|
||||
fetchProfile.add(Item.BODY);
|
||||
|
@ -321,6 +258,6 @@ public class Pop3FolderTest {
|
|||
|
||||
private List<Pop3Message> setupMessageFromServer() throws IOException, MessagingException {
|
||||
when(mockConnection.readLine()).thenReturn("1 abcd").thenReturn(".");
|
||||
return folder.getMessages(1, 1, null, mockListener);
|
||||
return folder.getMessages(1, 1, mockListener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.net.Socket;
|
|||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.AuthenticationFailedException;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
|
@ -138,7 +137,7 @@ public class Pop3StoreTest {
|
|||
when(mockSocket.getOutputStream()).thenReturn(byteArrayOutputStream);
|
||||
Pop3Folder folder = store.getFolder(Pop3Folder.INBOX);
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
|
||||
assertEquals(20, folder.getMessageCount());
|
||||
assertEquals(AUTH + CAPA + AUTH_PLAIN_WITH_LOGIN + STAT, byteArrayOutputStream.toString("UTF-8"));
|
||||
|
@ -153,7 +152,7 @@ public class Pop3StoreTest {
|
|||
when(mockSocket.getInputStream()).thenReturn(new ByteArrayInputStream(response.getBytes("UTF-8")));
|
||||
Pop3Folder folder = store.getFolder(Pop3Folder.INBOX);
|
||||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
folder.open();
|
||||
}
|
||||
|
||||
private ServerSettings createServerSettings() {
|
||||
|
|
Loading…
Reference in a new issue