Small improvement

pull/191/head
M66B 4 years ago
parent f918a63729
commit 828c3995c9

@ -1645,6 +1645,15 @@ public class MessageHelper {
boolean isPlainText() { boolean isPlainText() {
return "text/plain".equalsIgnoreCase(contentType.getBaseType()); return "text/plain".equalsIgnoreCase(contentType.getBaseType());
} }
boolean isHtml() {
return "text/html".equalsIgnoreCase(contentType.getBaseType());
}
boolean isDSN() {
return ("message/delivery-status".equalsIgnoreCase(contentType.getBaseType()) ||
"message/disposition-notification".equalsIgnoreCase(contentType.getBaseType()));
}
} }
class MessageParts { class MessageParts {
@ -1758,7 +1767,7 @@ public class MessageHelper {
if ((TextUtils.isEmpty(charset) || charset.equalsIgnoreCase(StandardCharsets.US_ASCII.name()))) if ((TextUtils.isEmpty(charset) || charset.equalsIgnoreCase(StandardCharsets.US_ASCII.name())))
charset = null; charset = null;
if (h.contentType.getBaseType().equalsIgnoreCase("text/plain")) { if (h.isPlainText()) {
Charset cs = null; Charset cs = null;
try { try {
if (charset != null) if (charset != null)
@ -1788,7 +1797,7 @@ public class MessageHelper {
if ("flowed".equalsIgnoreCase(h.contentType.getParameter("format"))) if ("flowed".equalsIgnoreCase(h.contentType.getParameter("format")))
result = HtmlHelper.flow(result); result = HtmlHelper.flow(result);
result = "<div x-plain=\"true\">" + HtmlHelper.formatPre(result) + "</div>"; result = "<div x-plain=\"true\">" + HtmlHelper.formatPre(result) + "</div>";
} else if (h.contentType.getBaseType().equalsIgnoreCase("text/html")) { } else if (h.isHtml()) {
// Fix incorrect UTF16 // Fix incorrect UTF16
if (charset != null) if (charset != null)
try { try {
@ -1860,8 +1869,7 @@ public class MessageHelper {
} }
} }
} }
} else if (h.contentType.getBaseType().equalsIgnoreCase("message/delivery-status") || } else if (h.isDSN()) {
h.contentType.getBaseType().equalsIgnoreCase("message/disposition-notification")) {
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append("<hr><div style=\"font-family: monospace; font-size: small;\">"); report.append("<hr><div style=\"font-family: monospace; font-size: small;\">");
for (String line : result.split("\\r?\\n")) { for (String line : result.split("\\r?\\n")) {
@ -1883,7 +1891,8 @@ public class MessageHelper {
} }
report.append("</div>"); report.append("</div>");
result = report.toString(); result = report.toString();
} } else
Log.w("Unexpected content type=" + h.contentType);
sb.append(result); sb.append(result);
} }

Loading…
Cancel
Save