mirror of https://github.com/M66B/FairEmail.git
Fixed html charset edge case
This commit is contained in:
parent
fe22ed2a8b
commit
63114d05f0
|
@ -146,10 +146,7 @@ public class text_plain extends handler_base {
|
||||||
String charset = ct.getParameter("charset");
|
String charset = ct.getParameter("charset");
|
||||||
if (charset == null)
|
if (charset == null)
|
||||||
// If the charset parameter is absent, use US-ASCII.
|
// If the charset parameter is absent, use US-ASCII.
|
||||||
charset = "us-ascii";
|
charset = StandardCharsets.ISO_8859_1.name();
|
||||||
if ("us-ascii".equals(charset) &&
|
|
||||||
"text/html".equalsIgnoreCase(ct.getBaseType()))
|
|
||||||
charset = StandardCharsets.UTF_8.name();
|
|
||||||
return MimeUtility.javaCharset(charset);
|
return MimeUtility.javaCharset(charset);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1907,8 +1907,11 @@ public class MessageHelper {
|
||||||
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.isHtml()) {
|
} else if (h.isHtml()) {
|
||||||
|
if (charset == null) {
|
||||||
|
if (CharsetHelper.isUTF8(result))
|
||||||
|
result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
// Fix incorrect UTF16
|
// Fix incorrect UTF16
|
||||||
if (charset != null)
|
|
||||||
try {
|
try {
|
||||||
Charset c = Charset.forName(charset);
|
Charset c = Charset.forName(charset);
|
||||||
if (CHARSET16.contains(c)) {
|
if (CHARSET16.contains(c)) {
|
||||||
|
@ -1924,6 +1927,7 @@ public class MessageHelper {
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (charset == null) {
|
if (charset == null) {
|
||||||
// <meta charset="utf-8" />
|
// <meta charset="utf-8" />
|
||||||
|
|
Loading…
Reference in New Issue