Loading k9mail-library/src/main/java/com/fsck/k9/mail/autoconfiguration/DNSHelper.java→k9mail-library/src/main/java/com/fsck/k9/mail/autoconfiguration/DnsHelper.java +31 −0 Original line number Diff line number Diff line Loading @@ -7,16 +7,25 @@ import org.xbill.DNS.MXRecord; import org.xbill.DNS.TextParseException; public class DNSHelper { public static String getMXDomain(String domain) throws TextParseException, UnknownHostException { public class DnsHelper { public static String getMxDomain(String domain) throws UnknownHostException { DNSOperation dnsOperation = new DNSOperation(); MXRecord mxRecord = dnsOperation.mxLookup(domain); MXRecord mxRecord; try { mxRecord = dnsOperation.mxLookup(domain); } catch (TextParseException e) { return null; } if (mxRecord != null) { final String target = mxRecord.getTarget().toString(true); final String[] targetParts = target.split("\\."); return targetParts[targetParts.length - 2] + "." + targetParts[targetParts.length - 1]; return getDomainFromFqdn(target); } return null; } private static String getDomainFromFqdn(String fqdn) { final String[] parts = fqdn.split("\\."); return parts[parts.length - 2] + "." + parts[parts.length - 1]; } } k9mail-library/src/main/java/com/fsck/k9/mail/store/StoreConfig.java +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ import com.fsck.k9.mail.NetworkType; public interface StoreConfig { String getStoreUri(); String getTransportUri(); void setStoreUri(String storeUri); void setTransportUri(String transportUri); boolean subscribedFoldersOnly(); boolean useCompression(NetworkType type); Loading k9mail/src/main/java/com/fsck/k9/account/OAuth2WebViewClient.java +1 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ abstract class OAuth2WebViewClient extends WebViewClient { if (arrivedAtRedirectUri(uri)) { final String error = uri.getQueryParameter("error"); if (error != null) { Timber.i("got oauth error: " + error); Timber.e("got oauth error: " + error); errorHandler.onError(error); requestHandler.onErrorWhenGettingOAuthCode(error); return true; Loading @@ -44,7 +44,6 @@ abstract class OAuth2WebViewClient extends WebViewClient { return true; } // if (!uri.getHost().contains("google")) { if (getOutOfDomain(uri)) { requestHandler.onErrorWhenGettingOAuthCode("Don't surf away"); // TODO: 2017/8/19 better error message return true; Loading k9mail/src/main/java/com/fsck/k9/activity/AccountConfig.java +0 −2 Original line number Diff line number Diff line Loading @@ -40,8 +40,6 @@ public interface AccountConfig extends StoreConfig { public void setDescription(String description); public void setDeletePolicy(DeletePolicy deletePolicy); public void setEmail(String email); public void setStoreUri(String storeUri); public void setTransportUri(String transportUri); void setCompression(NetworkType networkType, boolean useCompression); void addCertificate(CheckDirection direction, X509Certificate certificate) throws CertificateException; Loading k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupPresenter.java +35 −30 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ import com.fsck.k9.mail.autoconfiguration.AutoConfigure.ProviderInfo; import com.fsck.k9.mail.autoconfiguration.AutoConfigureAutodiscover; import com.fsck.k9.mail.autoconfiguration.AutoconfigureMozilla; import com.fsck.k9.mail.autoconfiguration.AutoconfigureSrv; import com.fsck.k9.mail.autoconfiguration.DNSHelper; import com.fsck.k9.mail.autoconfiguration.DnsHelper; import com.fsck.k9.mail.filter.Hex; import com.fsck.k9.mail.store.RemoteStore; import com.fsck.k9.mail.store.imap.ImapStoreSettings; Loading Loading @@ -248,14 +248,14 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, incomingReady = false; outgoingReady = false; try { String mxDomain = DNSHelper.getMXDomain(domain); String mxDomain = DnsHelper.getMxDomain(domain); if (mxDomain == null) return providerInfo; if (mxDomain == null) return null; publishProgress(R.string.account_setup_check_settings_retr_info_msg); providerInfo = autoconfigureDomain(mxDomain); } catch (TextParseException | UnknownHostException e) { } catch (UnknownHostException e) { Timber.e(e, "Error while trying to run MX lookup"); } Loading Loading @@ -288,8 +288,6 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, } private void testDomain(String domain) { publishProgress(R.string.account_setup_check_settings_guessing_msg); String guessedDomainForMailPrefix; //noinspection ConstantConditions if (domain.startsWith("mail.")) { Loading @@ -298,35 +296,42 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, guessedDomainForMailPrefix = "mail." + domain; } testIncoming(guessedDomainForMailPrefix); testIncoming(guessedDomainForMailPrefix, false); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.STARTTLS_REQUIRED); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.STARTTLS_REQUIRED, false); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.SSL_TLS_REQUIRED); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.SSL_TLS_REQUIRED, false); testIncoming("imap." + domain); testIncoming("imap." + domain, false); testOutgoing("smtp." + domain, ConnectionSecurity.STARTTLS_REQUIRED); testOutgoing("smtp." + domain, ConnectionSecurity.STARTTLS_REQUIRED, false); testOutgoing("smtp." + domain, ConnectionSecurity.SSL_TLS_REQUIRED); testOutgoing("smtp." + domain, ConnectionSecurity.SSL_TLS_REQUIRED, false); } private void testIncoming(String domain) { private void testIncoming(String domain, boolean useLocalPart) { if (!incomingReady) { try { accountConfig.setStoreUri(getDefaultStoreURI(email, password, domain).toString()); accountConfig.setStoreUri(getDefaultStoreURI( useLocalPart ? EmailHelper.getLocalPartFromEmailAddress(email) : email, password, domain).toString()); accountConfig.getRemoteStore().checkSettings(); incomingReady = true; } catch (AuthenticationFailedException afe) { if (!useLocalPart) { testIncoming(domain, true); } } catch (URISyntaxException | MessagingException ignored) { } } } private void testOutgoing(String domain, ConnectionSecurity connectionSecurity) { private void testOutgoing(String domain, ConnectionSecurity connectionSecurity, boolean useLocalPart) { if (!outgoingReady) { try { accountConfig.setTransportUri(getDefaultTransportURI(email, password, domain, connectionSecurity).toString()); accountConfig.setTransportUri(getDefaultTransportURI( useLocalPart ? EmailHelper.getLocalPartFromEmailAddress(email) : email, password, domain, connectionSecurity).toString()); Transport transport = TransportProvider.getInstance().getTransport(context, accountConfig, Globals.getOAuth2TokenProvider()); transport.close(); Loading @@ -336,6 +341,10 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, transport.close(); } outgoingReady = true; } catch (AuthenticationFailedException afe) { if (!useLocalPart) { testOutgoing(domain, connectionSecurity, true); } } catch (URISyntaxException | MessagingException ignored) { } } Loading Loading @@ -612,21 +621,8 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, @Override protected Boolean doInBackground(CheckDirection... params) { try { /* * This task could be interrupted at any point, but network operations can block, * so relying on InterruptedException is not enough. Instead, check after * each potentially long-running operation. */ if (canceled) { return false; } checkSettings(); if (canceled) { return false; } return true; } catch (OAuth2NeedUserPromptException ignored) { Loading Loading @@ -658,6 +654,15 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, protected void onPostExecute(Boolean bool) { super.onPostExecute(bool); /* * This task could be interrupted at any point, but network operations can block, * so relying on InterruptedException is not enough. Instead, check after * each potentially long-running operation. */ if (canceled) { return; } if (bool && callback != null) { callback.onCheckSuccess(); } Loading Loading
k9mail-library/src/main/java/com/fsck/k9/mail/autoconfiguration/DNSHelper.java→k9mail-library/src/main/java/com/fsck/k9/mail/autoconfiguration/DnsHelper.java +31 −0 Original line number Diff line number Diff line Loading @@ -7,16 +7,25 @@ import org.xbill.DNS.MXRecord; import org.xbill.DNS.TextParseException; public class DNSHelper { public static String getMXDomain(String domain) throws TextParseException, UnknownHostException { public class DnsHelper { public static String getMxDomain(String domain) throws UnknownHostException { DNSOperation dnsOperation = new DNSOperation(); MXRecord mxRecord = dnsOperation.mxLookup(domain); MXRecord mxRecord; try { mxRecord = dnsOperation.mxLookup(domain); } catch (TextParseException e) { return null; } if (mxRecord != null) { final String target = mxRecord.getTarget().toString(true); final String[] targetParts = target.split("\\."); return targetParts[targetParts.length - 2] + "." + targetParts[targetParts.length - 1]; return getDomainFromFqdn(target); } return null; } private static String getDomainFromFqdn(String fqdn) { final String[] parts = fqdn.split("\\."); return parts[parts.length - 2] + "." + parts[parts.length - 1]; } }
k9mail-library/src/main/java/com/fsck/k9/mail/store/StoreConfig.java +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ import com.fsck.k9.mail.NetworkType; public interface StoreConfig { String getStoreUri(); String getTransportUri(); void setStoreUri(String storeUri); void setTransportUri(String transportUri); boolean subscribedFoldersOnly(); boolean useCompression(NetworkType type); Loading
k9mail/src/main/java/com/fsck/k9/account/OAuth2WebViewClient.java +1 −2 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ abstract class OAuth2WebViewClient extends WebViewClient { if (arrivedAtRedirectUri(uri)) { final String error = uri.getQueryParameter("error"); if (error != null) { Timber.i("got oauth error: " + error); Timber.e("got oauth error: " + error); errorHandler.onError(error); requestHandler.onErrorWhenGettingOAuthCode(error); return true; Loading @@ -44,7 +44,6 @@ abstract class OAuth2WebViewClient extends WebViewClient { return true; } // if (!uri.getHost().contains("google")) { if (getOutOfDomain(uri)) { requestHandler.onErrorWhenGettingOAuthCode("Don't surf away"); // TODO: 2017/8/19 better error message return true; Loading
k9mail/src/main/java/com/fsck/k9/activity/AccountConfig.java +0 −2 Original line number Diff line number Diff line Loading @@ -40,8 +40,6 @@ public interface AccountConfig extends StoreConfig { public void setDescription(String description); public void setDeletePolicy(DeletePolicy deletePolicy); public void setEmail(String email); public void setStoreUri(String storeUri); public void setTransportUri(String transportUri); void setCompression(NetworkType networkType, boolean useCompression); void addCertificate(CheckDirection direction, X509Certificate certificate) throws CertificateException; Loading
k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupPresenter.java +35 −30 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ import com.fsck.k9.mail.autoconfiguration.AutoConfigure.ProviderInfo; import com.fsck.k9.mail.autoconfiguration.AutoConfigureAutodiscover; import com.fsck.k9.mail.autoconfiguration.AutoconfigureMozilla; import com.fsck.k9.mail.autoconfiguration.AutoconfigureSrv; import com.fsck.k9.mail.autoconfiguration.DNSHelper; import com.fsck.k9.mail.autoconfiguration.DnsHelper; import com.fsck.k9.mail.filter.Hex; import com.fsck.k9.mail.store.RemoteStore; import com.fsck.k9.mail.store.imap.ImapStoreSettings; Loading Loading @@ -248,14 +248,14 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, incomingReady = false; outgoingReady = false; try { String mxDomain = DNSHelper.getMXDomain(domain); String mxDomain = DnsHelper.getMxDomain(domain); if (mxDomain == null) return providerInfo; if (mxDomain == null) return null; publishProgress(R.string.account_setup_check_settings_retr_info_msg); providerInfo = autoconfigureDomain(mxDomain); } catch (TextParseException | UnknownHostException e) { } catch (UnknownHostException e) { Timber.e(e, "Error while trying to run MX lookup"); } Loading Loading @@ -288,8 +288,6 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, } private void testDomain(String domain) { publishProgress(R.string.account_setup_check_settings_guessing_msg); String guessedDomainForMailPrefix; //noinspection ConstantConditions if (domain.startsWith("mail.")) { Loading @@ -298,35 +296,42 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, guessedDomainForMailPrefix = "mail." + domain; } testIncoming(guessedDomainForMailPrefix); testIncoming(guessedDomainForMailPrefix, false); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.STARTTLS_REQUIRED); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.STARTTLS_REQUIRED, false); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.SSL_TLS_REQUIRED); testOutgoing(guessedDomainForMailPrefix, ConnectionSecurity.SSL_TLS_REQUIRED, false); testIncoming("imap." + domain); testIncoming("imap." + domain, false); testOutgoing("smtp." + domain, ConnectionSecurity.STARTTLS_REQUIRED); testOutgoing("smtp." + domain, ConnectionSecurity.STARTTLS_REQUIRED, false); testOutgoing("smtp." + domain, ConnectionSecurity.SSL_TLS_REQUIRED); testOutgoing("smtp." + domain, ConnectionSecurity.SSL_TLS_REQUIRED, false); } private void testIncoming(String domain) { private void testIncoming(String domain, boolean useLocalPart) { if (!incomingReady) { try { accountConfig.setStoreUri(getDefaultStoreURI(email, password, domain).toString()); accountConfig.setStoreUri(getDefaultStoreURI( useLocalPart ? EmailHelper.getLocalPartFromEmailAddress(email) : email, password, domain).toString()); accountConfig.getRemoteStore().checkSettings(); incomingReady = true; } catch (AuthenticationFailedException afe) { if (!useLocalPart) { testIncoming(domain, true); } } catch (URISyntaxException | MessagingException ignored) { } } } private void testOutgoing(String domain, ConnectionSecurity connectionSecurity) { private void testOutgoing(String domain, ConnectionSecurity connectionSecurity, boolean useLocalPart) { if (!outgoingReady) { try { accountConfig.setTransportUri(getDefaultTransportURI(email, password, domain, connectionSecurity).toString()); accountConfig.setTransportUri(getDefaultTransportURI( useLocalPart ? EmailHelper.getLocalPartFromEmailAddress(email) : email, password, domain, connectionSecurity).toString()); Transport transport = TransportProvider.getInstance().getTransport(context, accountConfig, Globals.getOAuth2TokenProvider()); transport.close(); Loading @@ -336,6 +341,10 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, transport.close(); } outgoingReady = true; } catch (AuthenticationFailedException afe) { if (!useLocalPart) { testOutgoing(domain, connectionSecurity, true); } } catch (URISyntaxException | MessagingException ignored) { } } Loading Loading @@ -612,21 +621,8 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, @Override protected Boolean doInBackground(CheckDirection... params) { try { /* * This task could be interrupted at any point, but network operations can block, * so relying on InterruptedException is not enough. Instead, check after * each potentially long-running operation. */ if (canceled) { return false; } checkSettings(); if (canceled) { return false; } return true; } catch (OAuth2NeedUserPromptException ignored) { Loading Loading @@ -658,6 +654,15 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter, protected void onPostExecute(Boolean bool) { super.onPostExecute(bool); /* * This task could be interrupted at any point, but network operations can block, * so relying on InterruptedException is not enough. Instead, check after * each potentially long-running operation. */ if (canceled) { return; } if (bool && callback != null) { callback.onCheckSuccess(); } Loading