Conditionally convert address header/subject charset

This commit is contained in:
M66B
2020-02-05 12:54:11 +01:00
parent 9df6a659d3
commit 9c9cadfbd6
2 changed files with 40 additions and 2 deletions

View File

@@ -854,7 +854,10 @@ public class MessageHelper {
if (header == null)
return null;
header = new String(header.getBytes(StandardCharsets.ISO_8859_1));
if (!Helper.isUTF8(header)) {
Log.w("Converting header '" + name + "' to ISO8859-1");
header = new String(header.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.ISO_8859_1);
}
Address[] addresses = InternetAddress.parseHeader(header, false);
for (Address address : addresses) {
@@ -995,7 +998,10 @@ public class MessageHelper {
if (subject == null)
return null;
subject = new String(subject.getBytes(StandardCharsets.ISO_8859_1));
if (!Helper.isUTF8(subject)) {
Log.w("Converting subject to ISO8859-1");
subject = new String(subject.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.ISO_8859_1);
}
subject = subject.replaceAll("\\?=\\r?\\n\\s+=\\?", "\\?==\\?");
subject = MimeUtility.unfold(subject);
subject = decodeMime(subject);