mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-15 06:30:17 -05:00
Use Transport.decodeTransportUri and Transport.createTransportUri
rather than manually creating the URIs. This mirrors behavior that occurs in AccountSetupIncoming.
This commit is contained in:
parent
c7e46faf0a
commit
23f8d53178
@ -55,6 +55,11 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
URI uri = new URI(mAccount.getStoreUri());
|
URI uri = new URI(mAccount.getStoreUri());
|
||||||
uri = new URI("pop3", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
uri = new URI("pop3", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||||
mAccount.setStoreUri(uri.toString());
|
mAccount.setStoreUri(uri.toString());
|
||||||
|
|
||||||
|
uri = new URI(mAccount.getTransportUri());
|
||||||
|
uri = new URI("smtp", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||||
|
mAccount.setTransportUri(uri.toString());
|
||||||
|
|
||||||
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
||||||
finish();
|
finish();
|
||||||
} catch (Exception use) {
|
} catch (Exception use) {
|
||||||
@ -68,6 +73,11 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
|
|||||||
URI uri = new URI(mAccount.getStoreUri());
|
URI uri = new URI(mAccount.getStoreUri());
|
||||||
uri = new URI("imap", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
uri = new URI("imap", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||||
mAccount.setStoreUri(uri.toString());
|
mAccount.setStoreUri(uri.toString());
|
||||||
|
|
||||||
|
uri = new URI(mAccount.getTransportUri());
|
||||||
|
uri = new URI("smtp", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
|
||||||
|
mAccount.setTransportUri(uri.toString());
|
||||||
|
|
||||||
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
|
||||||
finish();
|
finish();
|
||||||
} catch (Exception use) {
|
} catch (Exception use) {
|
||||||
|
@ -19,12 +19,12 @@ import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
|||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
import com.fsck.k9.mail.AuthType;
|
import com.fsck.k9.mail.AuthType;
|
||||||
import com.fsck.k9.mail.ConnectionSecurity;
|
import com.fsck.k9.mail.ConnectionSecurity;
|
||||||
|
import com.fsck.k9.mail.ServerSettings;
|
||||||
|
import com.fsck.k9.mail.Transport;
|
||||||
|
import com.fsck.k9.mail.transport.SmtpTransport;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
|
|
||||||
public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||||
OnCheckedChangeListener {
|
OnCheckedChangeListener {
|
||||||
@ -35,9 +35,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
private static final String SMTP_PORT = "587";
|
private static final String SMTP_PORT = "587";
|
||||||
private static final String SMTP_SSL_PORT = "465";
|
private static final String SMTP_SSL_PORT = "465";
|
||||||
|
|
||||||
private static final String smtpSchemes[] = {
|
|
||||||
"smtp", "smtp+ssl", "smtp+ssl+", "smtp+tls", "smtp+tls+"
|
|
||||||
};
|
|
||||||
private EditText mUsernameView;
|
private EditText mUsernameView;
|
||||||
private EditText mPasswordView;
|
private EditText mPasswordView;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
@ -152,21 +149,9 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(mAccount.getTransportUri());
|
ServerSettings settings = Transport.decodeTransportUri(mAccount.getTransportUri());
|
||||||
String username = null;
|
String username = settings.username;
|
||||||
String password = null;
|
String password = settings.password;
|
||||||
String authType = null;
|
|
||||||
if (uri.getUserInfo() != null) {
|
|
||||||
String[] userInfoParts = uri.getUserInfo().split(":");
|
|
||||||
|
|
||||||
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
|
|
||||||
if (userInfoParts.length > 1) {
|
|
||||||
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
|
|
||||||
}
|
|
||||||
if (userInfoParts.length > 2) {
|
|
||||||
authType = userInfoParts[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (username != null) {
|
if (username != null) {
|
||||||
mUsernameView.setText(username);
|
mUsernameView.setText(username);
|
||||||
@ -177,17 +162,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
mPasswordView.setText(password);
|
mPasswordView.setText(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authType != null) {
|
// The first item is selected if settings.authenticationType is null or is not in mAuthTypeAdapter
|
||||||
int position = mAuthTypeAdapter.getPosition(AuthType.valueOf(authType));
|
int position = mAuthTypeAdapter.getPosition(settings.authenticationType);
|
||||||
mAuthTypeView.setSelection(position, false);
|
mAuthTypeView.setSelection(position, false);
|
||||||
}
|
|
||||||
|
|
||||||
// Select currently configured security type
|
// Select currently configured security type
|
||||||
for (int i = 0; i < smtpSchemes.length; i++) {
|
mSecurityTypeView.setSelection(settings.connectionSecurity.ordinal(), false);
|
||||||
if (smtpSchemes[i].equals(uri.getScheme())) {
|
|
||||||
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Updates the port when the user changes the security type. This allows
|
* Updates the port when the user changes the security type. This allows
|
||||||
@ -209,12 +189,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
public void onNothingSelected(AdapterView<?> parent) { /* unused */ }
|
public void onNothingSelected(AdapterView<?> parent) { /* unused */ }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (uri.getHost() != null) {
|
if (settings.host != null) {
|
||||||
mServerView.setText(uri.getHost());
|
mServerView.setText(settings.host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri.getPort() != -1) {
|
if (settings.port != -1) {
|
||||||
mPortView.setText(Integer.toString(uri.getPort()));
|
mPortView.setText(Integer.toString(settings.port));
|
||||||
} else {
|
} else {
|
||||||
updatePortFromSecurityType();
|
updatePortFromSecurityType();
|
||||||
}
|
}
|
||||||
@ -284,34 +264,25 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onNext() {
|
protected void onNext() {
|
||||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
ConnectionSecurity securityType = (ConnectionSecurity) mSecurityTypeView.getSelectedItem();
|
||||||
URI uri;
|
String uri;
|
||||||
try {
|
String username = null;
|
||||||
String usernameEnc = URLEncoder.encode(mUsernameView.getText().toString(), "UTF-8");
|
String password = null;
|
||||||
String passwordEnc = URLEncoder.encode(mPasswordView.getText().toString(), "UTF-8");
|
AuthType authType = null;
|
||||||
|
if (mRequireLoginView.isChecked()) {
|
||||||
String userInfo = null;
|
username = mUsernameView.getText().toString();
|
||||||
String authType = ((AuthType) mAuthTypeView.getSelectedItem()).name();
|
password = mPasswordView.getText().toString();
|
||||||
if (mRequireLoginView.isChecked()) {
|
authType = (AuthType) mAuthTypeView.getSelectedItem();
|
||||||
userInfo = usernameEnc + ":" + passwordEnc + ":" + authType;
|
|
||||||
}
|
|
||||||
String newHost = mServerView.getText().toString();
|
|
||||||
int newPort = Integer.parseInt(mPortView.getText().toString());
|
|
||||||
uri = new URI(smtpSchemes[securityType], userInfo, newHost, newPort, null, null, null);
|
|
||||||
mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING);
|
|
||||||
mAccount.setTransportUri(uri.toString());
|
|
||||||
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING);
|
|
||||||
} catch (UnsupportedEncodingException enc) {
|
|
||||||
// This really shouldn't happen since the encoding is hardcoded to UTF-8
|
|
||||||
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
|
|
||||||
} catch (Exception e) {
|
|
||||||
/*
|
|
||||||
* It's unrecoverable if we cannot create a URI from components that
|
|
||||||
* we validated to be safe.
|
|
||||||
*/
|
|
||||||
failure(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String newHost = mServerView.getText().toString();
|
||||||
|
int newPort = Integer.parseInt(mPortView.getText().toString());
|
||||||
|
String type = SmtpTransport.TRANSPORT_TYPE;
|
||||||
|
ServerSettings server = new ServerSettings(type, newHost, newPort, securityType, authType, username, password);
|
||||||
|
uri = Transport.createTransportUri(server);
|
||||||
|
mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING);
|
||||||
|
mAccount.setTransportUri(uri);
|
||||||
|
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
Loading…
Reference in New Issue
Block a user