Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a55db0f3 authored by Vincent Breitmoser's avatar Vincent Breitmoser Committed by Vincent Breitmoser
Browse files

messageview: start parsing input only if it's not immediate EOF or EPIPE

parent 04e17564
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -40,6 +40,13 @@ public class DecryptStreamParser {
    private static final String DECRYPTED_CACHE_DIRECTORY = "decrypted";

    public static MimeBodyPart parse(Context context, InputStream inputStream) throws MessagingException, IOException {
        inputStream = new BufferedInputStream(inputStream, 4096);

        boolean hasInputData = waitForInputData(inputStream);
        if (!hasInputData) {
            return null;
        }

        File decryptedTempDirectory = getDecryptedTempDirectory(context);

        MimeBodyPart decryptedRootPart = new MimeBodyPart();
@@ -53,8 +60,6 @@ public class DecryptStreamParser {
        parser.setContentHandler(new PartBuilder(decryptedTempDirectory, decryptedRootPart));
        parser.setRecurse();

        inputStream = new BufferedInputStream(inputStream, 4096);

        try {
            parser.parse(new EOLConvertingInputStream(inputStream));
        } catch (MimeException e) {
@@ -64,6 +69,18 @@ public class DecryptStreamParser {
        return decryptedRootPart;
    }

    private static boolean waitForInputData(InputStream inputStream) {
        try {
            inputStream.mark(1);
            int ret = inputStream.read();
            inputStream.reset();
            return ret != -1;
        } catch (IOException e) {
            Log.d(K9.LOG_TAG, "got no input from pipe", e);
            return false;
        }
    }

    private static Body createBody(InputStream inputStream, String transferEncoding, File decryptedTempDirectory)
            throws IOException {
        DecryptedTempFileBody body = new DecryptedTempFileBody(decryptedTempDirectory, transferEncoding);