mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 15:32:52 +00:00
Refactoring
This commit is contained in:
parent
d5eca31bc3
commit
d0d4d15899
1 changed files with 20 additions and 16 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue