Recognize diff/patch extension

pull/217/head
M66B 9 months ago
parent ae4e9dc18d
commit 942df1e6b8

@ -32,6 +32,7 @@ import android.os.Build;
import android.provider.CalendarContract; import android.provider.CalendarContract;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.system.ErrnoException; import android.system.ErrnoException;
import android.text.Html;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
@ -3792,12 +3793,19 @@ public class MessageHelper {
class PartHolder { class PartHolder {
Part part; Part part;
ContentType contentType; ContentType contentType;
String filename;
PartHolder(Part part, ContentType contentType) { PartHolder(Part part, ContentType contentType) {
this.part = part; this.part = part;
this.contentType = contentType; this.contentType = contentType;
} }
PartHolder(Part part, ContentType contentType, String filename) {
this.part = part;
this.contentType = contentType;
this.filename = filename;
}
boolean isPlainText() { boolean isPlainText() {
return "text/plain".equalsIgnoreCase(contentType.getBaseType()); return "text/plain".equalsIgnoreCase(contentType.getBaseType());
} }
@ -3811,7 +3819,10 @@ public class MessageHelper {
} }
boolean isPatch() { boolean isPatch() {
return "text/x-diff".equalsIgnoreCase(contentType.getBaseType()) || String ext = Helper.getExtension(filename);
return "diff".equalsIgnoreCase(ext) ||
"patch".equalsIgnoreCase(ext) ||
"text/x-diff".equalsIgnoreCase(contentType.getBaseType()) ||
"text/x-patch".equalsIgnoreCase(contentType.getBaseType()); "text/x-patch".equalsIgnoreCase(contentType.getBaseType());
} }
@ -4239,7 +4250,10 @@ public class MessageHelper {
result = HtmlHelper.formatPlainText(result); result = HtmlHelper.formatPlainText(result);
} }
} else if (h.isPatch()) { } else if (h.isPatch()) {
String filename = h.part.getFileName();
result = (first ? "" : "<br><hr>") + result = (first ? "" : "<br><hr>") +
(TextUtils.isEmpty(filename) ? "" :
"<div style =\"text-align: center;\">" + Html.escapeHtml(filename) + "</div><br>") +
"<pre style=\"font-family: monospace; font-size:small;\">" + "<pre style=\"font-family: monospace; font-size:small;\">" +
HtmlHelper.formatPlainText(result) + HtmlHelper.formatPlainText(result) +
"</pre>"; "</pre>";
@ -5382,10 +5396,13 @@ public class MessageHelper {
filename += ".html"; filename += ".html";
} }
String ext = Helper.getExtension(filename);
if ("text/markdown".equalsIgnoreCase(ct) || if ("text/markdown".equalsIgnoreCase(ct) ||
"text/x-diff".equalsIgnoreCase(ct) || "text/x-diff".equalsIgnoreCase(ct) ||
"text/x-patch".equalsIgnoreCase(ct)) "text/x-patch".equalsIgnoreCase(ct) ||
parts.extra.add(new PartHolder(part, contentType)); "diff".equalsIgnoreCase(ext) ||
"patch".equalsIgnoreCase(ext))
parts.extra.add(new PartHolder(part, contentType, filename));
if (Report.isDeliveryStatus(ct) || if (Report.isDeliveryStatus(ct) ||
Report.isDispositionNotification(ct) || Report.isDispositionNotification(ct) ||

Loading…
Cancel
Save