Revert "Small address JSON fixes"

This reverts commit cd6986ac7e.
This commit is contained in:
M66B 2020-05-07 13:14:21 +02:00
parent b45ef948b3
commit a271d66992
2 changed files with 13 additions and 18 deletions

View File

@ -1635,24 +1635,19 @@ public abstract class DB extends RoomDatabase {
@TypeConverter
public static Address[] decodeAddresses(String json) {
try {
if (TextUtils.isEmpty(json))
return null;
else if (json.startsWith("[[")) {
// [[{"address":"...","personal":"..."}],[{... ...}]]
// There is a slim chance somebody uses the split pattern in an email address
String[] parts = json.substring(3, json.length() - 3).split(JSPLIT);
Address[] addresses = new Address[parts.length];
for (int i = 0; i < parts.length; i++)
addresses[i] = InternetAddressJson.from(parts[i]);
return addresses;
} else {
// [{"address":"...","personal":"..."}]
return new Address[]{InternetAddressJson.from(json.substring(2, json.length() - 2))};
}
} catch (Throwable ex) {
Log.e(ex);
if (json == null)
return null;
else if (json.startsWith("[[")) {
// [[{"address":"...","personal":"..."}],[{... ...}]]
// There is a slim chance somebody uses the split pattern in an email address
String[] parts = json.substring(3, json.length() - 3).split(JSPLIT);
Address[] addresses = new Address[parts.length];
for (int i = 0; i < parts.length; i++)
addresses[i] = InternetAddressJson.from(parts[i]);
return addresses;
} else {
// [{"address":"...","personal":"..."}]
return new Address[]{InternetAddressJson.from(json.substring(2, json.length() - 2))};
}
}
}

View File

@ -106,7 +106,7 @@ public class InternetAddressJson extends InternetAddress {
if (this.json != null) {
try {
JSONObject jaddress = new JSONObject("{" + this.json + "}");
String address = jaddress.optString("address");
String address = jaddress.getString("address");
String personal = jaddress.optString("personal");
if (!TextUtils.isEmpty(address))
super.setAddress(address);