diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index 2b2ec686d5..2b30addf7a 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -26,7 +26,6 @@ import org.json.JSONObject; import java.io.File; import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -1635,25 +1634,17 @@ public abstract class DB extends RoomDatabase { public static Address[] decodeAddresses(String json) { if (json == null) return null; + List
result = new ArrayList<>(); try { JSONArray jroot = new JSONArray(json); - JSONArray jaddresses = new JSONArray(); for (int i = 0; i < jroot.length(); i++) { Object item = jroot.get(i); if (jroot.get(i) instanceof JSONArray) for (int j = 0; j < ((JSONArray) item).length(); j++) - jaddresses.put(((JSONArray) item).get(j)); + result.add(InternetAddressJson.from((JSONObject) ((JSONArray) item).get(j))); else - jaddresses.put(item); - } - for (int i = 0; i < jaddresses.length(); i++) { - JSONObject jaddress = (JSONObject) jaddresses.get(i); - String email = jaddress.getString("address"); - String personal = jaddress.optString("personal"); - if (TextUtils.isEmpty(personal)) - personal = null; - result.add(new InternetAddress(email, personal, StandardCharsets.UTF_8.name())); + result.add(InternetAddressJson.from((JSONObject) item)); } } catch (Throwable ex) { // Compose can store invalid addresses diff --git a/app/src/main/java/eu/faircode/email/InternetAddressJson.java b/app/src/main/java/eu/faircode/email/InternetAddressJson.java new file mode 100644 index 0000000000..d1f65e629c --- /dev/null +++ b/app/src/main/java/eu/faircode/email/InternetAddressJson.java @@ -0,0 +1,116 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see