Convert large bodies to attachments

pull/212/head
M66B 2 years ago
parent 190f3b2293
commit aadd95595f

@ -3310,6 +3310,7 @@ public class MessageHelper {
parts.addAll(extra); parts.addAll(extra);
for (PartHolder h : parts) { for (PartHolder h : parts) {
/*
int size = h.part.getSize(); int size = h.part.getSize();
if (size > 100 * 1024 * 1024) if (size > 100 * 1024 * 1024)
Log.e("Unreasonable message size=" + size); Log.e("Unreasonable message size=" + size);
@ -3317,6 +3318,7 @@ public class MessageHelper {
warnings.add(context.getString(R.string.title_insufficient_memory, size)); warnings.add(context.getString(R.string.title_insufficient_memory, size));
return null; return null;
} }
*/
if (Boolean.parseBoolean(System.getProperty("fairemail.preamble"))) { if (Boolean.parseBoolean(System.getProperty("fairemail.preamble"))) {
String preamble = h.contentType.getParameter("preamble"); String preamble = h.contentType.getParameter("preamble");
@ -4657,6 +4659,13 @@ public class MessageHelper {
filename = null; filename = null;
} }
int size = Integer.MAX_VALUE;
try {
size = part.getSize();
} catch (MessagingException ex) {
Log.w(ex);
}
ContentType contentType; ContentType contentType;
try { try {
// From the body structure // From the body structure
@ -4671,7 +4680,8 @@ public class MessageHelper {
String ct = contentType.getBaseType(); String ct = contentType.getBaseType();
if (("text/plain".equalsIgnoreCase(ct) || "text/html".equalsIgnoreCase(ct)) && if (("text/plain".equalsIgnoreCase(ct) || "text/html".equalsIgnoreCase(ct)) &&
!Part.ATTACHMENT.equalsIgnoreCase(disposition) && TextUtils.isEmpty(filename)) { !Part.ATTACHMENT.equalsIgnoreCase(disposition) && TextUtils.isEmpty(filename) &&
(size <= MAX_MESSAGE_SIZE || size == Integer.MAX_VALUE)) {
parts.text.add(new PartHolder(part, contentType)); parts.text.add(new PartHolder(part, contentType));
} else { } else {
// Workaround for NIL message content type // Workaround for NIL message content type
@ -4682,6 +4692,16 @@ public class MessageHelper {
parts.text.add(new PartHolder(part, plain)); parts.text.add(new PartHolder(part, plain));
} }
if (("text/plain".equalsIgnoreCase(ct) || "text/html".equalsIgnoreCase(ct)) &&
TextUtils.isEmpty(Helper.getExtension(filename))) {
if (TextUtils.isEmpty(filename))
filename = "body";
if ("text/plain".equalsIgnoreCase(ct))
filename += ".txt";
if ("text/html".equalsIgnoreCase(ct))
filename += ".html";
}
if (Report.isDeliveryStatus(ct) || if (Report.isDeliveryStatus(ct) ||
Report.isDispositionNotification(ct) || Report.isDispositionNotification(ct) ||
Report.isFeedbackReport(ct)) Report.isFeedbackReport(ct))

Loading…
Cancel
Save