Fixed subject header decoding

pull/156/head
M66B 6 years ago
parent 7454645ada
commit 9f306c52d5

@ -627,21 +627,31 @@ public class MessageHelper {
subject = MimeUtility.unfold(subject); subject = MimeUtility.unfold(subject);
// Fix UTF-8 if (subject.contains("=?")) {
char[] kars = subject.toCharArray(); // Decode header
byte[] bytes = new byte[kars.length]; try {
for (int i = 0; i < kars.length; i++) subject = MimeUtility.decodeText(subject);
bytes[i] = (byte) kars[i]; } catch (UnsupportedEncodingException ex) {
Log.w(ex);
}
return decodeMime(subject);
} else {
// Fix UTF-8 plain header
char[] kars = subject.toCharArray();
byte[] bytes = new byte[kars.length];
for (int i = 0; i < kars.length; i++)
bytes[i] = (byte) kars[i];
try { try {
CharsetDecoder cs = StandardCharsets.UTF_8.newDecoder(); CharsetDecoder cs = StandardCharsets.UTF_8.newDecoder();
cs.decode(ByteBuffer.wrap(bytes)); cs.decode(ByteBuffer.wrap(bytes));
subject = new String(bytes, StandardCharsets.UTF_8); subject = new String(bytes, StandardCharsets.UTF_8);
} catch (CharacterCodingException ex) { } catch (CharacterCodingException ex) {
Log.w(ex); Log.w(ex);
} }
return decodeMime(subject); return decodeMime(subject);
}
} }
Long getSize() throws MessagingException { Long getSize() throws MessagingException {

Loading…
Cancel
Save