Added UID expunge

pull/194/merge
M66B 3 years ago
parent a9cfd10b07
commit 1f04eecea7

@ -763,7 +763,7 @@ class Core {
} }
if (uid != null && purge) { if (uid != null && purge) {
boolean purged = false; List<Message> deleted = new ArrayList<>();
for (Message iexisting : imessages) { for (Message iexisting : imessages) {
long muid = ifolder.getUID(iexisting); long muid = ifolder.getUID(iexisting);
if (muid < 0) if (muid < 0)
@ -772,21 +772,13 @@ class Core {
try { try {
Log.i(name + " deleting uid=" + muid + " for msgid=" + msgid); Log.i(name + " deleting uid=" + muid + " for msgid=" + msgid);
iexisting.setFlag(Flags.Flag.DELETED, true); iexisting.setFlag(Flags.Flag.DELETED, true);
purged = true; deleted.add(iexisting);
} catch (MessagingException ignored) { } catch (MessagingException ignored) {
Log.w(name + " existing gone uid=" + muid + " for msgid=" + msgid); Log.w(name + " existing gone uid=" + muid + " for msgid=" + msgid);
} }
} }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); expunge(context, ifolder, deleted);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (purged && perform_expunge)
try {
ifolder.expunge();
} catch (MessagingException ex) {
// NO EXPUNGE failed.
Log.e(ex);
}
} }
} }
@ -989,11 +981,7 @@ class Core {
if (imessage == null) if (imessage == null)
throw new MessageRemovedException(); throw new MessageRemovedException();
imessage.setFlag(Flags.Flag.DELETED, true); imessage.setFlag(Flags.Flag.DELETED, true);
expunge(context, ifolder, Arrays.asList(imessage));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge();
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.w(ex); Log.w(ex);
} }
@ -1162,10 +1150,7 @@ class Core {
Message iprev = ifolder.getMessageByUID(Math.min(newuid, found)); Message iprev = ifolder.getMessageByUID(Math.min(newuid, found));
if (iprev != null) { if (iprev != null) {
iprev.setFlag(Flags.Flag.DELETED, true); iprev.setFlag(Flags.Flag.DELETED, true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); expunge(context, ifolder, Arrays.asList(iprev));
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge();
} }
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.w(ex); Log.w(ex);
@ -1369,11 +1354,7 @@ class Core {
try { try {
for (Message imessage : map.keySet()) for (Message imessage : map.keySet())
imessage.setFlag(Flags.Flag.DELETED, true); imessage.setFlag(Flags.Flag.DELETED, true);
expunge(context, ifolder, Arrays.asList(map.keySet().toArray(new Message[0])));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge();
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
Log.w(ex); Log.w(ex);
} }
@ -1589,8 +1570,9 @@ class Core {
} }
try { try {
boolean deleted = false; List<Message> deleted = new ArrayList<>();
boolean found = false;
if (message.uid != null) { if (message.uid != null) {
Message iexisting = ifolder.getMessageByUID(message.uid); Message iexisting = ifolder.getMessageByUID(message.uid);
if (iexisting == null) if (iexisting == null)
@ -1602,13 +1584,16 @@ class Core {
iexisting.setFlag(Flags.Flag.DELETED, true); iexisting.setFlag(Flags.Flag.DELETED, true);
else else
iexisting.setFlag(Flags.Flag.DELETED, message.ui_deleted); iexisting.setFlag(Flags.Flag.DELETED, message.ui_deleted);
deleted = true;
found = true;
if (perform_expunge || message.ui_deleted)
deleted.add(iexisting);
} catch (MessageRemovedException ignored) { } catch (MessageRemovedException ignored) {
Log.w(folder.name + " existing gone uid=" + message.uid); Log.w(folder.name + " existing gone uid=" + message.uid);
} }
} }
if (!deleted && !TextUtils.isEmpty(message.msgid)) if (!found && !TextUtils.isEmpty(message.msgid))
try { try {
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid)); Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid));
if (imessages == null) if (imessages == null)
@ -1622,7 +1607,9 @@ class Core {
iexisting.setFlag(Flags.Flag.DELETED, true); iexisting.setFlag(Flags.Flag.DELETED, true);
else else
iexisting.setFlag(Flags.Flag.DELETED, message.ui_deleted); iexisting.setFlag(Flags.Flag.DELETED, message.ui_deleted);
deleted = true;
if (perform_expunge || message.ui_deleted)
deleted.add(iexisting);
} catch (MessageRemovedException ignored) { } catch (MessageRemovedException ignored) {
Log.w(folder.name + " existing gone uid=" + muid); Log.w(folder.name + " existing gone uid=" + muid);
} }
@ -1632,11 +1619,10 @@ class Core {
} }
if (perform_expunge) { if (perform_expunge) {
if (deleted) if (expunge(context, ifolder, deleted))
ifolder.expunge(); // NO EXPUNGE failed.
db.message().deleteMessage(message.id); db.message().deleteMessage(message.id);
} else { } else {
if (deleted) if (deleted.size() > 0)
db.message().setMessageDeleted(message.id, message.ui_deleted); db.message().setMessageDeleted(message.id, message.ui_deleted);
} }
@ -2391,12 +2377,7 @@ class Core {
} else } else
ifolder.setFlags(idelete.toArray(new Message[0]), new Flags(Flags.Flag.DELETED), true); 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");
expunge(context, ifolder, idelete);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (perform_expunge)
ifolder.expunge();
Log.i(folder.name + " purge expunged");
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
throw ex; throw ex;
@ -3059,13 +3040,13 @@ class Core {
} }
}); });
int expunge = 0; List<Message> deleted = new ArrayList<>();
for (int i = 0; i < imessages.length; i++) { for (int i = 0; i < imessages.length; i++) {
state.ensureRunning("Sync/IMAP/delete"); state.ensureRunning("Sync/IMAP/delete");
try { try {
if (perform_expunge && imessages[i].isSet(Flags.Flag.DELETED)) if (perform_expunge && imessages[i].isSet(Flags.Flag.DELETED))
expunge++; deleted.add(imessages[i]);
else else
uids.remove(ifolder.getUID(imessages[i])); uids.remove(ifolder.getUID(imessages[i]));
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
@ -3079,13 +3060,7 @@ class Core {
} }
} }
if (expunge > 0) expunge(context, ifolder, deleted);
try {
Log.i(folder.name + " expunging=" + expunge);
ifolder.expunge();
} catch (Throwable ex) {
Log.w(ex);
}
if (uids.size() > 0) { if (uids.size() > 0) {
// This is done outside of JavaMail to prevent changed notifications // This is done outside of JavaMail to prevent changed notifications
@ -3483,7 +3458,6 @@ class Core {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean download_headers = prefs.getBoolean("download_headers", false); boolean download_headers = prefs.getBoolean("download_headers", false);
boolean notify_known = prefs.getBoolean("notify_known", false); boolean notify_known = prefs.getBoolean("notify_known", false);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
boolean pro = ActivityBilling.isPro(context); boolean pro = ActivityBilling.isPro(context);
long uid = ifolder.getUID(imessage); long uid = ifolder.getUID(imessage);
@ -3496,13 +3470,10 @@ class Core {
Log.w(folder.name + " expunged uid=" + uid); Log.w(folder.name + " expunged uid=" + uid);
throw new MessageRemovedException("Expunged"); throw new MessageRemovedException("Expunged");
} }
if (perform_expunge && imessage.isSet(Flags.Flag.DELETED)) {
if (imessage.isSet(Flags.Flag.DELETED)) {
Log.w(folder.name + " deleted uid=" + uid); Log.w(folder.name + " deleted uid=" + uid);
try { expunge(context, ifolder, Arrays.asList(imessage));
ifolder.expunge();
} catch (MessagingException ex) {
Log.w(ex);
}
throw new MessageRemovedException("Deleted"); throw new MessageRemovedException("Deleted");
} }
@ -4050,6 +4021,32 @@ class Core {
return message; return message;
} }
private static boolean expunge(Context context, IMAPFolder ifolder, List<Message> messages) {
if (messages.size() == 0)
return false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
if (!perform_expunge)
return false;
try {
boolean uidplus = MessageHelper.hasCapability(ifolder, "UIDPLUS");
String count = (uidplus ? messages.size() : "all") + "messages";
Log.i(ifolder.getName() + " expunging " + count);
if (uidplus)
ifolder.expunge(messages.toArray(new Message[0]));
else
ifolder.expunge();
Log.i(ifolder.getName() + " expunged " + count);
return true;
} catch (MessagingException ex) {
// NO EXPUNGE failed.
Log.w(ex);
return false;
}
}
private static EntityIdentity matchIdentity(Context context, EntityFolder folder, EntityMessage message) { private static EntityIdentity matchIdentity(Context context, EntityFolder folder, EntityMessage message) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);

Loading…
Cancel
Save