diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 54d977ebf6..30a51765bd 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -331,7 +331,7 @@ class Core { break; case EntityOperation.ADD: - onAdd(context, jargs, folder, message, (IMAPStore) istore, (IMAPFolder) ifolder, state); + onAdd(context, jargs, account, folder, message, (IMAPStore) istore, (IMAPFolder) ifolder, state); break; case EntityOperation.MOVE: @@ -773,7 +773,7 @@ class Core { } } - private static void onAdd(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException { + private static void onAdd(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException { // Add message DB db = DB.getInstance(context); @@ -788,6 +788,19 @@ class Core { if (target != folder.id) throw new IllegalArgumentException("Invalid folder"); + // Check size + if (account.max_size != null && BuildConfig.DEBUG) { + long size = MessageHelper.HEADERS_SIZE; + if (message.content) + size += message.getFile(context).length(); + List attachments = db.attachment().getAttachments(message.id); + for (EntityAttachment attachment : attachments) + if (attachment.available) + size += attachment.size; + if (size > account.max_size) + throw new IllegalArgumentException("Message too large"); + } + // External draft might have a uid only if (TextUtils.isEmpty(message.msgid)) { message.msgid = EntityMessage.generateMessageId(); diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index 9a10bfe12a..5a4ab7d427 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -635,6 +635,8 @@ public class EmailService implements AutoCloseable { } Long getMaxSize() throws MessagingException { + // https://support.google.com/mail/answer/6584#limit + String size; if (iservice instanceof SMTPTransport) { // https://tools.ietf.org/html/rfc1870 diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 80bcbfada0..716e8b86e5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -264,7 +264,6 @@ public class FragmentCompose extends FragmentBase { private static final int REDUCED_IMAGE_QUALITY = 90; // percent private static final int RECIPIENTS_WARNING = 10; - private static final int HEADERS_SIZE = 32 * 1024; // bytes private static final int REQUEST_CONTACT_TO = 1; private static final int REQUEST_CONTACT_CC = 2; @@ -4283,7 +4282,7 @@ public class FragmentCompose extends FragmentBase { // Check size if (identity != null && identity.max_size != null) { - long size = HEADERS_SIZE + body.length(); + long size = MessageHelper.HEADERS_SIZE + body.length(); for (EntityAttachment attachment : attachments) if (attachment.available) size += attachment.size; diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 68ddfa4130..c56ac68491 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -109,6 +109,7 @@ public class MessageHelper { static final int SMALL_MESSAGE_SIZE = 64 * 1024; // bytes static final int DEFAULT_ATTACHMENT_DOWNLOAD_SIZE = 256 * 1024; // bytes + static final int HEADERS_SIZE = 32 * 1024; // bytes static final String HEADER_CORRELATION_ID = "X-Correlation-ID"; private static final int MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // bytes