Delete previous messages by ID

pull/147/head
M66B 6 years ago
parent 7062a6c947
commit 0f055effb1

@ -1687,6 +1687,10 @@ public class ServiceSynchronize extends LifecycleService {
} }
private void doAdd(EntityFolder folder, Session isession, IMAPStore istore, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException, IOException { private void doAdd(EntityFolder folder, Session isession, IMAPStore istore, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException, IOException {
// Add message
if (TextUtils.isEmpty(message.msgid))
throw new IllegalArgumentException("Message ID missing");
// Get message // Get message
MimeMessage imessage; MimeMessage imessage;
if (folder.id.equals(message.folder)) { if (folder.id.equals(message.folder)) {
@ -1741,16 +1745,17 @@ public class ServiceSynchronize extends LifecycleService {
if (folder.id.equals(message.folder)) { if (folder.id.equals(message.folder)) {
// Delete previous message // Delete previous message
if (message.uid != null) { Message[] ideletes = ifolder.search(new MessageIDTerm(message.msgid));
Message iprevious = ifolder.getMessageByUID(message.uid); for (Message idelete : ideletes) {
if (iprevious == null) long duid = ifolder.getUID(idelete);
Log.e(folder.name + " previous uid=" + message.uid + " not found"); if (duid == uid)
Log.i(folder.name + " append confirmed uid=" + duid);
else { else {
Log.i(folder.name + " deleting uid=" + message.uid); Log.i(folder.name + " deleting uid=" + duid + " msgid=" + message.msgid);
iprevious.setFlag(Flags.Flag.DELETED, true); idelete.setFlag(Flags.Flag.DELETED, true);
ifolder.expunge();
} }
} }
ifolder.expunge();
} else { } else {
// Cross account move // Cross account move
if (autoread) { if (autoread) {
@ -1861,14 +1866,15 @@ public class ServiceSynchronize extends LifecycleService {
private void doDelete(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException { private void doDelete(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException {
// Delete message // Delete message
if (message.msgid != null) { if (TextUtils.isEmpty(message.msgid))
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid)); throw new IllegalArgumentException("Message ID missing");
for (Message imessage : imessages) {
Log.i("Deleting uid=" + message.uid + " msgid=" + message.msgid); Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid));
imessage.setFlag(Flags.Flag.DELETED, true); for (Message imessage : imessages) {
} Log.i(folder.name + " deleting uid=" + message.uid + " msgid=" + message.msgid);
ifolder.expunge(); imessage.setFlag(Flags.Flag.DELETED, true);
} }
ifolder.expunge();
db.message().deleteMessage(message.id); db.message().deleteMessage(message.id);
} }
@ -2578,10 +2584,8 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(folder.name + " set uid=" + uid); Log.i(folder.name + " set uid=" + uid);
dup.uid = uid; dup.uid = uid;
filter = true; filter = true;
} else if (dup.uid != uid) { } else
Log.e(folder.name + " changed uid=" + dup.uid + "/" + uid); Log.w(folder.name + " changed uid=" + dup.uid + " -> " + uid);
dup.uid = uid;
}
dup.msgid = msgid; dup.msgid = msgid;
dup.thread = thread; dup.thread = thread;

Loading…
Cancel
Save