Added POP3 delete

This commit is contained in:
M66B 2019-09-20 10:21:38 +02:00
parent d7cf5736de
commit 0043d1c9a7
1 changed files with 30 additions and 3 deletions

View File

@ -216,7 +216,7 @@ class Core {
// Do nothing
break;
case EntityOperation.DELETE:
onDelete(context, jargs, folder, message, (POP3Folder) ifolder);
onDelete(context, jargs, folder, message, (POP3Folder) ifolder, state);
break;
case EntityOperation.SYNC:
onSynchronizeMessages(context, jargs, account, folder, (POP3Folder) ifolder, state);
@ -806,12 +806,39 @@ class Core {
}
}
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder) throws MessagingException {
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder, State state) throws MessagingException {
// Delete message
DB db = DB.getInstance(context);
if (EntityFolder.INBOX.equals(folder.type)) {
// Do nothing
Message[] imessages = ifolder.getMessages();
Log.i(folder.name + " POP messages=" + imessages.length);
boolean found = false;
for (Message imessage : imessages) {
MessageHelper helper = new MessageHelper((MimeMessage) imessage);
String msgid = helper.getMessageID();
if (msgid != null && msgid.equals(message.msgid)) {
found = true;
Log.i(folder.name + " POP delete=" + msgid);
imessage.setFlag(Flags.Flag.DELETED, true);
break;
}
}
Log.i(folder.name + " POP expunge=" + found);
if (found)
try {
ifolder.close(true);
ifolder.open(Folder.READ_WRITE);
} catch (Throwable ex) {
Log.e(ex);
state.error(new FolderClosedException(ifolder, "POP"));
}
else
db.message().deleteMessage(folder.id, message.id);
} else
db.message().deleteMessage(folder.id, message.id);
}