diff --git a/app/k9mail/proguard-rules.pro b/app/k9mail/proguard-rules.pro index bbb161dcc7ee303332bad504ca1b5aa1dab6e77b..122f6ebbfacc2126a02c4217bb50c4c888373690 100644 --- a/app/k9mail/proguard-rules.pro +++ b/app/k9mail/proguard-rules.pro @@ -49,3 +49,46 @@ # OkHttp platform used only on JVM and when Conscrypt dependency is available. -dontwarn okhttp3.internal.platform.ConscryptPlatform + +# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and +# EnclosingMethod is required to use InnerClasses. +-keepattributes Signature, InnerClasses, EnclosingMethod + +# Retrofit does reflection on method and parameter annotations. +-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations + +# Keep annotation default values (e.g., retrofit2.http.Field.encoded). +-keepattributes AnnotationDefault + +# Retain service method parameters when optimizing. +-keepclassmembers,allowshrinking,allowobfuscation interface * { + @retrofit2.http.* ; +} + +# Ignore annotation used for build tooling. +-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement + +# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath. +-dontwarn kotlin.Unit + +# Top-level functions that can only be used by Kotlin. +-dontwarn retrofit2.KotlinExtensions +-dontwarn retrofit2.KotlinExtensions$* + +# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy +# and replaces all potential values with null. Explicitly keeping the interfaces prevents this. +-if interface * { @retrofit2.http.* ; } +-keep,allowobfuscation interface <1> + +# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items). +-keep,allowobfuscation,allowshrinking interface retrofit2.Call +-keep,allowobfuscation,allowshrinking class retrofit2.Response + +# With R8 full mode generic signatures are stripped for classes that are not +# kept. Suspend functions are wrapped in continuations where the type argument +# is used. +-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation + +-keep class org.simpleframework.xml.** { *; } + +-keep class com.fsck.k9.activity.setup.accountmanager.** { *; } \ No newline at end of file diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt index 9c86fcce148cde45b20273d9c853edfba645e273..3f668626e3f627f564bb680cef56f487e00e6a03 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt @@ -1,3 +1,19 @@ +/* + * Copyright ECORP SAS 2022 + * This program 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. + * + * This program 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 this program. If not, see . + */ + package com.fsck.k9.activity import android.accounts.AccountManager @@ -28,6 +44,7 @@ import androidx.drawerlayout.widget.DrawerLayout.DrawerListener import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentTransaction import androidx.lifecycle.Observer +import androidx.lifecycle.lifecycleScope import com.fsck.k9.Account import com.fsck.k9.Account.SortType import com.fsck.k9.K9 @@ -74,6 +91,8 @@ import com.fsck.k9.view.ViewSwitcher import com.fsck.k9.view.ViewSwitcher.OnSwitchCompleteListener import com.google.android.material.snackbar.Snackbar import com.mikepenz.materialdrawer.util.getOptimalDrawerWidth +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.component.KoinComponent @@ -142,17 +161,17 @@ open class MessageList : public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + setLayout(R.layout.message_list_loading) - var accounts = preferences.accounts + val accounts = preferences.accounts deleteIncompleteAccounts(accounts) accountManager = AccountManager.get(this) + addNewAccountsAutomatically(accounts, savedInstanceState) + } -// TODO remove old accounts automatically - if (addNewAccountsAutomatically(accounts)) { - accounts = preferences.accounts - } - + private fun onAccountConfigurationFinish(savedInstanceState: Bundle?) { + val accounts = preferences.accounts val hasAccountSetup = accounts.any { it.isFinishedSetup } if (!hasAccountSetup) { AccountSetupBasics.actionNewAccount(this) @@ -1679,51 +1698,51 @@ open class MessageList : val messageViewOnly: Boolean = false ) - private fun addNewAccountsAutomatically(accounts: List): Boolean { - return try { - val eeloAccounts: Array = getEeloAccountsOnDevice() - val googleAccounts: Array = getGoogleAccountsOnDevice() - var accountWasAdded = false - for (eeloAccount in eeloAccounts) { - val emailId: String = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY) - if (!emailId.contains("@")) continue - var accountIsSignedIn = false - for (account in accounts) { - if (emailId == account.email) { - accountIsSignedIn = true - break + private fun addNewAccountsAutomatically(accounts: List, savedInstanceState: Bundle?) { + lifecycleScope.launch(Dispatchers.IO) { + try { + val eeloAccounts: Array = getEeloAccountsOnDevice() + val googleAccounts: Array = getGoogleAccountsOnDevice() + for (eeloAccount in eeloAccounts) { + val emailId: String = accountManager.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 = accountManager.getPassword(eeloAccount) + EeloAccountCreator.createAccount(applicationContext, emailId, password, false) } } - if (!accountIsSignedIn) { - val password: String = accountManager.getPassword(eeloAccount) - EeloAccountCreator.createAccount(this, emailId, password, false) - accountWasAdded = true - } - } - - for (googleAccount in googleAccounts) { - val emailId: String = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY) - var accountIsSignedIn = false - for (account in accounts) { - if (emailId == account.email) { - if (account.name == null) { // we need to fix an old bug - account.name = emailId - Preferences.getPreferences(this).saveAccount(account) + for (googleAccount in googleAccounts) { + val emailId: String = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY) + + var accountIsSignedIn = false + for (account in accounts) { + if (emailId == account.email) { + if (account.name == null) { // we need to fix an old bug + account.name = emailId + Preferences.getPreferences(applicationContext).saveAccount(account) + } + accountIsSignedIn = true + break } - accountIsSignedIn = true - break + } + if (!accountIsSignedIn) { + EeloAccountCreator.createAccount(applicationContext, emailId, "", true) } } - if (!accountIsSignedIn) { - EeloAccountCreator.createAccount(this, emailId, "", true) - accountWasAdded = true - } + } catch (e: SecurityException) { + Timber.e(e) + } + lifecycleScope.launch(Dispatchers.Main) { + onAccountConfigurationFinish(savedInstanceState) } - return accountWasAdded - } catch (e: SecurityException) { - e.printStackTrace() - false } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigEmailProvider.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigEmailProvider.java index fdd09588cebaaf28ac2283d3d89ea82f57edfba1..7c6c138c70cde7d4bec7d3428c933c939dae419c 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigEmailProvider.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigEmailProvider.java @@ -1,11 +1,25 @@ -package com.fsck.k9.activity.setup.accountmanager; +/* + * Copyright ECORP SAS 2022 + * This program 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. + * + * This program 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 this program. If not, see . + */ +package com.fsck.k9.activity.setup.accountmanager; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; - @Root(name = "emailProvider", strict = false) public class EeloMailAutoConfigEmailProvider { @@ -18,6 +32,17 @@ public class EeloMailAutoConfigEmailProvider { @Element private EeloMailAutoConfigIncomingServer incomingServer; + public EeloMailAutoConfigEmailProvider() { + } + + public EeloMailAutoConfigEmailProvider(String id, + EeloMailAutoConfigOutgoingServer outgoingServer, + EeloMailAutoConfigIncomingServer incomingServer) { + this.id = id; + this.outgoingServer = outgoingServer; + this.incomingServer = incomingServer; + } + public String getId() { return id; } diff --git a/app/ui/legacy/src/main/res/layout/message_list_loading.xml b/app/ui/legacy/src/main/res/layout/message_list_loading.xml new file mode 100644 index 0000000000000000000000000000000000000000..c8805e37f630e88ce907525c529e023da7c328c8 --- /dev/null +++ b/app/ui/legacy/src/main/res/layout/message_list_loading.xml @@ -0,0 +1,36 @@ + + + + + + + + \ No newline at end of file