Refactoring

pull/156/head
M66B 6 years ago
parent 121c89abbd
commit 09ace5e05a

@ -804,9 +804,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
try { try {
via = new InternetAddress(message.identityEmail, message.identityName); via = new InternetAddress(message.identityEmail, message.identityName);
if (message.to != null) { if (message.to != null) {
String v = Helper.canonicalAddress(via.getAddress()); String v = MessageHelper.canonicalAddress(via.getAddress());
for (Address t : message.to) { for (Address t : message.to) {
if (v.equals(Helper.canonicalAddress(((InternetAddress) t).getAddress()))) { if (v.equals(MessageHelper.canonicalAddress(((InternetAddress) t).getAddress()))) {
self = true; self = true;
break; break;
} }
@ -1197,7 +1197,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
else { else {
String from = ((InternetAddress) message.from[0]).getAddress(); String from = ((InternetAddress) message.from[0]).getAddress();
EntityIdentity identity = db.identity().getIdentity(message.identity); EntityIdentity identity = db.identity().getIdentity(message.identity);
outgoing = Helper.canonicalAddress(identity.email).equals(Helper.canonicalAddress(from)); outgoing = MessageHelper.canonicalAddress(identity.email)
.equals(MessageHelper.canonicalAddress(from));
} }
return (outgoing return (outgoing

@ -1268,7 +1268,7 @@ class Core {
if (!TextUtils.isEmpty(email)) { if (!TextUtils.isEmpty(email)) {
identity = db.identity().getIdentity(folder.account, email); identity = db.identity().getIdentity(folder.account, email);
if (identity == null) { if (identity == null) {
String canonical = Helper.canonicalAddress(email); String canonical = MessageHelper.canonicalAddress(email);
if (!canonical.equals(email)) if (!canonical.equals(email))
identity = db.identity().getIdentity(folder.account, canonical); identity = db.identity().getIdentity(folder.account, canonical);
} }
@ -1496,7 +1496,7 @@ class Core {
boolean me = true; boolean me = true;
for (Address reply : recipients) { for (Address reply : recipients) {
String email = ((InternetAddress) reply).getAddress(); String email = ((InternetAddress) reply).getAddress();
String canonical = Helper.canonicalAddress(email); String canonical = MessageHelper.canonicalAddress(email);
if (!TextUtils.isEmpty(email) && if (!TextUtils.isEmpty(email) &&
db.identity().getIdentity(folder.account, email) == null && db.identity().getIdentity(folder.account, email) == null &&
(canonical.equals(email) || (canonical.equals(email) ||

@ -2035,10 +2035,10 @@ public class FragmentCompose extends FragmentBase {
String via = null; String via = null;
Address[] recipient = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply); Address[] recipient = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
if (recipient != null && recipient.length > 0) if (recipient != null && recipient.length > 0)
to = Helper.canonicalAddress(((InternetAddress) recipient[0]).getAddress()); to = MessageHelper.canonicalAddress(((InternetAddress) recipient[0]).getAddress());
if (ref.identity != null) { if (ref.identity != null) {
EntityIdentity v = db.identity().getIdentity(ref.identity); EntityIdentity v = db.identity().getIdentity(ref.identity);
via = Helper.canonicalAddress(v.email); via = MessageHelper.canonicalAddress(v.email);
} }
if (to != null && to.equals(via)) { if (to != null && to.equals(via)) {
@ -2058,10 +2058,10 @@ public class FragmentCompose extends FragmentBase {
if (ref.cc != null) if (ref.cc != null)
addresses.addAll(Arrays.asList(ref.cc)); addresses.addAll(Arrays.asList(ref.cc));
for (Address address : new ArrayList<>(addresses)) { for (Address address : new ArrayList<>(addresses)) {
String cc = Helper.canonicalAddress(((InternetAddress) address).getAddress()); String cc = MessageHelper.canonicalAddress(((InternetAddress) address).getAddress());
List<TupleIdentityEx> identities = db.identity().getComposableIdentities(ref.account); List<TupleIdentityEx> identities = db.identity().getComposableIdentities(ref.account);
for (EntityIdentity identity : identities) { for (EntityIdentity identity : identities) {
String email = Helper.canonicalAddress(identity.email); String email = MessageHelper.canonicalAddress(identity.email);
if (cc.equals(email)) if (cc.equals(email))
addresses.remove(address); addresses.remove(address);
} }
@ -2120,9 +2120,9 @@ public class FragmentCompose extends FragmentBase {
do { do {
String from = null; String from = null;
if (iindex >= 0) if (iindex >= 0)
from = Helper.canonicalAddress(((InternetAddress) draft.from[iindex]).getAddress()); from = MessageHelper.canonicalAddress(((InternetAddress) draft.from[iindex]).getAddress());
for (EntityIdentity identity : identities) { for (EntityIdentity identity : identities) {
String email = Helper.canonicalAddress(identity.email); String email = MessageHelper.canonicalAddress(identity.email);
if (email.equals(from)) { if (email.equals(from)) {
draft.identity = identity.id; draft.identity = identity.id;
draft.from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)}; draft.from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)};

@ -787,16 +787,6 @@ public class Helper {
return new InternetAddress("marcel+fairemail@faircode.eu", "FairCode"); return new InternetAddress("marcel+fairemail@faircode.eu", "FairCode");
} }
static String canonicalAddress(String address) {
String[] a = address.split("@");
if (a.length > 0) {
String[] extra = a[0].split("\\+");
if (extra.length > 0)
a[0] = extra[0];
}
return TextUtils.join("@", a).toLowerCase();
}
static void writeText(File file, String content) throws IOException { static void writeText(File file, String content) throws IOException {
try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) { try (BufferedWriter out = new BufferedWriter(new FileWriter(file))) {
out.write(content == null ? "" : content); out.write(content == null ? "" : content);

@ -731,6 +731,16 @@ public class MessageHelper {
return TextUtils.join(", ", formatted); return TextUtils.join(", ", formatted);
} }
static String canonicalAddress(String address) {
String[] a = address.split("@");
if (a.length > 0) {
String[] extra = a[0].split("\\+");
if (extra.length > 0)
a[0] = extra[0];
}
return TextUtils.join("@", a).toLowerCase();
}
static String decodeMime(String text) { static String decodeMime(String text) {
if (text == null) if (text == null)
return null; return null;

Loading…
Cancel
Save