Refactoring

This commit is contained in:
M66B 2019-09-02 08:30:13 +02:00
parent 4d5794a51b
commit 03f97c7e3b
3 changed files with 17 additions and 9 deletions

View File

@ -22,6 +22,7 @@ import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
@ -316,4 +317,19 @@ public class ConnectionHelper {
return ok;
}
static boolean isSameDomain(String host1, String host2) {
String domain1 = getDomain(host1);
String domain2 = getDomain(host2);
return Objects.equals(domain1, domain2);
}
private static String getDomain(String host) {
if (host != null) {
String[] h = host.split("\\.");
if (h.length >= 2)
return h[h.length - 2] + "." + h[h.length - 1];
}
return host;
}
}

View File

@ -934,7 +934,7 @@ public class FragmentAccount extends FragmentBase {
List<EntityIdentity> identities = db.identity().getIdentities(account.id);
for (EntityIdentity identity : identities)
if (identity.password.equals(account.password) &&
Helper.getTld(identity.host).equals(Helper.getTld(account.host))) {
ConnectionHelper.isSameDomain(identity.host, account.host)) {
Log.i("Changing identity password host=" + identity.host);
identity.password = password;
db.identity().updateIdentity(identity);

View File

@ -871,14 +871,6 @@ public class Helper {
return true;
}
static String getTld(String host) {
String[] h = host.split("\\.");
if (h.length >= 2)
return h[h.length - 2] + "." + h[h.length - 1];
else
return host;
}
static int getSize(Bundle bundle) {
Parcel p = Parcel.obtain();
bundle.writeToParcel(p, 0);