-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Empty Spam command #8126
base: main
Are you sure you want to change the base?
Add Empty Spam command #8126
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingDelete; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptySpam; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingEmptyTrash; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingExpunge; | ||
import com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead; | ||
|
@@ -2080,6 +2081,66 @@ private static List<String> getUidsFromMessages(List<LocalMessage> messages) { | |
return uids; | ||
} | ||
|
||
void processPendingEmptySpam(Account account) throws MessagingException { | ||
if (!account.hasSpamFolder()) { | ||
return; | ||
} | ||
|
||
long spamFolderId = account.getSpamFolderId(); | ||
LocalStore localStore = localStoreProvider.getInstance(account); | ||
LocalFolder folder = localStore.getFolder(spamFolderId); | ||
folder.open(); | ||
String spamFolderServerId = folder.getServerId(); | ||
|
||
Backend backend = getBackend(account); | ||
backend.deleteAllMessages(spamFolderServerId); | ||
|
||
// Remove all messages marked as deleted | ||
folder.destroyDeletedMessages(); | ||
|
||
compact(account); | ||
} | ||
|
||
public void emptySpam(final Account account, MessagingListener listener) { | ||
putBackground("emptySpam", listener, new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
Long spamFolderId = account.getSpamFolderId(); | ||
if (spamFolderId == null) { | ||
Timber.w("No Spam folder configured. Can't empty spam."); | ||
return; | ||
} | ||
|
||
LocalStore localStore = localStoreProvider.getInstance(account); | ||
LocalFolder localFolder = localStore.getFolder(spamFolderId); | ||
localFolder.open(); | ||
|
||
boolean isSpamLocalOnly = isSpamLocalOnly(account); | ||
if (isSpamLocalOnly) { | ||
localFolder.clearAllMessages(); | ||
} else { | ||
localFolder.destroyLocalOnlyMessages(); | ||
localFolder.setFlags(Collections.singleton(Flag.DELETED), true); | ||
} | ||
Comment on lines
+2119
to
+2125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike with the trash folder, there never is a local-only spam folder. Assume |
||
|
||
for (MessagingListener l : getListeners()) { | ||
l.folderStatusChanged(account, spamFolderId); | ||
} | ||
|
||
if (!isSpamLocalOnly) { | ||
PendingCommand command = PendingEmptySpam.create(); | ||
queuePendingCommand(account, command); | ||
processPendingCommands(account); | ||
} | ||
} catch (Exception e) { | ||
Timber.e(e, "emptySpam failed"); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
void processPendingEmptyTrash(Account account) throws MessagingException { | ||
if (!account.hasTrashFolder()) { | ||
return; | ||
|
@@ -2157,6 +2218,22 @@ protected void clearFolderSynchronous(Account account, long folderId) { | |
} | ||
|
||
|
||
/** | ||
* Find out whether the account type only supports a local Spam folder. | ||
* <p> | ||
* <p>Note: Currently this is only the case for POP3 accounts.</p> | ||
* | ||
* @param account | ||
* The account to check. | ||
* | ||
* @return {@code true} if the account only has a local Spam folder that is not synchronized | ||
* with a folder on the server. {@code false} otherwise. | ||
*/ | ||
private boolean isSpamLocalOnly(Account account) { | ||
Backend backend = getBackend(account); | ||
return !backend.getSupportsSpamFolder(); | ||
} | ||
|
||
/** | ||
* Find out whether the account type only supports a local Trash folder. | ||
* <p> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -738,6 +738,12 @@ class MessageListFragment : | |
} | ||
} | ||
|
||
private fun onEmptySpam() { | ||
if (isShowingSpamFolder) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
showDialog(R.id.dialog_confirm_empty_spam) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ID needs to be added to |
||
} | ||
} | ||
|
||
private fun onEmptyTrash() { | ||
if (isShowingTrashFolder) { | ||
showDialog(R.id.dialog_confirm_empty_trash) | ||
|
@@ -786,6 +792,14 @@ class MessageListFragment : | |
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText) | ||
} | ||
|
||
R.id.dialog_confirm_empty_spam -> { | ||
val title = getString(R.string.dialog_confirm_empty_spam_title) | ||
val message = getString(R.string.dialog_confirm_empty_spam_message) | ||
Comment on lines
+796
to
+797
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These strings are missing. |
||
val confirmText = getString(R.string.dialog_confirm_delete_confirm_button) | ||
val cancelText = getString(R.string.dialog_confirm_delete_cancel_button) | ||
ConfirmationDialogFragment.newInstance(dialogId, title, message, confirmText, cancelText) | ||
} | ||
|
||
R.id.dialog_confirm_empty_trash -> { | ||
val title = getString(R.string.dialog_confirm_empty_trash_title) | ||
val message = getString(R.string.dialog_confirm_empty_trash_message) | ||
|
@@ -820,6 +834,7 @@ class MessageListFragment : | |
menu.findItem(R.id.set_sort).isVisible = true | ||
menu.findItem(R.id.select_all).isVisible = true | ||
menu.findItem(R.id.mark_all_as_read).isVisible = isMarkAllAsReadSupported | ||
menu.findItem(R.id.empty_spam).isVisible = isShowingSpamFolder | ||
menu.findItem(R.id.empty_trash).isVisible = isShowingTrashFolder | ||
|
||
if (isSingleAccountMode) { | ||
|
@@ -843,6 +858,7 @@ class MessageListFragment : | |
menu.findItem(R.id.select_all).isVisible = false | ||
menu.findItem(R.id.mark_all_as_read).isVisible = false | ||
menu.findItem(R.id.send_messages).isVisible = false | ||
menu.findItem(R.id.empty_spam).isVisible = false | ||
menu.findItem(R.id.empty_trash).isVisible = false | ||
menu.findItem(R.id.expunge).isVisible = false | ||
menu.findItem(R.id.search_everywhere).isVisible = false | ||
|
@@ -862,6 +878,7 @@ class MessageListFragment : | |
R.id.select_all -> selectAll() | ||
R.id.mark_all_as_read -> confirmMarkAllAsRead() | ||
R.id.send_messages -> onSendPendingMessages() | ||
R.id.empty_spam -> onEmptySpam() | ||
R.id.empty_trash -> onEmptyTrash() | ||
R.id.expunge -> onExpunge() | ||
R.id.search_everywhere -> onSearchEverywhere() | ||
|
@@ -1225,6 +1242,10 @@ class MessageListFragment : | |
markAllAsRead() | ||
} | ||
|
||
R.id.dialog_confirm_empty_spam -> { | ||
messagingController.emptySpam(account, null) | ||
} | ||
|
||
R.id.dialog_confirm_empty_trash -> { | ||
messagingController.emptyTrash(account, null) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessagingController
already is way too large. Please move your new code toSpamOperations
and write it in Kotlin. SeeDraftOperations
for an example.