Guarantee deletion of tmp file

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

@ -1520,36 +1520,38 @@ 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 (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try {
imessage.writeTo(os); try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
} imessage.writeTo(os);
}
Properties props = MessageHelper.getSessionProperties(account.unicode);
Session isession = Session.getInstance(props, null);
Message icopy; Properties props = MessageHelper.getSessionProperties(account.unicode);
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { Session isession = Session.getInstance(props, null);
if (duplicate) {
String msgid = EntityMessage.generateMessageId(); try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
msgids.put(message, msgid); if (duplicate) {
icopy = new MimeMessageEx(isession, is, msgid); String msgid = EntityMessage.generateMessageId();
icopy.saveChanges(); msgids.put(message, msgid);
icopy = new MimeMessageEx(isession, is, msgid);
if (!copy) { icopy.saveChanges();
List<EntityMessage> tmps = db.message().getMessagesByMsgId(message.account, message.msgid);
for (EntityMessage tmp : tmps) if (!copy) {
if (target.id.equals(tmp.folder)) { List<EntityMessage> tmps = db.message().getMessagesByMsgId(message.account, message.msgid);
db.message().setMessageMsgId(tmp.id, msgid); for (EntityMessage tmp : tmps)
break; if (target.id.equals(tmp.folder)) {
} db.message().setMessageMsgId(tmp.id, msgid);
} break;
} else }
icopy = new MimeMessage(isession, is); }
} else
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