Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02e51541 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

feat(account): Identify Murena email and web hosts

parent 5a5e7abd
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.Context
import app.k9mail.core.android.common.accountmanager.AccountManagerConstants
import timber.log.Timber

import com.fsck.k9.Account as K9Account

object OsAccountManagerUtil {

    /**
@@ -83,4 +85,23 @@ object OsAccountManagerUtil {

        fun isAccountFound() = this != ACCOUNT_NOT_FOUND
    }

    fun isMurenaEmailAccount(account: K9Account): Boolean {
        val incoming = account.incomingServerSettings
        val outgoing = account.outgoingServerSettings

        if (incoming.host == null || outgoing.host == null) {
            return false
        }

        return isMurenaMailHost(incoming.host!!) && isMurenaMailHost(outgoing.host!!)
    }

    private fun isMurenaMailHost(host: String): Boolean {
        return "mail.ecloud.global" == host
    }

    fun isMurenaWebHostUrl(host: String): Boolean {
        return host.contains("https://murena.io") || host.contains("http://murena.io")
    }
}
+30 −23
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.Account.Expunge;
import com.fsck.k9.DI;
import com.fsck.k9.K9;
import com.fsck.k9.OsAccountManagerUtil;
import com.fsck.k9.Preferences;
import com.fsck.k9.backend.BackendManager;
import com.fsck.k9.backend.api.Backend;
@@ -671,10 +672,17 @@ public class MessagingController {
    }

    private boolean updatePassword(Account account) {
        if (!OsAccountManagerUtil.INSTANCE.isMurenaEmailAccount(account)) return false;

        AccountManager accountManager = AccountManager.get(context);
        android.accounts.Account[] eeloAccounts =
            accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE);

        for (String accountType : AccountManagerConstants.INSTANCE.getALL_ACCOUNT_TYPES()) {
            for (android.accounts.Account deviceAccount : accountManager.getAccountsByType(accountType)) {
        for (android.accounts.Account deviceAccount : eeloAccounts) {
            String hostUrl = accountManager.getUserData(deviceAccount, AccountManagerConstants.KEY_OC_BASE_URL);
            if (hostUrl == null || !OsAccountManagerUtil.INSTANCE.isMurenaWebHostUrl(hostUrl)) {
                continue;
            }
            // Check if the account email matches with account manager
            String emailId = accountManager.getUserData(deviceAccount,
                    AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY);
@@ -700,7 +708,6 @@ public class MessagingController {
                return true;
            }
        }
        }

        return false;
    }
+9 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.fsck.k9.Account;
import com.fsck.k9.Account.DeletePolicy;
import com.fsck.k9.Core;
import com.fsck.k9.DI;
import com.fsck.k9.OsAccountManagerUtil;
import com.fsck.k9.Preferences;
import com.fsck.k9.account.AccountCreatorHelper;
import com.fsck.k9.account.BackgroundAccountRemover;
@@ -140,6 +141,9 @@ public class EeloAccountCreator {
    }

    private static void updatePasswordIfChanged(Account account, String password) {
        // Don't update password if its not a murena account
        if (!OsAccountManagerUtil.INSTANCE.isMurenaEmailAccount(account)) return;

        ServerSettings incoming = account.getIncomingServerSettings();
        ServerSettings outgoing = account.getOutgoingServerSettings();

@@ -170,6 +174,11 @@ public class EeloAccountCreator {
            accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE);
        for (android.accounts.Account eeloAccount : eeloAccounts) {
            final String emailId = getEmailId(accountManager, eeloAccount);
            String hostUrl = accountManager.getUserData(eeloAccount, AccountManagerConstants.KEY_OC_BASE_URL);
            // We are trying to add account that are not murena.
            if (hostUrl == null || !OsAccountManagerUtil.INSTANCE.isMurenaWebHostUrl(hostUrl)) {
                continue;
            }

            if (isInvalidEmail(emailId)) {
                continue;
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ object AccountManagerConstants {
    const val AUTH_TOKEN_TYPE = "oauth2-access-token"
    const val KEY_AUTH_STATE = "auth_state"
    const val USERNAME_HINT = "userNameHint"
    const val KEY_OC_BASE_URL = "oc_base_url"

    const val OPEN_APP_PACKAGE_AFTER_AUTH = "open_app_package_after_auth"
    const val OPEN_APP_ACTIVITY_AFTER_AUTH = "open_app_activity_after_auth"