Guarantee deletion of tmp file

pull/209/head
M66B 2 years ago
parent 20e17ce615
commit f2fb73b926

@ -1520,7 +1520,9 @@ class Core {
for (Message imessage : map.keySet()) { for (Message imessage : map.keySet()) {
EntityMessage message = map.get(imessage); EntityMessage message = map.get(imessage);
Message icopy;
File file = new File(message.getFile(context).getAbsoluteFile() + ".copy"); File file = new File(message.getFile(context).getAbsoluteFile() + ".copy");
try {
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
imessage.writeTo(os); imessage.writeTo(os);
} }
@ -1528,7 +1530,6 @@ class Core {
Properties props = MessageHelper.getSessionProperties(account.unicode); Properties props = MessageHelper.getSessionProperties(account.unicode);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
Message icopy;
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
if (duplicate) { if (duplicate) {
String msgid = EntityMessage.generateMessageId(); String msgid = EntityMessage.generateMessageId();
@ -1547,8 +1548,9 @@ class Core {
} else } else
icopy = new MimeMessage(isession, is); icopy = new MimeMessage(isession, is);
} }
} finally {
file.delete(); file.delete();
}
for (Flags.Flag flag : imessage.getFlags().getSystemFlags()) for (Flags.Flag flag : imessage.getFlags().getSystemFlags())
icopy.setFlag(flag, true); icopy.setFlag(flag, true);

Loading…
Cancel
Save