Added purge folder

pull/184/head
M66B 4 years ago
parent 8cb130c0e8
commit 81fdd8dfe0

@ -388,6 +388,7 @@ The low priority status bar notification shows the number of pending operations,
* *attachment*: download attachment
* *sync*: synchronize local and remote messages
* *subscribe*: subscribe to remote folder
* *purge*: delete all messages from remote folder
* *send*: send message
* *exists*: check if message exists
* *rule*: execute rule on body text

@ -475,13 +475,13 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_local, 3, R.string.title_delete_local);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_browsed, 4, R.string.title_delete_browsed);
if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, 5, R.string.title_empty_trash);
else if (EntityFolder.JUNK.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_spam, 5, R.string.title_empty_spam);
}
if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, 5, R.string.title_empty_trash);
else if (EntityFolder.JUNK.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_spam, 5, R.string.title_empty_spam);
if (folder.account != null) {
popupMenu.getMenu().add(Menu.NONE, R.string.title_unified_folder, 6, R.string.title_unified_folder)
.setCheckable(true).setChecked(folder.unified);

@ -56,6 +56,7 @@ import com.sun.mail.imap.IMAPStore;
import com.sun.mail.imap.protocol.FLAGS;
import com.sun.mail.imap.protocol.FetchResponse;
import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.imap.protocol.MessageSet;
import com.sun.mail.imap.protocol.UID;
import com.sun.mail.pop3.POP3Folder;
import com.sun.mail.pop3.POP3Message;
@ -186,7 +187,8 @@ class Core {
if (message == null &&
!EntityOperation.FETCH.equals(op.name) &&
!EntityOperation.SYNC.equals(op.name) &&
!EntityOperation.SUBSCRIBE.equals(op.name))
!EntityOperation.SUBSCRIBE.equals(op.name) &&
!EntityOperation.PURGE.equals(op.name))
throw new MessageRemovedException();
// Process similar operations
@ -303,6 +305,10 @@ class Core {
onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, (POP3Store) istore, state);
break;
case EntityOperation.PURGE:
onPurgeFolder(context, jargs, folder, (POP3Folder) ifolder);
break;
default:
Log.w(folder.name + " ignored=" + op.name);
}
@ -381,6 +387,10 @@ class Core {
onSubscribeFolder(context, jargs, folder, (IMAPFolder) ifolder);
break;
case EntityOperation.PURGE:
onPurgeFolder(context, jargs, folder, (IMAPFolder) ifolder);
break;
case EntityOperation.RULE:
onRule(context, jargs, message);
break;
@ -1730,6 +1740,45 @@ class Core {
Log.i(folder.name + " subscribed=" + subscribe);
}
private static void onPurgeFolder(Context context, JSONArray jargs, EntityFolder folder, IMAPFolder ifolder) throws MessagingException {
// Delete all messages from folder
DB db = DB.getInstance(context);
try {
final MessageSet[] sets = new MessageSet[]{new MessageSet(1, ifolder.getMessageCount())};
Log.i(folder.name + " purge " + MessageSet.toString(sets));
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
protocol.storeFlags(sets, new Flags(Flags.Flag.DELETED), true);
return null;
}
});
Log.i(folder.name + " purge deleted");
ifolder.expunge();
Log.i(folder.name + " purge expunged");
} finally {
int count = ifolder.getMessageCount();
db.folder().setFolderTotal(folder.id, count < 0 ? null : count);
}
}
private static void onPurgeFolder(Context context, JSONArray jargs, EntityFolder folder, POP3Folder ifolder) throws MessagingException {
DB db = DB.getInstance(context);
try {
db.beginTransaction();
int purged = db.message().deleteHiddenMessages(folder.id);
Log.i(folder.name + " purge count=" + purged);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
private static void onRule(Context context, JSONArray jargs, EntityMessage message) throws JSONException, IOException {
// Download message body
DB db = DB.getInstance(context);

@ -767,6 +767,11 @@ public interface DaoMessage {
" AND NOT uid IS NULL")
int deleteBrowsedMessages(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND ui_hide")
int deleteHiddenMessages(long folder);
@Query("DELETE FROM message" +
" WHERE folder = :folder" +
" AND uid IS NULL" +

@ -99,6 +99,7 @@ public class EntityOperation {
static final String SEND = "send";
static final String EXISTS = "exists";
static final String RULE = "rule";
static final String PURGE = "purge";
static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context);

@ -691,13 +691,23 @@ public class FragmentFolders extends FragmentBase {
if (!folder.type.equals(type))
throw new IllegalStateException("Invalid folder type=" + type);
EntityAccount account = db.account().getAccount(folder.account);
if (account == null)
return null;
EntityLog.log(context,
"Empty account=" + account.name + " folder=" + folder.name + " count=" + folder.total);
List<Long> ids = db.message().getMessageByFolder(folder.id);
for (Long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message.uid != null || !TextUtils.isEmpty(message.msgid))
EntityOperation.queue(context, message, EntityOperation.DELETE);
if (message != null &&
(account.protocol == EntityAccount.TYPE_POP || message.uid != null))
db.message().setMessageUiHide(message.id, true);
}
EntityOperation.queue(context, folder, EntityOperation.PURGE);
db.setTransactionSuccessful();
} finally {
db.endTransaction();

@ -2493,7 +2493,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
result.hasTrash = (result.hasTrash == null ? hasTrash : result.hasTrash && hasTrash);
result.hasJunk = (result.hasJunk == null ? hasJunk : result.hasJunk && hasJunk);
if (accounts.size() == 1)
if (accounts.size() == 1 && account.protocol == EntityAccount.TYPE_IMAP)
result.copyto = account;
}
@ -6832,21 +6832,21 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
for (EntityAccount account : accounts) {
EntityFolder folder = db.folder().getFolderByType(account.id, type);
EntityLog.log(context,
"Empty account=" + account.name + " folder=" + (folder == null ? null : folder.name));
if (folder == null)
continue;
EntityLog.log(context,
"Empty account=" + account.name + " folder=" + folder.name + " count=" + folder.total);
List<Long> ids = db.message().getMessageByFolder(folder.id);
for (Long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message != null &&
(account.protocol == EntityAccount.TYPE_POP ||
message.uid != null || !TextUtils.isEmpty(message.msgid))) {
Log.i("Deleting account=" + account.id + " folder=" + folder.id + " message=" + message.id);
EntityOperation.queue(context, message, EntityOperation.DELETE);
}
(account.protocol == EntityAccount.TYPE_POP || message.uid != null))
db.message().setMessageUiHide(message.id, true);
}
EntityOperation.queue(context, folder, EntityOperation.PURGE);
}
db.setTransactionSuccessful();

Loading…
Cancel
Save