After marking a message as deleted, is it possible to undo the deletion?

John Zukowski

Messages aren't deleted until you expunge the folder. If you don't want to the messages deleted, call close() with a value of false, and/or don't call expunge().

Once you've closed the folder with close(true) or called expunge(), the message is gone.