diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index fb5ed4568b..909f7ad059 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -117,6 +117,7 @@ import com.google.android.material.snackbar.Snackbar; import org.openintents.openpgp.util.OpenPgpApi; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -2086,6 +2087,22 @@ public class Helper { } } + static class ByteArrayInOutStream extends ByteArrayOutputStream { + public ByteArrayInOutStream() { + super(); + } + + public ByteArrayInOutStream(int size) { + super(size); + } + + public ByteArrayInputStream getInputStream() { + ByteArrayInputStream in = new ByteArrayInputStream(this.buf, 0, this.count); + this.buf = null; + return in; + } + } + // Cryptography static String sha256(String data) throws NoSuchAlgorithmException { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index d959c697f8..3eaa2724ae 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -65,7 +65,6 @@ import org.simplejavamail.outlookmessageparser.model.OutlookFileAttachment; import org.simplejavamail.outlookmessageparser.model.OutlookMessage; import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -141,8 +140,6 @@ public class MessageHelper { private String threadId = null; private InternetHeaders reportHeaders = null; - private static File cacheDir = null; - static final int SMALL_MESSAGE_SIZE = 192 * 1024; // bytes static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes static final String HEADER_CORRELATION_ID = "X-Correlation-ID"; @@ -1172,8 +1169,6 @@ public class MessageHelper { if (cake < Helper.MIN_REQUIRED_SPACE) throw new IOException(context.getString(R.string.app_cake), new ErrnoException(context.getPackageName(), ENOSPC)); - if (cacheDir == null) - cacheDir = context.getCacheDir(); this.imessage = message; } @@ -4243,23 +4238,18 @@ public class MessageHelper { }); Log.w("Fetching raw message"); - File file = File.createTempFile("serverbug", null, cacheDir); - try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { - imessage.writeTo(os); - } + Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream(); + imessage.writeTo(bos); - if (file.length() == 0) + ByteArrayInputStream bis = bos.getInputStream(); + if (bis.available() == 0) throw new IOException("NIL"); Properties props = MessageHelper.getSessionProperties(); Session isession = Session.getInstance(props, null); Log.w("Decoding raw message"); - try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { - imessage = new MimeMessageEx(isession, is, imessage); - } - - file.delete(); + imessage = new MimeMessageEx(isession, bis, imessage); } catch (IOException ex1) { Log.e(ex1); throw ex;