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

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

test

parent 0c2487fb
Loading
Loading
Loading
Loading
+3 −38
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
@@ -49,8 +48,6 @@ import com.fsck.k9.K9.PostRemoveNavigation
import com.fsck.k9.K9.SplitViewMode
import com.fsck.k9.Preferences
import com.fsck.k9.account.BackgroundAccountRemover
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.EELO_ACCOUNT_TYPE
import com.fsck.k9.activity.accountmanager.EeloAccountCreator
import com.fsck.k9.activity.compose.MessageActions
import com.fsck.k9.controller.MessagingController
@@ -116,8 +113,6 @@ open class MessageList :

    private var messageListActivityConfig: MessageListActivityConfig? = null

    private lateinit var accountMngr: android.accounts.AccountManager

    /**
     * `true` if the message list should be displayed as flat list (i.e. no threading)
     * regardless whether or not message threading was enabled in the settings. This is used for
@@ -152,8 +147,9 @@ open class MessageList :

        var accounts = accountManager.getAccounts()

        accountMngr = android.accounts.AccountManager.get(this)
        if (addNewAccountsAutomatically(accounts)) {
        val eeloAccount = EeloAccountCreator()
        eeloAccount.init(this)
        if (eeloAccount.addNewAccountsAutomatically(accounts)) {
            accounts = preferences.getAccounts()
        }

@@ -203,37 +199,6 @@ open class MessageList :
        initializeFunding()
    }

    private fun addNewAccountsAutomatically(accounts: List<Account>): Boolean {
        return try {
            val eeloAccounts: Array<android.accounts.Account> = getEeloAccountsOnDevice()
            var accountWasAdded = false
            for (eeloAccount in eeloAccounts) {
                val emailId: String = accountMngr.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY)
                if (!emailId.contains("@")) continue
                var accountIsSignedIn = false
                for (account in accounts) {
                    if (emailId == account.email) {
                        accountIsSignedIn = true
                        break
                    }
                }
                if (!accountIsSignedIn) {
                    val password: String = accountMngr.getPassword(eeloAccount)
                    EeloAccountCreator.createAccount(this, emailId, password)
                    accountWasAdded = true
                }
            }
            accountWasAdded
        } catch (e: SecurityException) {
            Log.e("blah", "e $e")
            false
        }
    }

    private fun getEeloAccountsOnDevice(): Array<android.accounts.Account> {
        return accountMngr.getAccountsByType(EELO_ACCOUNT_TYPE)
    }

    private fun initializeFunding() {
        fundingManager.addFundingReminder(this) {
            FeatureLauncherActivity.launch(
+50 −12
Original line number Diff line number Diff line
package com.fsck.k9.activity.accountmanager

import android.accounts.AccountManager
import android.content.Context
import app.k9mail.legacy.account.Account
import com.fsck.k9.Core.setServicesEnabled
import com.fsck.k9.Preferences.Companion.getPreferences
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.EELO_ACCOUNT_TYPE

object EeloAccountCreator {
    fun createAccount(context: Context, emailId: String, password: String?) {
internal class EeloAccountCreator {
    private lateinit var mContext: Context
    private lateinit var accountMngr: AccountManager

    fun init(context: Context) {
        mContext = context
        accountMngr = AccountManager.get(context)
    }

    private fun createAccount(emailId: String, password: String) {
        val preferences = getPreferences()
        val account = preferences.newAccount()
        account.email = emailId
        val incomingSettings = account.incomingServerSettings
        val newAccount = preferences.newAccount()
        newAccount.email = emailId
        val incomingSettings = newAccount.incomingServerSettings
        incomingSettings.newPassword(password)
        val outgoingSettings = account.outgoingServerSettings
        val outgoingSettings = newAccount.outgoingServerSettings
        outgoingSettings.newPassword(password)
        account.incomingServerSettings = incomingSettings
        account.outgoingServerSettings = outgoingSettings
        val deletePolicy = account.deletePolicy
        account.deletePolicy = deletePolicy
        preferences.saveAccount(account)
        setServicesEnabled(context)
        newAccount.incomingServerSettings = incomingSettings
        newAccount.outgoingServerSettings = outgoingSettings
        val deletePolicy = newAccount.deletePolicy
        newAccount.deletePolicy = deletePolicy
        preferences.saveAccount(newAccount)
        setServicesEnabled(mContext)
    }

    fun addNewAccountsAutomatically(accounts: List<Account>): Boolean {
        var accountWasAdded = false
        try {
            val eeloAccounts = accountMngr.getAccountsByType(EELO_ACCOUNT_TYPE)
            for (eeloAccount in eeloAccounts) {
                val emailId: String = accountMngr.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY)
                if (!emailId.contains("@")) continue
                var accountIsSignedIn = false
                for (account in accounts) {
                    if (emailId == account.email) {
                        accountIsSignedIn = true
                        break
                    }
                }
                if (!accountIsSignedIn) {
                    val password: String = accountMngr.getPassword(eeloAccount)
                    createAccount(emailId, password)
                    accountWasAdded = true
                }
            }
        } catch (e: SecurityException) {
            // The app was not installed as system app.
        }
        return accountWasAdded
    }
}