Search in sources :

Example 16 with ConnectionSecurity

use of com.fsck.k9.mail.ConnectionSecurity in project k-9 by k9mail.

the class AccountSetupIncoming method onNext.

protected void onNext() {
    try {
        ConnectionSecurity connectionSecurity = getSelectedSecurity();
        String username = mUsernameView.getText().toString().trim();
        String password = null;
        String clientCertificateAlias = null;
        AuthType authType = getSelectedAuthType();
        if ((ConnectionSecurity.SSL_TLS_REQUIRED == connectionSecurity) || (ConnectionSecurity.STARTTLS_REQUIRED == connectionSecurity)) {
            clientCertificateAlias = mClientCertificateSpinner.getAlias();
        }
        if (authType != AuthType.EXTERNAL) {
            password = mPasswordView.getText().toString();
        }
        String host = mServerView.getText().toString();
        int port = Integer.parseInt(mPortView.getText().toString());
        Map<String, String> extra = emptyMap();
        if (mStoreType.equals(Protocols.IMAP)) {
            boolean autoDetectNamespace = mImapAutoDetectNamespaceView.isChecked();
            String pathPrefix = mImapPathPrefixView.getText().toString();
            extra = ImapStoreSettings.createExtra(autoDetectNamespace, pathPrefix);
        } else if (mStoreType.equals(Protocols.WEBDAV)) {
            String path = mWebdavPathPrefixView.getText().toString();
            String authPath = mWebdavAuthPathView.getText().toString();
            String mailboxPath = mWebdavMailboxPathView.getText().toString();
            extra = WebDavStoreSettings.createExtra(null, path, authPath, mailboxPath);
        }
        DI.get(LocalKeyStoreManager.class).deleteCertificate(mAccount, host, port, MailServerDirection.INCOMING);
        ServerSettings settings = new ServerSettings(mStoreType, host, port, connectionSecurity, authType, username, password, clientCertificateAlias, extra);
        mAccount.setIncomingServerSettings(settings);
        mAccount.setCompression(NetworkType.MOBILE, mCompressionMobile.isChecked());
        mAccount.setCompression(NetworkType.WIFI, mCompressionWifi.isChecked());
        mAccount.setCompression(NetworkType.OTHER, mCompressionOther.isChecked());
        mAccount.setSubscribedFoldersOnly(mSubscribedFoldersOnly.isChecked());
        AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
    } catch (Exception e) {
        failure(e);
    }
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity) ServerSettings(com.fsck.k9.mail.ServerSettings) LocalKeyStoreManager(com.fsck.k9.LocalKeyStoreManager) AuthType(com.fsck.k9.mail.AuthType)

Example 17 with ConnectionSecurity

use of com.fsck.k9.mail.ConnectionSecurity in project k-9 by k9mail.

the class AccountSetupOutgoing method validateFields.

/**
 * This is invoked only when the user makes changes to a widget, not when
 * widgets are changed programmatically.  (The logic is simpler when you know
 * that this is the last thing called after an input change.)
 */
private void validateFields() {
    AuthType authType = getSelectedAuthType();
    boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
    ConnectionSecurity connectionSecurity = getSelectedSecurity();
    boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    if (isAuthTypeExternal && !hasConnectionSecurity) {
        // Notify user of an invalid combination of AuthType.EXTERNAL & ConnectionSecurity.NONE
        String toastText = getString(R.string.account_setup_outgoing_invalid_setting_combo_notice, getString(R.string.account_setup_incoming_auth_type_label), AuthType.EXTERNAL.toString(), getString(R.string.account_setup_incoming_security_label), ConnectionSecurity.NONE.toString());
        Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
        // Reset the views back to their previous settings without recursing through here again
        OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
        mAuthTypeView.setOnItemSelectedListener(null);
        mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
        mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateViewFromAuthType();
        updateViewFromSecurity(getSelectedSecurity());
        onItemSelectedListener = mSecurityTypeView.getOnItemSelectedListener();
        mSecurityTypeView.setOnItemSelectedListener(null);
        mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
        mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateAuthPlainTextFromSecurityType(getSelectedSecurity());
        mPortView.removeTextChangedListener(validationTextWatcher);
        mPortView.setText(mCurrentPortViewSetting);
        mPortView.addTextChangedListener(validationTextWatcher);
        authType = getSelectedAuthType();
        isAuthTypeExternal = (AuthType.EXTERNAL == authType);
        connectionSecurity = getSelectedSecurity();
        hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    } else {
        mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
        mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition();
        mCurrentPortViewSetting = mPortView.getText().toString();
    }
    boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null;
    boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView);
    boolean hasValidPasswordSettings = hasValidUserName && !isAuthTypeExternal && Utility.requiredFieldValid(mPasswordView);
    boolean hasValidExternalAuthSettings = hasValidUserName && isAuthTypeExternal && hasConnectionSecurity && hasValidCertificateAlias;
    mNextButton.setEnabled(Utility.domainFieldValid(mServerView) && Utility.requiredFieldValid(mPortView) && (!mRequireLoginView.isChecked() || hasValidPasswordSettings || hasValidExternalAuthSettings));
    Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AuthType(com.fsck.k9.mail.AuthType)

Example 18 with ConnectionSecurity

use of com.fsck.k9.mail.ConnectionSecurity in project k-9 by k9mail.

the class AccountSetupOutgoing method updatePortFromSecurityType.

private void updatePortFromSecurityType() {
    ConnectionSecurity securityType = getSelectedSecurity();
    updateAuthPlainTextFromSecurityType(securityType);
    // Remove listener so as not to trigger validateFields() which is called
    // elsewhere as a result of user interaction.
    mPortView.removeTextChangedListener(validationTextWatcher);
    mPortView.setText(String.valueOf(accountCreator.getDefaultPort(securityType, Protocols.SMTP)));
    mPortView.addTextChangedListener(validationTextWatcher);
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity)

Aggregations

ConnectionSecurity (com.fsck.k9.mail.ConnectionSecurity)15 ServerSettings (com.fsck.k9.mail.ServerSettings)10 AuthType (com.fsck.k9.mail.AuthType)9 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)2 LocalKeyStoreManager (com.fsck.k9.LocalKeyStoreManager)2 HashMap (java.util.HashMap)2 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 MessagingException (com.fsck.k9.mail.MessagingException)1 PeekableInputStream (com.fsck.k9.mail.filter.PeekableInputStream)1 TextInputLayout (com.google.android.material.textfield.TextInputLayout)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1