Check append limit

This commit is contained in:
M66B 2020-07-03 10:04:09 +02:00
parent d12e7a1d92
commit f4ef463cbd
4 changed files with 19 additions and 4 deletions

View File

@ -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<EntityAttachment> 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();

View File

@ -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

View File

@ -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;

View File

@ -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