Refactoring

This commit is contained in:
M66B 2019-06-04 18:35:51 +02:00
parent d5eca31bc3
commit d0d4d15899
1 changed files with 20 additions and 16 deletions

View File

@ -663,22 +663,8 @@ public class MessageHelper {
} catch (UnsupportedEncodingException ex) {
Log.w(ex);
}
} else {
// Fix UTF-8 plain header
try {
char[] kars = subject.toCharArray();
byte[] bytes = new byte[kars.length];
for (int i = 0; i < kars.length; i++)
bytes[i] = (byte) kars[i];
CharsetDecoder cs = StandardCharsets.UTF_8.newDecoder();
CharBuffer out = cs.decode(ByteBuffer.wrap(bytes));
if (out.length() > 0)
subject = new String(bytes, StandardCharsets.UTF_8);
} catch (CharacterCodingException ex) {
Log.w(ex);
}
}
} else
subject = fixUTF8(subject);
return decodeMime(subject);
}
@ -798,6 +784,24 @@ public class MessageHelper {
return text;
}
static String fixUTF8(String text) {
try {
char[] kars = text.toCharArray();
byte[] bytes = new byte[kars.length];
for (int i = 0; i < kars.length; i++)
bytes[i] = (byte) kars[i];
CharsetDecoder cs = StandardCharsets.UTF_8.newDecoder();
CharBuffer out = cs.decode(ByteBuffer.wrap(bytes));
if (out.length() > 0)
return new String(bytes, StandardCharsets.UTF_8);
} catch (CharacterCodingException ex) {
Log.w(ex);
}
return text;
}
static String getSortKey(Address[] addresses) {
if (addresses == null || addresses.length == 0)
return null;