Prevent purging busy messages

pull/198/head
M66B 4 years ago
parent 2dd844724a
commit 1d3f496a3c

@ -61,8 +61,6 @@ import com.sun.mail.imap.IMAPStore;
import com.sun.mail.imap.protocol.FLAGS; import com.sun.mail.imap.protocol.FLAGS;
import com.sun.mail.imap.protocol.FetchResponse; import com.sun.mail.imap.protocol.FetchResponse;
import com.sun.mail.imap.protocol.IMAPProtocol; import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.imap.protocol.MailboxInfo;
import com.sun.mail.imap.protocol.MessageSet;
import com.sun.mail.imap.protocol.UID; import com.sun.mail.imap.protocol.UID;
import com.sun.mail.pop3.POP3Folder; import com.sun.mail.pop3.POP3Folder;
import com.sun.mail.pop3.POP3Message; import com.sun.mail.pop3.POP3Message;
@ -2161,23 +2159,25 @@ class Core {
private static void onPurgeFolder(Context context, JSONArray jargs, EntityFolder folder, IMAPFolder ifolder) throws MessagingException { private static void onPurgeFolder(Context context, JSONArray jargs, EntityFolder folder, IMAPFolder ifolder) throws MessagingException {
// Delete all messages from folder // Delete all messages from folder
try { try {
Log.i(folder.name + " purge=" + ifolder.getMessageCount()); DB db = DB.getInstance(context);
ifolder.doCommand(new IMAPFolder.ProtocolCommand() { List<Long> busy = db.message().getBusyUids(folder.id, new Date().getTime());
@Override
public Object doCommand(IMAPProtocol protocol) throws ProtocolException { Message[] imessages = ifolder.getMessages();
MailboxInfo info = protocol.select(ifolder.getFullName()); Log.i(folder.name + " purge=" + imessages.length + " busy=" + busy.size());
if (info.total > 0) {
MessageSet[] sets = new MessageSet[]{new MessageSet(1, info.total)}; FetchProfile fp = new FetchProfile();
EntityLog.log(context, folder.name + " purging=" + MessageSet.toString(sets)); fp.add(UIDFolder.FetchProfileItem.UID);
try { ifolder.fetch(imessages, fp);
protocol.storeFlags(sets, new Flags(Flags.Flag.DELETED), true);
} catch (ProtocolException ex) { List<Message> idelete = new ArrayList<>();
throw new ProtocolException("Purge=" + MessageSet.toString(sets), ex); for (Message imessage : imessages) {
} long uid = ifolder.getUID(imessage);
} if (!busy.contains(uid))
return null; idelete.add(imessage);
} }
});
EntityLog.log(context, folder.name + " purging=" + idelete.size() + "/" + imessages.length);
ifolder.setFlags(idelete.toArray(new Message[0]), new Flags(Flags.Flag.DELETED), true);
Log.i(folder.name + " purge deleted"); Log.i(folder.name + " purge deleted");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

@ -560,6 +560,13 @@ public interface DaoMessage {
" AND NOT uid IS NULL") " AND NOT uid IS NULL")
List<Long> getUids(long folder, Long received); List<Long> getUids(long folder, Long received);
@Query("SELECT uid FROM message" +
" WHERE folder = :folder" +
" AND NOT ui_busy IS NULL" +
" AND ui_busy > :time" +
" AND NOT uid IS NULL")
List<Long> getBusyUids(long folder, long time);
@Query("SELECT id, uidl, msgid FROM message" + @Query("SELECT id, uidl, msgid FROM message" +
" WHERE folder = :folder") " WHERE folder = :folder")
List<TupleUidl> getUidls(long folder); List<TupleUidl> getUidls(long folder);

Loading…
Cancel
Save