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 6e768230c5186daf72060fdeaeae6605357db7bb..fd1c2ecac5301005cd2e49e9e41b8f12262a215b 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 db99fbc1f9dcf2fbf84bbcdf986fbaa071ad52ea..2981ff02f6971491d5d0bce04724b1aa63b80263 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,8 +691,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { } if (!accountIsSignedIn) { String password = accountManager.getPassword(eeloAccount); - EeloAccountCreator.createAccount(this, emailId, password); - accountWasAdded = true; + if (isDomainAvailable(emailId)) { + EeloAccountCreator.createAccount(this, emailId, password); + accountWasAdded = true; + } + } } @@ -674,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; @@ -689,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(); @@ -708,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 7598fc8541c2bb360633df512556157c09aa017b..8808f94b7f8530d71c99465b0ca1d2d099a81710 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 ea17b0ceff0680ea5fdbbdf9eb09c42ca26975ef..1b535934dc1823136b8db6259b51b401c392143d 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 5c3ce8bd39b4be6ee7155f7704701ece339c308c..9c1210f4a70bd8fba466015f016754f4a773183d 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 f2b94f45da9031581ae1e4d8351484f9a6bebb46..9cc366e0c5809a22665595f73af743673ced3fcb 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 93e2cc9eb96c2a3e6260243e483d8c3c9316e8df..ced636be4be455bee79c7a0217ad3083bc8a7cc8 100644 --- a/k9mail/src/main/res/xml/providers.xml +++ b/k9mail/src/main/res/xml/providers.xml @@ -1,5 +1,4 @@ - - - + - + - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - + + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - + + + - - - + + + - - - - - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + + + + + - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - + + + + + + + + + + + + + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - + + - - + +