From a60702da68836f0586aec553f83ae7f8d0d4bd24 Mon Sep 17 00:00:00 2001 From: Sumit Pundir Date: Fri, 24 Apr 2020 08:26:56 +0530 Subject: [PATCH 1/2] Accounts: do not auto-sync for certain custom server based accounts Accounts based on non /e/ custom servers are not to be synced because they most probably lack a mail server in their implementation. So check whether an /e/ type tagged account is syncable or not and let the mail app to not crash if it isn't tagged syncable. Signed-off-by: Sumit Pundir --- .../src/main/java/foundation/e/mail/activity/Accounts.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java b/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java index db99fbc1f9..85de833cd3 100644 --- a/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java +++ b/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java @@ -663,8 +663,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } if (!accountIsSignedIn) { String password = accountManager.getPassword(eeloAccount); - EeloAccountCreator.createAccount(this, emailId, password); - accountWasAdded = true; + if (ContentResolver.getIsSyncable(eeloAccount, MAIL_CONTENT_AUTHORITY) > 0) { + EeloAccountCreator.createAccount(this, emailId, password); + accountWasAdded = true; + } } } -- GitLab From 298f80ce8335429d247a6d5afd09db047379c002 Mon Sep 17 00:00:00 2001 From: Mohit Date: Tue, 12 May 2020 12:22:34 +0530 Subject: [PATCH 2/2] - Fixed Display flashing bug - Fixed crash for accounts that are not available in providers list --- .../e/mail/mail/store/RemoteStore.java | 25 +- .../foundation/e/mail/activity/Accounts.java | 49 +- .../activity/setup/AccountSetupPresenter.java | 15 +- .../activity/setup/EeloAccountCreator.java | 12 + .../mail/controller/MessagingController.java | 13 + .../layout/account_setup_check_settings.xml | 47 +- k9mail/src/main/res/xml/providers.xml | 2226 ++++++++++++----- 7 files changed, 1760 insertions(+), 627 deletions(-) diff --git a/k9mail-library/src/main/java/foundation/e/mail/mail/store/RemoteStore.java b/k9mail-library/src/main/java/foundation/e/mail/mail/store/RemoteStore.java index 6e768230c5..fd1c2ecac5 100644 --- a/k9mail-library/src/main/java/foundation/e/mail/mail/store/RemoteStore.java +++ b/k9mail-library/src/main/java/foundation/e/mail/mail/store/RemoteStore.java @@ -48,24 +48,25 @@ public abstract class RemoteStore extends Store { { String uri = storeConfig.getStoreUri(); - if (uri.startsWith("local")) { + if (uri != null && uri.startsWith("local")) { throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI"); } Store store = sStores.get(uri); if (store == null) { - if (uri.startsWith("imap")) { - store = new ImapStore( - storeConfig, - new DefaultTrustedSocketFactory(context), - (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), - oAuth2TokenProvider); - } else if (uri.startsWith("pop3")) { - store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context)); - } else if (uri.startsWith("webdav")) { - store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory()); + if (uri != null) { + if (uri.startsWith("imap")) { + store = new ImapStore( + storeConfig, + new DefaultTrustedSocketFactory(context), + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE), + oAuth2TokenProvider); + } else if (uri.startsWith("pop3")) { + store = new Pop3Store(storeConfig, new DefaultTrustedSocketFactory(context)); + } else if (uri.startsWith("webdav")) { + store = new WebDavStore(storeConfig, new WebDavHttpClient.WebDavHttpClientFactory()); + } } - if (store != null) { sStores.put(uri, store); } diff --git a/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java b/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java index 85de833cd3..2981ff02f6 100644 --- a/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java +++ b/k9mail/src/main/java/foundation/e/mail/activity/Accounts.java @@ -498,6 +498,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { return true; } + + private boolean isDomainAvailable(String deviceAccountEmailId) { + try { + String[] emailParts = EmailHelper.splitEmail(deviceAccountEmailId); + AccountSetupPresenter.Provider provider = findProviderForDomain(this, emailParts[1]); + if (provider != null) { + return true; + } + } catch (Exception e) { + Timber.e(e, "Error while trying to initialise account configuration."); + } + return false; + } + + private static AccountSetupPresenter.Provider findProviderForDomain(Context context, String domain) { try { @@ -529,6 +544,19 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { return provider; } } + + if (provider == null) { + provider = new AccountSetupPresenter.Provider(); + provider.id = domain; + provider.label = domain + " mail service"; + provider.domain = domain; + provider.note = ""; + provider.incomingUriTemplate = new URI("imap+ssl+://mail." + domain); + provider.incomingUsernameTemplate = "$email"; + provider.outgoingUriTemplate = new URI("smtp+tls+://mail." + domain); + provider.outgoingUsernameTemplate = "$email"; + } + } catch (Exception e) { Timber.e(e, "Error while trying to load provider settings."); } @@ -663,10 +691,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } if (!accountIsSignedIn) { String password = accountManager.getPassword(eeloAccount); - if (ContentResolver.getIsSyncable(eeloAccount, MAIL_CONTENT_AUTHORITY) > 0) { + if (isDomainAvailable(emailId)) { EeloAccountCreator.createAccount(this, emailId, password); accountWasAdded = true; - } + } + } } @@ -676,9 +705,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { boolean accountIsSignedIn = false; for (Account account : accounts) { if (emailId.equals(account.getEmail())) { - if(account.getName() == null){ // we need to fix an old bug - account.setName(emailId); - account.save(Preferences.getPreferences(this)); + if (account.getName() == null) { // we need to fix an old bug + account.setName(emailId); + account.save(Preferences.getPreferences(this)); } accountIsSignedIn = true; @@ -691,17 +720,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } } - return accountWasAdded; - } - catch (SecurityException e) - { + return accountWasAdded; + } catch (SecurityException e) { e.printStackTrace(); return false; } } - private void removeOldAccountsAutomatically(List accounts){ + private void removeOldAccountsAutomatically(List accounts) { try { android.accounts.Account[] eeloAccounts = getEeloAccountsOnDevice(); android.accounts.Account[] googleAccounts = getGoogleAccountsOnDevice(); @@ -710,7 +737,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { if (account.isDeviceAccount()) { boolean accountIsSignedInOnDevice = false; // because of a now fixed bug, accounts with empty mails coming from custom nextcloud server could have been added: we need to remove them - if(account.getEmail() != null) { + if (account.getEmail() != null) { for (android.accounts.Account eeloAccount : eeloAccounts) { String emailId = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY); diff --git a/k9mail/src/main/java/foundation/e/mail/activity/setup/AccountSetupPresenter.java b/k9mail/src/main/java/foundation/e/mail/activity/setup/AccountSetupPresenter.java index 7598fc8541..8808f94b7f 100644 --- a/k9mail/src/main/java/foundation/e/mail/activity/setup/AccountSetupPresenter.java +++ b/k9mail/src/main/java/foundation/e/mail/activity/setup/AccountSetupPresenter.java @@ -724,6 +724,19 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, return provider; } } + + if (provider == null) { + provider = new AccountSetupPresenter.Provider(); + provider.id = domain; + provider.label = domain + " mail service"; + provider.domain = domain; + provider.note = ""; + provider.incomingUriTemplate = new URI("imap+ssl+://mail." + domain); + provider.incomingUsernameTemplate = "$email"; + provider.outgoingUriTemplate = new URI("smtp+tls+://mail." + domain); + provider.outgoingUsernameTemplate = "$email"; + } + } catch (Exception e) { Timber.e(e, "Error while trying to load provider settings."); } @@ -1878,7 +1891,7 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, public void onWebViewDismiss() { if (!oAuth2CodeGotten) { view.goToBasics(); - view.showErrorDialog("Couldn't sign in"); + view.showErrorDialog("Couldn't sign in"); } } diff --git a/k9mail/src/main/java/foundation/e/mail/activity/setup/EeloAccountCreator.java b/k9mail/src/main/java/foundation/e/mail/activity/setup/EeloAccountCreator.java index ea17b0ceff..1b535934dc 100644 --- a/k9mail/src/main/java/foundation/e/mail/activity/setup/EeloAccountCreator.java +++ b/k9mail/src/main/java/foundation/e/mail/activity/setup/EeloAccountCreator.java @@ -154,6 +154,18 @@ public class EeloAccountCreator { return provider; } } + if (provider == null) { + provider = new AccountSetupPresenter.Provider(); + provider.id = domain; + provider.label = domain + " mail service"; + provider.domain = domain; + provider.note = ""; + provider.incomingUriTemplate = new URI("imap+ssl+://mail." + domain); + provider.incomingUsernameTemplate = "$email"; + provider.outgoingUriTemplate = new URI("smtp+tls+://mail." + domain); + provider.outgoingUsernameTemplate = "$email"; + } + } catch (Exception e) { Timber.e(e, "Error while trying to load provider settings."); } diff --git a/k9mail/src/main/java/foundation/e/mail/controller/MessagingController.java b/k9mail/src/main/java/foundation/e/mail/controller/MessagingController.java index 5c3ce8bd39..9c1210f4a7 100644 --- a/k9mail/src/main/java/foundation/e/mail/controller/MessagingController.java +++ b/k9mail/src/main/java/foundation/e/mail/controller/MessagingController.java @@ -3521,6 +3521,19 @@ public class MessagingController { return provider; } } + + if (provider == null) { + provider = new AccountSetupPresenter.Provider(); + provider.id = domain; + provider.label = domain + " mail service"; + provider.domain = domain; + provider.note = ""; + provider.incomingUriTemplate = new URI("imap+ssl+://mail." + domain); + provider.incomingUsernameTemplate = "$email"; + provider.outgoingUriTemplate = new URI("smtp+tls+://mail." + domain); + provider.outgoingUsernameTemplate = "$email"; + } + } catch (Exception e) { Timber.e(e, "Error while trying to load provider settings."); } diff --git a/k9mail/src/main/res/layout/account_setup_check_settings.xml b/k9mail/src/main/res/layout/account_setup_check_settings.xml index f2b94f45da..9cc366e0c5 100644 --- a/k9mail/src/main/res/layout/account_setup_check_settings.xml +++ b/k9mail/src/main/res/layout/account_setup_check_settings.xml @@ -1,45 +1,46 @@ + android:layout_height="match_parent"> + + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintLeft_toLeftOf="@+id/title" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toBottomOf="@+id/message" + app:mpb_progressStyle="horizontal" /> + tools:layout_constraintTop_creator="1" /> diff --git a/k9mail/src/main/res/xml/providers.xml b/k9mail/src/main/res/xml/providers.xml index 93e2cc9eb9..ced636be4b 100644 --- a/k9mail/src/main/res/xml/providers.xml +++ b/k9mail/src/main/res/xml/providers.xml @@ -1,5 +1,4 @@ - - - + - + - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - + + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - + + + - - - + + + - - - - - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + + + + + - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - + + + + + + + + + + + + + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - + + - - + + -- GitLab