Tidy-up MessagingController - checkstyle fixes

This commit is contained in:
Philip Whitehouse 2017-02-14 00:28:29 +00:00
parent 2e01043a28
commit b97cbba320

View file

@ -148,7 +148,7 @@ public class MessagingController {
private volatile boolean stopped = false;
public synchronized static MessagingController getInstance(Context context) {
public static synchronized MessagingController getInstance(Context context) {
if (inst == null) {
Context appContext = context.getApplicationContext();
NotificationController notificationController = NotificationController.newInstance(appContext);
@ -242,7 +242,8 @@ public class MessagingController {
putCommand(queuedCommands, description, listener, runnable, false);
}
private void putCommand(BlockingQueue<Command> queue, String description, MessagingListener listener, Runnable runnable, boolean isForeground) {
private void putCommand(BlockingQueue<Command> queue, String description, MessagingListener listener,
Runnable runnable, boolean isForeground) {
int retries = 10;
Exception e = null;
while (retries-- > 0) {
@ -754,8 +755,9 @@ public class MessagingController {
Folder remoteFolder = null;
LocalFolder tLocalFolder = null;
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Synchronizing folder " + account.getDescription() + ":" + folder);
}
for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxStarted(account, folder);
@ -773,8 +775,9 @@ public class MessagingController {
Exception commandException = null;
try {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: About to process pending commands for account " + account.getDescription());
}
try {
processPendingCommandsSynchronous(account);
@ -789,8 +792,9 @@ public class MessagingController {
* Get the message list from the local store and create an index of
* the uids within the list.
*/
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: About to get local folder " + folder);
}
final LocalStore localStore = account.getLocalStore();
tLocalFolder = localStore.getFolder(folder);
@ -800,14 +804,16 @@ public class MessagingController {
Map<String, Long> localUidMap = localFolder.getAllMessagesAndEffectiveDates();
if (providedRemoteFolder != null) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: using providedRemoteFolder " + folder);
}
remoteFolder = providedRemoteFolder;
} else {
Store remoteStore = account.getRemoteStore();
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: About to get remote folder " + folder);
}
remoteFolder = remoteStore.getFolder(folder);
if (!verifyOrCreateRemoteSpecialFolder(account, folder, remoteFolder, listener)) {
@ -836,13 +842,15 @@ public class MessagingController {
/*
* Open the remote folder. This pre-loads certain metadata like message count.
*/
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: About to open remote folder " + folder);
}
remoteFolder.open(Folder.OPEN_MODE_RW);
if (Expunge.EXPUNGE_ON_POLL == account.getExpungePolicy()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Expunging folder " + account.getDescription() + ":" + folder);
}
remoteFolder.expunge();
}
@ -864,8 +872,9 @@ public class MessagingController {
final List<Message> remoteMessages = new ArrayList<>();
Map<String, Message> remoteUidMap = new HashMap<>();
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: Remote message count for folder " + folder + " is " + remoteMessageCount);
}
final Date earliestDate = account.getEarliestPollDate();
long earliestTimestamp = earliestDate != null ? earliestDate.getTime() : 0L;
@ -879,8 +888,10 @@ public class MessagingController {
remoteStart = 1;
}
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: About to get messages " + remoteStart + " through " + remoteMessageCount + " for folder " + folder);
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: About to get messages " + remoteStart + " through " + remoteMessageCount
+ " for folder " + folder);
}
final AtomicInteger headerProgress = new AtomicInteger(0);
for (MessagingListener l : getListeners(listener)) {
@ -903,8 +914,9 @@ public class MessagingController {
remoteUidMap.put(thisMess.getUid(), thisMess);
}
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "SYNC: Got " + remoteUidMap.size() + " messages for folder " + folder);
}
for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxHeadersFinished(account, folder, headerProgress.get(), remoteUidMap.size());
@ -961,9 +973,10 @@ public class MessagingController {
localFolder.setLastChecked(System.currentTimeMillis());
localFolder.setStatus(null);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Done synchronizing folder " + account.getDescription() + ":" + folder +
" @ " + new Date() + " with " + newMessages + " new messages");
}
for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFinished(account, folder, remoteMessageCount, newMessages);
@ -980,8 +993,9 @@ public class MessagingController {
}
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Done synchronizing folder " + account.getDescription() + ":" + folder);
}
} catch (AuthenticationFailedException e) {
handleAuthenticationFailure(account, true);
@ -1061,8 +1075,9 @@ public class MessagingController {
for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFinished(account, folder, 0, 0);
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Done synchronizing folder " + folder);
}
return false;
}
@ -1122,7 +1137,8 @@ public class MessagingController {
List<Message> messages = new ArrayList<>(inputMessages);
for (Message message : messages) {
evaluateMessageForDownload(message, folder, localFolder, remoteFolder, account, unsyncedMessages, syncFlagMessages , flagSyncOnly);
evaluateMessageForDownload(message, folder, localFolder, remoteFolder, account, unsyncedMessages,
syncFlagMessages, flagSyncOnly);
}
final AtomicInteger progress = new AtomicInteger(0);
@ -1131,8 +1147,9 @@ public class MessagingController {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Have " + unsyncedMessages.size() + " unsynced messages");
}
messages.clear();
final List<Message> largeMessages = new ArrayList<>();
@ -1157,8 +1174,9 @@ public class MessagingController {
}
fp.add(FetchProfile.Item.ENVELOPE);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: About to fetch " + unsyncedMessages.size() + " unsynced messages for folder " + folder);
}
fetchUnsyncedMessages(account, remoteFolder, unsyncedMessages, smallMessages, largeMessages, progress, todo, fp);
@ -1175,11 +1193,12 @@ public class MessagingController {
Log.d(K9.LOG_TAG, "SYNC: Synced unsynced messages for folder " + folder);
}
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Have "
+ largeMessages.size() + " large messages and "
+ smallMessages.size() + " small messages out of "
+ unsyncedMessages.size() + " unsynced messages");
}
unsyncedMessages.clear();
/*
@ -1209,8 +1228,9 @@ public class MessagingController {
refreshLocalMessageFlags(account, remoteFolder, localFolder, syncFlagMessages, progress, todo);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Synced remote messages for folder " + folder + ", " + newMessages.get() + " new messages");
}
if (purgeToVisibleLimit) {
localFolder.purgeToVisibleLimit(new MessageRemovalListener() {
@ -1252,8 +1272,9 @@ public class MessagingController {
final List<Message> syncFlagMessages,
boolean flagSyncOnly) throws MessagingException {
if (message.isSet(Flag.DELETED)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is marked as deleted");
}
syncFlagMessages.add(message);
return;
}
@ -1263,13 +1284,15 @@ public class MessagingController {
if (localMessage == null) {
if (!flagSyncOnly) {
if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " has not yet been downloaded");
}
unsyncedMessages.add(message);
} else {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is partially or fully downloaded");
}
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
@ -1288,13 +1311,15 @@ public class MessagingController {
}
}
} else if (!localMessage.isSet(Flag.DELETED)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is present in the local store");
}
if (!localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid()
+ " is not downloaded, even partially; trying again");
}
unsyncedMessages.add(message);
} else {
@ -1305,10 +1330,11 @@ public class MessagingController {
syncFlagMessages.add(message);
}
} else {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Local copy of message with uid " + message.getUid() + " is marked as deleted");
}
}
}
private <T extends Message> void fetchUnsyncedMessages(final Account account, final Folder<T> remoteFolder,
List<T> unsyncedMessages,
@ -1391,8 +1417,9 @@ public class MessagingController {
final Date earliestDate = account.getEarliestPollDate();
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Fetching " + smallMessages.size() + " small messages for folder " + folder);
}
remoteFolder.fetch(smallMessages,
fp, new MessageRetrievalListener<T>() {
@ -1420,9 +1447,10 @@ public class MessagingController {
newMessages.incrementAndGet();
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "About to notify listeners that we got a new small message "
+ account + ":" + folder + ":" + message.getUid());
}
// Update the listener with what we've found
for (MessagingListener l : getListeners()) {
@ -1452,9 +1480,10 @@ public class MessagingController {
public void messagesFinished(int total) { }
});
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Done fetching small messages for folder " + folder);
}
}
private <T extends Message> void downloadLargeMessages(final Account account, final Folder<T> remoteFolder,
final LocalFolder localFolder,
@ -1465,12 +1494,10 @@ public class MessagingController {
final int todo,
FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
}
remoteFolder.fetch(largeMessages, fp, null);
for (T message : largeMessages) {
@ -1480,13 +1507,77 @@ public class MessagingController {
}
if (message.getBody() == null) {
downloadSaneBody(account, remoteFolder, localFolder, message);
} else {
downloadPartial(remoteFolder, localFolder, message);
}
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "About to notify listeners that we got a new large message "
+ account + ":" + folder + ":" + message.getUid());
}
// Update the listener with what we've found
progress.incrementAndGet();
// TODO do we need to re-fetch this here?
LocalMessage localMessage = localFolder.getMessage(message.getUid());
// Increment the number of "new messages" if the newly downloaded message is
// not marked as read.
if (!localMessage.isSet(Flag.SEEN)) {
newMessages.incrementAndGet();
}
for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
// Send a notification of this message
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);
}
}
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
}
}
private void downloadPartial(Folder remoteFolder, LocalFolder localFolder, 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.
*/
for (Part part : viewables) {
remoteFolder.fetchPart(message, part, null);
}
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
private void downloadSaneBody(Account account, Folder remoteFolder, LocalFolder localFolder, Message 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
* incomplete so the entire thing can be downloaded later if the user
* wishes to download it.
*/
fp = new FetchProfile();
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY_SANE);
/*
* TODO a good optimization here would be to make sure that all Stores set
@ -1513,7 +1604,8 @@ public class MessagingController {
* If there is no limit on autodownload size, that's the same as the message
* being smaller than the max size
*/
if (account.getMaximumAutoDownloadMessageSize() == 0 || message.getSize() < account.getMaximumAutoDownloadMessageSize()) {
if (account.getMaximumAutoDownloadMessageSize() == 0
|| message.getSize() < account.getMaximumAutoDownloadMessageSize()) {
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
} else {
// Set a flag indicating that the message has been partially downloaded and
@ -1521,63 +1613,6 @@ public class MessagingController {
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
}
} else {
/*
* 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.
*/
for (Part part : viewables) {
remoteFolder.fetchPart(message, part, null);
}
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
// Set a flag indicating this message has been fully downloaded and can be
// viewed.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "About to notify listeners that we got a new large message "
+ account + ":" + folder + ":" + message.getUid());
// Update the listener with what we've found
progress.incrementAndGet();
// TODO do we need to re-fetch this here?
LocalMessage localMessage = localFolder.getMessage(message.getUid());
// Increment the number of "new messages" if the newly downloaded message is
// not marked as read.
if (!localMessage.isSet(Flag.SEEN)) {
newMessages.incrementAndGet();
}
for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
// Send a notification of this message
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);
}
}//for large messages
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder);
}
@ -1590,9 +1625,10 @@ public class MessagingController {
final String folder = remoteFolder.getName();
if (remoteFolder.supportsFetchingFlags()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: About to sync flags for "
+ syncFlagMessages.size() + " remote messages for folder " + folder);
}
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.FLAGS);
@ -1828,8 +1864,9 @@ public class MessagingController {
" same message id");
String rUid = remoteFolder.getUidFromMessageId(localMessage);
if (rUid != null) {
Log.w(K9.LOG_TAG, "Local message has flag " + Flag.X_REMOTE_COPY_STARTED + " already set, and there is a remote message with " +
" uid " + rUid + ", assuming message was already copied and aborting this copy");
Log.w(K9.LOG_TAG, "Local message has flag " + Flag.X_REMOTE_COPY_STARTED +
" already set, and there is a remote message with uid " +
rUid + ", assuming message was already copied and aborting this copy");
String oldUid = localMessage.getUid();
localMessage.setUid(rUid);
@ -1958,18 +1995,21 @@ public class MessagingController {
}
remoteSrcFolder.open(Folder.OPEN_MODE_RW);
if (remoteSrcFolder.getMode() != Folder.OPEN_MODE_RW) {
throw new MessagingException("processingPendingMoveOrCopy: could not open remoteSrcFolder " + srcFolder + " read/write", true);
throw new MessagingException("processingPendingMoveOrCopy: could not open remoteSrcFolder "
+ srcFolder + " read/write", true);
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "processingPendingMoveOrCopy: source folder = " + srcFolder
+ ", " + messages.size() + " messages, destination folder = " + destFolder + ", isCopy = " + isCopy);
}
Map<String, String> remoteUidMap = null;
if (!isCopy && destFolder.equals(account.getTrashFolderName())) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "processingPendingMoveOrCopy doing special case for deleting message");
}
String destFolderName = destFolder;
if (K9.FOLDER_NONE.equals(destFolderName)) {
@ -1986,8 +2026,9 @@ public class MessagingController {
}
}
if (!isCopy && Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "processingPendingMoveOrCopy expunging folder " + account.getDescription() + ":" + srcFolder);
}
remoteSrcFolder.expunge();
}
@ -2088,8 +2129,9 @@ public class MessagingController {
if (account.getErrorFolderName().equals(folder)) {
return;
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "processPendingExpunge: folder = " + folder);
}
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(folder);
@ -2102,8 +2144,9 @@ public class MessagingController {
return;
}
remoteFolder.expunge();
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "processPendingExpunge: complete for folder = " + folder);
}
} finally {
closeFolder(remoteFolder);
}
@ -2606,8 +2649,9 @@ public class MessagingController {
l.loadAttachmentFinished(account, message, part);
}
} catch (MessagingException me) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Exception loading attachment", me);
}
for (MessagingListener l : getListeners(listener)) {
l.loadAttachmentFailed(account, message, part, me.getMessage());
@ -2756,9 +2800,10 @@ public class MessagingController {
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Scanning folder '" + account.getOutboxFolderName()
+ "' (" + localFolder.getId() + ") for messages to send");
}
Transport transport = transportProvider.getInstance(K9.app, account);
@ -2773,8 +2818,9 @@ public class MessagingController {
if (oldCount != null) {
count = oldCount;
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Send count for message " + message.getUid() + " is " + count.get());
}
if (count.incrementAndGet() > K9.MAX_SEND_ATTEMPTS) {
Log.e(K9.LOG_TAG, "Send count for message " + message.getUid() + " can't be delivered after "
@ -2793,8 +2839,9 @@ public class MessagingController {
}
message.setFlag(Flag.X_SEND_IN_PROGRESS, true);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Sending message with UID " + message.getUid());
}
transport.sendMessage(message);
message.setFlag(Flag.X_SEND_IN_PROGRESS, false);
message.setFlag(Flag.SEEN, true);
@ -2869,18 +2916,21 @@ public class MessagingController {
private void moveOrDeleteSentMessage(Account account, LocalStore localStore,
LocalFolder localFolder, LocalMessage message) throws MessagingException {
if (!account.hasSentFolder()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Account does not have a sent mail folder; deleting sent message");
}
message.setFlag(Flag.DELETED, true);
} else {
LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName());
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Moving sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
}
localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Moved sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
}
PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid());
queuePendingCommand(account, command);
@ -3188,9 +3238,10 @@ public class MessagingController {
origUidMap.put(message.getUid(), message);
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "moveOrCopyMessageSynchronous: source folder = " + srcFolder
+ ", " + messages.size() + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
}
Map<String, String> uidMap;
@ -3389,8 +3440,9 @@ public class MessagingController {
localFolder = localStore.getFolder(folder);
Map<String, String> uidMap = null;
if (folder.equals(account.getTrashFolderName()) || !account.hasTrashFolder()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Deleting messages in trash folder or trash set to -None-, not copying");
}
localFolder.setFlags(messages, Collections.singleton(Flag.DELETED), true);
} else {
@ -3399,8 +3451,9 @@ public class MessagingController {
localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES);
}
if (localTrashFolder.exists()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Deleting messages in normal folder, moving");
}
uidMap = localFolder.moveMessages(messages, localTrashFolder);
@ -3414,8 +3467,9 @@ public class MessagingController {
}
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Delete policy for account " + account.getDescription() + " is " + account.getDeletePolicy());
}
if (folder.equals(account.getOutboxFolderName())) {
for (Message message : messages) {
@ -3436,9 +3490,10 @@ public class MessagingController {
queueSetFlag(account, folder, true, Flag.SEEN, uids);
processPendingCommands(account);
} else {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Delete policy " + account.getDeletePolicy() + " prevents delete from server");
}
}
unsuppressMessages(account, messages);
} catch (UnavailableStorageException e) {
@ -3575,9 +3630,10 @@ public class MessagingController {
}
public void sendAlternate(Context context, Account account, LocalMessage message) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Got message " + account.getDescription() + ":" + message.getFolder()
+ ":" + message.getUid() + " for sendAlternate");
}
Intent msg = new Intent(Intent.ACTION_SEND);
String quotedText = null;
@ -3645,8 +3701,9 @@ public class MessagingController {
public void run() {
try {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Starting mail check");
}
Preferences prefs = Preferences.getPreferences(context);
Collection<Account> accounts;
@ -3669,8 +3726,9 @@ public class MessagingController {
@Override
public void run() {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Finished mail sync");
}
if (wakeLock != null) {
wakeLock.release();
@ -3699,13 +3757,15 @@ public class MessagingController {
}
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
if (!ignoreLastCheckedTime && accountInterval <= 0) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
}
return;
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Synchronizing account " + account.getDescription());
}
account.setRingNotified(false);
@ -3725,9 +3785,10 @@ public class MessagingController {
if (modeMismatch(aDisplayMode, fDisplayClass)) {
// Never sync a folder that isn't displayed
/*
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
" which is in display mode " + fDisplayClass + " while account is in display mode " + aDisplayMode);
}
*/
continue;
@ -3736,9 +3797,10 @@ public class MessagingController {
if (modeMismatch(aSyncMode, fSyncClass)) {
// Do not sync folders in the wrong class
/*
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName() +
" which is in sync mode " + fSyncClass + " while account is in sync mode " + aSyncMode);
}
*/
continue;
@ -3752,8 +3814,9 @@ public class MessagingController {
putBackground("clear notification flag for " + account.getDescription(), null, new Runnable() {
@Override
public void run() {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Clearing notification flag for " + account.getDescription());
}
account.setRingNotified(false);
try {
AccountStats stats = account.getStats(context);
@ -3780,16 +3843,18 @@ public class MessagingController {
final MessagingListener listener) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Folder " + folder.getName() + " was last synced @ " +
new Date(folder.getLastChecked()));
}
if (!ignoreLastCheckedTime && folder.getLastChecked() >
(System.currentTimeMillis() - accountInterval)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName()
+ ", previously synced @ " + new Date(folder.getLastChecked())
+ " which would be too recent for the account period");
}
return;
}
@ -3806,10 +3871,11 @@ public class MessagingController {
if (!ignoreLastCheckedTime && tLocalFolder.getLastChecked() >
(System.currentTimeMillis() - accountInterval)) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not running Command for folder " + folder.getName()
+ ", previously synced @ " + new Date(folder.getLastChecked())
+ " which would be too recent for the account period");
}
return;
}
showFetchingMailNotificationIfNecessary(account, folder);
@ -3978,9 +4044,10 @@ public class MessagingController {
try {
Integer messageUid = Integer.parseInt(message.getUid());
if (messageUid <= localFolder.getLastUid()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Message uid is " + messageUid + ", max message uid is " +
localFolder.getLastUid() + ". Skipping notification.");
}
return false;
}
} catch (NumberFormatException e) {
@ -4126,9 +4193,10 @@ public class MessagingController {
if (folder.getName().equals(account.getErrorFolderName())
|| folder.getName().equals(account.getOutboxFolderName())) {
/*
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not pushing folder " + folder.getName() +
" which should never be pushed");
}
*/
continue;
@ -4141,9 +4209,10 @@ public class MessagingController {
if (modeMismatch(aDisplayMode, fDisplayClass)) {
// Never push a folder that isn't displayed
/*
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not pushing folder " + folder.getName() +
" which is in display class " + fDisplayClass + " while account is in display mode " + aDisplayMode);
}
*/
continue;
@ -4152,15 +4221,17 @@ public class MessagingController {
if (modeMismatch(aPushMode, fPushClass)) {
// Do not push folders in the wrong class
/*
if (K9.DEBUG)
if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Not pushing folder " + folder.getName() +
" which is in push mode " + fPushClass + " while account is in push mode " + aPushMode);
}
*/
continue;
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Starting pusher for " + account.getDescription() + ":" + folder.getName());
}
names.add(folder.getName());
}
@ -4170,9 +4241,10 @@ public class MessagingController {
int maxPushFolders = account.getMaxPushFolders();
if (names.size() > maxPushFolders) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Count of folders to push for account " + account.getDescription() + " is " + names.size()
+ ", greater than limit of " + maxPushFolders + ", truncating");
}
names = names.subList(0, maxPushFolders);
}
@ -4180,8 +4252,9 @@ public class MessagingController {
try {
Store store = account.getRemoteStore();
if (!store.isPushCapable()) {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Account " + account.getDescription() + " is not push capable, skipping");
}
return false;
}
@ -4199,8 +4272,9 @@ public class MessagingController {
return true;
} else {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "No folders are configured for pushing in account " + account.getDescription());
}
return false;
}
@ -4211,8 +4285,9 @@ public class MessagingController {
}
public void stopAllPushing() {
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Stopping all pushers");
}
Iterator<Pusher> iter = pushers.values().iterator();
while (iter.hasNext()) {
@ -4222,10 +4297,12 @@ public class MessagingController {
}
}
public void messagesArrived(final Account account, final Folder remoteFolder, final List<Message> messages, final boolean flagSyncOnly) {
if (K9.DEBUG)
public void messagesArrived(final Account account, final Folder remoteFolder, final List<Message> messages,
final boolean flagSyncOnly) {
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Got new pushed email messages for account " + account.getDescription()
+ ", folder " + remoteFolder.getName());
}
final CountDownLatch latch = new CountDownLatch(1);
putBackground("Push messageArrived of account " + account.getDescription()
@ -4246,8 +4323,9 @@ public class MessagingController {
localFolder.setLastPush(System.currentTimeMillis());
localFolder.setStatus(null);
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "messagesArrived newCount = " + newCount + ", unread count = " + unreadMessageCount);
}
if (unreadMessageCount == 0) {
notificationController.clearNewMailNotifications(account);
@ -4281,9 +4359,10 @@ public class MessagingController {
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Interrupted while awaiting latch release", e);
}
if (K9.DEBUG)
if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "MessagingController.messagesArrivedLatch released");
}
}
public void systemStatusChanged() {
for (MessagingListener l : getListeners()) {