From d3805dc80ba62287eb905b7008b5545d8396ed5c Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 20 Feb 2021 08:46:23 +0100 Subject: [PATCH] Use temporary folder for encryption --- .../java/eu/faircode/email/FragmentCompose.java | 15 +++++++++++---- .../java/eu/faircode/email/WorkerCleanup.java | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index bb172cb203..5c382d027c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2320,8 +2320,11 @@ public class FragmentCompose extends FragmentBase { throw new IllegalArgumentException(context.getString(R.string.title_from_missing)); // Create files - File input = new File(context.getCacheDir(), "pgp_input." + draft.id); - File output = new File(context.getCacheDir(), "pgp_output." + draft.id); + File tmp = new File(context.getFilesDir(), "encryption"); + if (!tmp.exists()) + tmp.mkdir(); + File input = new File(tmp, draft.id + ".pgp_input"); + File output = new File(tmp, draft.id + ".pgp_output"); // Serializing messages is NOT reproducible if ((EntityMessage.PGP_SIGNONLY.equals(draft.ui_encrypt) && @@ -2652,6 +2655,10 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean check_certificate = prefs.getBoolean("check_certificate", true); + File tmp = new File(context.getFilesDir(), "encryption"); + if (!tmp.exists()) + tmp.mkdir(); + DB db = DB.getInstance(context); // Get data @@ -2777,7 +2784,7 @@ public class FragmentCompose extends FragmentBase { .build(contentSigner, chain[0]); cmsGenerator.addSignerInfoGenerator(signerInfoGenerator); - File sinput = new File(context.getCacheDir(), "smime_sign." + draft.id); + File sinput = new File(tmp, draft.id + ".smime_sign"); try (FileOutputStream fos = new FileOutputStream(sinput)) { bpContent.writeTo(fos); } @@ -2895,7 +2902,7 @@ public class FragmentCompose extends FragmentBase { } } - File einput = new File(context.getCacheDir(), "smime_encrypt." + draft.id); + File einput = new File(tmp, draft.id + ".smime_encrypt"); try (FileOutputStream fos = new FileOutputStream(einput)) { imessage.writeTo(fos); } diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 8c9df5d60d..bb6eb6f07c 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -191,6 +191,7 @@ public class WorkerCleanup extends Worker { File[] messages = new File(context.getFilesDir(), "messages").listFiles(); File[] revision = new File(context.getFilesDir(), "revision").listFiles(); File[] references = new File(context.getFilesDir(), "references").listFiles(); + File[] encryption = new File(context.getFilesDir(), "encryption").listFiles(); File[] photos = new File(context.getCacheDir(), "photo").listFiles(); File[] calendars = new File(context.getCacheDir(), "calendar").listFiles(); @@ -200,6 +201,8 @@ public class WorkerCleanup extends Worker { files.addAll(Arrays.asList(revision)); if (references != null) files.addAll(Arrays.asList(references)); + if (encryption != null) + files.addAll(Arrays.asList(encryption)); if (photos != null) files.addAll(Arrays.asList(photos)); if (calendars != null)