mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-01 03:45:10 +00:00
Added markdown text support
This commit is contained in:
parent
0e5a67fe9f
commit
395aed2a98
1 changed files with 19 additions and 0 deletions
|
@ -69,6 +69,8 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
|||
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
|
||||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
@ -3497,6 +3499,10 @@ public class MessageHelper {
|
|||
return "text/html".equalsIgnoreCase(contentType.getBaseType());
|
||||
}
|
||||
|
||||
boolean isMarkdown() {
|
||||
return "text/markdown".equalsIgnoreCase(contentType.getBaseType());
|
||||
}
|
||||
|
||||
boolean isReport() {
|
||||
String ct = contentType.getBaseType();
|
||||
return (Report.isDeliveryStatus(ct) ||
|
||||
|
@ -3903,6 +3909,16 @@ public class MessageHelper {
|
|||
Helper.copy(h.part.getDataHandler().getInputStream(), bos);
|
||||
result = bos.toString(override);
|
||||
}
|
||||
} else if (h.isMarkdown()) {
|
||||
try {
|
||||
Parser p = Parser.builder().build();
|
||||
org.commonmark.node.Node d = p.parse(result);
|
||||
HtmlRenderer r = HtmlRenderer.builder().build();
|
||||
return r.render(d);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return HtmlHelper.formatPlainText(Log.formatThrowable(ex));
|
||||
}
|
||||
} else if (h.isReport()) {
|
||||
Report report = new Report(h.contentType.getBaseType(), result);
|
||||
result = report.html;
|
||||
|
@ -5028,6 +5044,9 @@ public class MessageHelper {
|
|||
filename += ".html";
|
||||
}
|
||||
|
||||
if ("text/markdown".equalsIgnoreCase(ct))
|
||||
parts.extra.add(new PartHolder(part, contentType));
|
||||
|
||||
if (Report.isDeliveryStatus(ct) ||
|
||||
Report.isDispositionNotification(ct) ||
|
||||
Report.isFeedbackReport(ct))
|
||||
|
|
Loading…
Reference in a new issue