mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-22 07:42:52 +00:00
From Punycode
This commit is contained in:
parent
bcb8b943f0
commit
76eb98e3f9
1 changed files with 35 additions and 3 deletions
|
@ -907,7 +907,7 @@ public class MessageHelper {
|
|||
// https://en.wikipedia.org/wiki/International_email
|
||||
for (Address address : addresses) {
|
||||
String email = ((InternetAddress) address).getAddress();
|
||||
email = punyCode(email, false);
|
||||
email = toPunyCode(email, false);
|
||||
((InternetAddress) address).setAddress(email);
|
||||
}
|
||||
return addresses;
|
||||
|
@ -2817,7 +2817,8 @@ public class MessageHelper {
|
|||
|
||||
if (email != null) {
|
||||
email = decodeMime(email);
|
||||
email = punyCode(email, true);
|
||||
email = fromPunyCode(email);
|
||||
email = toPunyCode(email, true);
|
||||
|
||||
iaddress.setAddress(email);
|
||||
}
|
||||
|
@ -3569,7 +3570,37 @@ public class MessageHelper {
|
|||
return TextUtils.join(compose ? ", " : "; ", formatted);
|
||||
}
|
||||
|
||||
static String punyCode(String email, boolean single) {
|
||||
static String fromPunyCode(String email) {
|
||||
try {
|
||||
int at = email.indexOf('@');
|
||||
if (at > 0) {
|
||||
String user = email.substring(0, at);
|
||||
String domain = email.substring(at + 1);
|
||||
|
||||
try {
|
||||
user = IDN.toUnicode(user, IDN.ALLOW_UNASSIGNED);
|
||||
} catch (Throwable ex) {
|
||||
Log.i(ex);
|
||||
}
|
||||
|
||||
String[] parts = domain.split("\\.");
|
||||
for (int p = 0; p < parts.length; p++)
|
||||
try {
|
||||
parts[p] = IDN.toUnicode(parts[p], IDN.ALLOW_UNASSIGNED);
|
||||
} catch (Throwable ex) {
|
||||
Log.i(ex);
|
||||
}
|
||||
|
||||
email = user + '@' + TextUtils.join(".", parts);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.i(ex);
|
||||
}
|
||||
|
||||
return email;
|
||||
}
|
||||
|
||||
static String toPunyCode(String email, boolean single) {
|
||||
int at = email.indexOf('@');
|
||||
if (at > 0) {
|
||||
String user = email.substring(0, at);
|
||||
|
@ -3596,6 +3627,7 @@ public class MessageHelper {
|
|||
|
||||
email = user + '@' + TextUtils.join(".", parts);
|
||||
}
|
||||
|
||||
return email;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue