Guess UTF-16 LE without BOM

This commit is contained in:
M66B
2022-06-10 22:05:42 +02:00
parent 77a1e96736
commit 7beab967d4
2 changed files with 44 additions and 1 deletions

View File

@@ -3112,7 +3112,21 @@ public class MessageHelper {
String result;
try {
Object content = h.part.getContent();
Object content;
// Check for UTF-16 LE without BOM
String pcharset = h.contentType.getParameter("charset");
if ("utf-16".equalsIgnoreCase(pcharset) && override == null) {
String charset = pcharset;
BufferedInputStream bis = new BufferedInputStream(h.part.getDataHandler().getInputStream());
if (Boolean.TRUE.equals(CharsetHelper.isUTF16LE(bis))) {
charset = StandardCharsets.UTF_16LE.name();
Log.e("Charset " + pcharset + " -> " + charset);
}
content = Helper.readStream(bis, Charset.forName(charset));
} else
content = h.part.getContent();
Log.i("Content class=" + (content == null ? null : content.getClass().getName()));
if (content == null) {