mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 15:11:03 +00:00
Check raw message file size
This commit is contained in:
parent
bbfeec1a79
commit
c05d8faa05
3 changed files with 33 additions and 19 deletions
|
@ -788,19 +788,6 @@ 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();
|
||||
|
@ -813,15 +800,19 @@ class Core {
|
|||
|
||||
// Get raw message
|
||||
MimeMessage imessage;
|
||||
File file = message.getRawFile(context);
|
||||
if (folder.id.equals(message.folder)) {
|
||||
// Pre flight check
|
||||
if (!message.content)
|
||||
throw new IllegalArgumentException("Message body missing");
|
||||
|
||||
imessage = MessageHelper.from(context, message, null, isession, false);
|
||||
|
||||
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
imessage.writeTo(os);
|
||||
}
|
||||
} else {
|
||||
// Cross account move
|
||||
File file = message.getRawFile(context);
|
||||
if (!file.exists())
|
||||
throw new IllegalArgumentException("raw message file not found");
|
||||
|
||||
|
@ -831,6 +822,21 @@ class Core {
|
|||
}
|
||||
}
|
||||
|
||||
db.message().setMessageRaw(message.id, true);
|
||||
|
||||
// Check size
|
||||
if (account.max_size != null) {
|
||||
long size = file.length();
|
||||
if (size > account.max_size) {
|
||||
String msg = "Too large" +
|
||||
" size=" + Helper.humanReadableByteCount(size) +
|
||||
"/" + Helper.humanReadableByteCount(account.max_size) +
|
||||
" host=" + account.host;
|
||||
Log.e(msg);
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle auto read
|
||||
if (flags.contains(Flags.Flag.SEEN)) {
|
||||
if (autoread && !imessage.isSet(Flags.Flag.SEEN)) {
|
||||
|
|
|
@ -173,6 +173,7 @@ import java.util.regex.Pattern;
|
|||
import javax.activation.DataHandler;
|
||||
import javax.mail.Address;
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessageRemovedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
|
@ -4282,10 +4283,18 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
// Check size
|
||||
if (identity != null && identity.max_size != null) {
|
||||
long size = MessageHelper.HEADERS_SIZE + body.length();
|
||||
for (EntityAttachment attachment : attachments)
|
||||
if (attachment.available)
|
||||
size += attachment.size;
|
||||
Properties props = MessageHelper.getSessionProperties();
|
||||
if (identity.unicode)
|
||||
props.put("mail.mime.allowutf8", "true");
|
||||
Session isession = Session.getInstance(props, null);
|
||||
Message imessage = MessageHelper.from(context, draft, identity, isession, true);
|
||||
|
||||
File file = draft.getRawFile(context);
|
||||
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
imessage.writeTo(os);
|
||||
}
|
||||
|
||||
long size = file.length();
|
||||
if (size > identity.max_size) {
|
||||
args.putBoolean("remind_size", true);
|
||||
args.putLong("size", size);
|
||||
|
|
|
@ -109,7 +109,6 @@ 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
|
||||
|
|
Loading…
Reference in a new issue