diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 52e7bc3fc3..39d38e7c27 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1550,16 +1550,16 @@ public class FragmentCompose extends FragmentBase { attachments.remove(attachment); } + // Create temporary files + File plain = File.createTempFile("plain", "." + id, context.getCacheDir()); + File encrypted = File.createTempFile("encrypted", "." + id, context.getCacheDir()); + // Build message Properties props = MessageHelper.getSessionProperties(); Session isession = Session.getInstance(props, null); MimeMessage imessage = new MimeMessage(isession); MessageHelper.build(context, message, attachments, identity, imessage); - // Create temporary files - File plain = File.createTempFile("plain", "." + id, context.getCacheDir()); - File encrypted = File.createTempFile("encrypted", "." + id, context.getCacheDir()); - // Serialize message try (OutputStream out = new FileOutputStream(plain)) { imessage.writeTo(out); @@ -1567,16 +1567,15 @@ public class FragmentCompose extends FragmentBase { // Call OpenPGP Intent result; - try (InputStream in = new FileInputStream(plain)) { - try (OutputStream out = new FileOutputStream(encrypted)) { - Log.i("Executing " + data.getAction()); - OpenPgpApi api = new OpenPgpApi(context, pgpService.getService()); - result = api.executeApi(data, in, out); - } + try { + Log.i("Executing " + data.getAction()); + Log.logExtras(data); + OpenPgpApi api = new OpenPgpApi(context, pgpService.getService()); + result = api.executeApi(data, new FileInputStream(plain), new FileOutputStream(encrypted)); + } finally { + plain.delete(); } - plain.delete(); - // Process result try { int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index b25e030f34..5b58800180 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3888,14 +3888,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. File plain = File.createTempFile("plain", "." + id, context.getCacheDir()); try { // Decrypt message - try { - try (OutputStream out = new FileOutputStream(plain)) { - OpenPgpApi api = new OpenPgpApi(context, pgpService.getService()); - result = api.executeApi(data, in, out); - } - } finally { - in.close(); - } + Log.i("Executing " + data.getAction()); + Log.logExtras(data); + OpenPgpApi api = new OpenPgpApi(context, pgpService.getService()); + result = api.executeApi(data, in, new FileOutputStream(plain)); Log.i("PGP result=" + result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)); switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {