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

Commit 5678786c authored by cketti's avatar cketti
Browse files

Properly closing InputStreams to avoid StrictMode warnings

parent 9c335127
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -45,13 +45,16 @@ public class BinaryTempFileBody implements Body {

    public void writeTo(OutputStream out) throws IOException, MessagingException {
        InputStream in = getInputStream();
        try {
            Base64OutputStream base64Out = new Base64OutputStream(out);
            try {
                IOUtils.copy(in, base64Out);
            } finally {
                base64Out.close();
            }
        mFile.delete();
        } finally {
            in.close();
        }
    }

    class BinaryTempFileBodyInputStream extends FilterInputStream {
@@ -61,8 +64,11 @@ public class BinaryTempFileBody implements Body {

        @Override
        public void close() throws IOException {
            try {
                super.close();
            } finally {
                mFile.delete();
            }
        }
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -1061,7 +1061,18 @@ public class MimeUtility {
                     * the stream is now wrapped we'll remove any transfer encoding at this point.
                     */
                    InputStream in = part.getBody().getInputStream();
                    return readToString(in, charset);
                    try {
                        String text = readToString(in, charset);

                        // Replace the body with a TextBody that already contains the decoded text
                        part.setBody(new TextBody(text));

                        return text;
                    } finally {
                        try {
                            in.close();
                        } catch (IOException e) { /* Ignore */ }
                    }
                }
            }