Simplify plain only handling

pull/194/merge
M66B 3 years ago
parent c56dd9a648
commit 1d414e65a1

@ -2777,10 +2777,16 @@ public class MessageHelper {
Boolean isPlainOnly() { Boolean isPlainOnly() {
if (text.size() + extra.size() == 0) if (text.size() + extra.size() == 0)
return null; return null;
for (PartHolder h : text)
if (!h.isPlainText()) boolean has = false;
for (PartHolder h : text) {
if (h.isHtml())
return false; return false;
return true; if (h.isPlainText())
has = true;
}
return (has ? true : null);
} }
boolean hasBody() throws MessagingException { boolean hasBody() throws MessagingException {
@ -2845,8 +2851,17 @@ public class MessageHelper {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
List<PartHolder> parts = new ArrayList<>(); List<PartHolder> parts = new ArrayList<>();
Boolean plain = isPlainOnly();
if (plain != null && plain)
parts.addAll(text); parts.addAll(text);
else
for (PartHolder h : text)
if (h.isHtml())
parts.add(h);
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)
@ -3722,29 +3737,10 @@ public class MessageHelper {
else else
throw new MessagingStructureException(content); throw new MessagingStructureException(content);
boolean other = false;
List<Part> plain = new ArrayList<>();
int count = multipart.getCount(); int count = multipart.getCount();
boolean alternative = part.isMimeType("multipart/alternative");
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
try { try {
BodyPart child = multipart.getBodyPart(i); BodyPart child = multipart.getBodyPart(i);
if (alternative && count > 1 && child.isMimeType("text/plain"))
plain.add(child);
else {
getMessageParts(part, child, parts, encrypt);
other = true;
}
} catch (ParseException ex) {
// Nested body: try to continue
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
Log.w(ex);
parts.warnings.add(Log.formatThrowable(ex, false));
}
if (alternative && count > 1 && !other)
for (Part child : plain)
try {
getMessageParts(part, child, parts, encrypt); getMessageParts(part, child, parts, encrypt);
} catch (ParseException ex) { } catch (ParseException ex) {
// Nested body: try to continue // Nested body: try to continue

Loading…
Cancel
Save