diff --git a/FAQ.md b/FAQ.md index 529f09b751..848c496e4c 100644 --- a/FAQ.md +++ b/FAQ.md @@ -51,7 +51,7 @@ Related questions: * A bug in Nova Launcher on Android 5.x lets FairEmail crash with a *java.lang.StackOverflowError* when Nova Launcher has access to the accessibility service. * The folder selector sometimes shows no folders for yet unknown reasons. * A [bug in AndroidX](https://issuetracker.google.com/issues/64729576) makes it hard to grap the fast scroller. -* Encryption with YubiKey results into an infinite loop. This seems to be caused by a [bug in OpenKeychain](https://github.com/open-keychain/open-keychain/issues/2507). +* ~~Encryption with YubiKey results into an infinite loop. This seems to be caused by a [bug in OpenKeychain](https://github.com/open-keychain/open-keychain/issues/2507).~~ * Scrolling to an internal linked location in original messages does not work. This can't be fixed because the original message view is contained in a scrolling view. * A preview of the message text doesn't (always) appear on a Samsung watch because [setLocalOnly](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder.html#setLocalOnly(boolean)) seem to be ignored. However, message preview texts are known to appear correctly on a Pebble 2, a Fitbit Charge 3 and a Mi band 3. See also [this FAQ](#user-content-faq126). diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 86764e3f33..7805df07bc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1557,30 +1557,28 @@ public class FragmentCompose extends FragmentBase { } // 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); - - // Serialize message - try (OutputStream out = new FileOutputStream(plain)) { - imessage.writeTo(out); + File plain = new File(context.getCacheDir(), "plain." + id); + File encrypted = new File(context.getCacheDir(), "encrypted." + id); + + // Serializing messages is NOT reproducible + if (OpenPgpApi.ACTION_GET_KEY_IDS.equals(data.getAction())) { + // Build message + Properties props = MessageHelper.getSessionProperties(); + Session isession = Session.getInstance(props, null); + MimeMessage imessage = new MimeMessage(isession); + MessageHelper.build(context, message, attachments, identity, imessage); + + // Serialize message + try (OutputStream out = new FileOutputStream(plain)) { + imessage.writeTo(out); + } } // Call OpenPGP - Intent result; - 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(); - } + Log.i("Executing " + data.getAction()); + Log.logExtras(data); + OpenPgpApi api = new OpenPgpApi(context, pgpService.getService()); + Intent result = api.executeApi(data, new FileInputStream(plain), new FileOutputStream(encrypted)); // Process result try { @@ -1686,6 +1684,8 @@ public class FragmentCompose extends FragmentBase { intent.putExtra(BuildConfig.APPLICATION_ID, id); return intent; } else if (OpenPgpApi.ACTION_SIGN_AND_ENCRYPT.equals(data.getAction())) { + plain.delete(); + // Get signature Intent intent = new Intent(OpenPgpApi.ACTION_DETACHED_SIGN); intent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, pgpSignKeyId); @@ -1700,6 +1700,7 @@ public class FragmentCompose extends FragmentBase { return (PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT); case OpenPgpApi.RESULT_CODE_ERROR: + plain.delete(); db.identity().setIdentitySignKey(identity.id, null); OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); throw new IllegalArgumentException(