Heuristically fix UTF-8 filenames

master
M66B 15 hours ago
parent 9a24c99f96
commit 32517888df

@ -420,6 +420,19 @@ public class BODYSTRUCTURE implements Item {
", applying Exchange bug workaround"); ", applying Exchange bug workaround");
value = ""; value = "";
} }
try {
if (!r.supportsUtf8() &&
("name".equalsIgnoreCase(name) || "filename".equalsIgnoreCase(name)) &&
!java.nio.charset.StandardCharsets.US_ASCII.newEncoder().canEncode(value)) {
byte[] octets = com.sun.mail.util.ASCIIUtility.getBytes(value);
if (eu.faircode.email.CharsetHelper.isUTF8(octets))
value = new String(octets, java.nio.charset.StandardCharsets.UTF_8);
}
} catch (Throwable ex) {
eu.faircode.email.Log.e(ex);
}
list.set(name, value); list.set(name, value);
} while (!r.isNextNonSpace(')')); } while (!r.isNextNonSpace(')'));
list.combineSegments(); list.combineSegments();

@ -92,7 +92,7 @@ public class CharsetHelper {
} }
} }
static boolean isUTF8(byte[] octets) { public static boolean isUTF8(byte[] octets) {
return isValid(octets, StandardCharsets.UTF_8); return isValid(octets, StandardCharsets.UTF_8);
} }

Loading…
Cancel
Save