From 9b15168b0e3c6cae028596b5afc2c05e2ab04478 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 20 Feb 2020 12:44:49 +0100 Subject: [PATCH] Limit messages size to 10 MB --- FAQ.md | 3 +++ app/src/main/java/eu/faircode/email/MessageHelper.java | 5 +++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 9 insertions(+) diff --git a/FAQ.md b/FAQ.md index 920bb9f476..e7f0369119 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2546,6 +2546,9 @@ FairEmail will workaround this is in most cases, so this message can mostly be c The error *...SendFailedException...* means that there was a problem while sending a message. The error will almost always include a reason. Common reasons are that the message was too big or that one or more recipient addresses were invalid. +The warning *Message too large to fit into the available memory* means that the message was larger than 10 MiB. +Even if your device has plenty of storage space Android provides limited working memory to apps, which limits the size of messages that can be handled. + Please see [here](#user-content-faq22) for other error messages in the outbox.
diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 6aa87ec8ae..a9ad995902 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -93,6 +93,7 @@ public class MessageHelper { private MimeMessage imessage; static final int SMALL_MESSAGE_SIZE = 64 * 1024; // bytes + static final int MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // bytes static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes static final long ATTACHMENT_PROGRESS_UPDATE = 1500L; // milliseconds @@ -1250,6 +1251,10 @@ public class MessageHelper { String result; Part part = (html == null ? plain : html); + if (part.getSize() > MAX_MESSAGE_SIZE) { + warnings.add(context.getString(R.string.title_insufficient_memory)); + return null; + } try { Object content = part.getContent(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6109139d4b..df81ae6f7d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -701,6 +701,7 @@ Search on server is not available for this account Message too large to completely reformat Message too large to display completely + Message too large to fit into the available memory Show full message Unused inline images will be removed on send Messages moved across accounts will be downloaded again resulting in extra data usage