1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Fix password prompts on account import

Don't prompt if server's AuthType == EXTERNAL

Don't prompt for SMTP servers that don't require authentication
(no user name).
This commit is contained in:
Joe Steele 2014-07-14 20:47:26 -04:00
parent 6d8497a3c3
commit 373c7569ed
3 changed files with 129 additions and 64 deletions

View File

@ -14,20 +14,28 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15dip"/> android:layout_marginBottom="15dip"/>
<!-- Password prompt for the incoming server --> <!-- Password prompt for the incoming server. Won't be shown for accounts without
<TextView user names or accounts with AuthType EXTERNAL! -->
android:id="@+id/password_prompt_incoming_server" <LinearLayout
android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/incoming_server_prompt"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/incoming_server_password"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_marginBottom="10dip"/> android:layout_height="wrap_content">
<TextView
android:id="@+id/password_prompt_incoming_server"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/incoming_server_password"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginBottom="10dip"/>
</LinearLayout>
<!-- Password prompt for the outgoing server. Won't be shown for WebDAV accounts! --> <!-- Password prompt for the outgoing server. Won't be shown for WebDAV accounts,
accounts without user names, or accounts with AuthType EXTERNAL! -->
<LinearLayout <LinearLayout
android:id="@+id/outgoing_server_prompt" android:id="@+id/outgoing_server_prompt"
android:orientation="vertical" android:orientation="vertical"

View File

@ -75,6 +75,7 @@ import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.activity.setup.WelcomeMessage; import com.fsck.k9.activity.setup.WelcomeMessage;
import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.helper.SizeFormatter; import com.fsck.k9.helper.SizeFormatter;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.Transport;
@ -743,7 +744,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
public boolean retain() { public boolean retain() {
if (mDialog != null) { if (mDialog != null) {
// Retain entered passwords and checkbox state // Retain entered passwords and checkbox state
mIncomingPassword = mIncomingPasswordView.getText().toString(); if (mIncomingPasswordView != null) {
mIncomingPassword = mIncomingPasswordView.getText().toString();
}
if (mOutgoingPasswordView != null) { if (mOutgoingPasswordView != null) {
mOutgoingPassword = mOutgoingPasswordView.getText().toString(); mOutgoingPassword = mOutgoingPasswordView.getText().toString();
mUseIncoming = mUseIncomingView.isChecked(); mUseIncoming = mUseIncomingView.isChecked();
@ -770,9 +773,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
ServerSettings incoming = Store.decodeStoreUri(mAccount.getStoreUri()); ServerSettings incoming = Store.decodeStoreUri(mAccount.getStoreUri());
ServerSettings outgoing = Transport.decodeTransportUri(mAccount.getTransportUri()); ServerSettings outgoing = Transport.decodeTransportUri(mAccount.getTransportUri());
// Don't ask for the password to the outgoing server for WebDAV accounts, because /*
// incoming and outgoing servers are identical for this account type. * Don't ask for the password to the outgoing server for WebDAV
boolean configureOutgoingServer = !WebDavStore.STORE_TYPE.equals(outgoing.type); * accounts, because incoming and outgoing servers are identical for
* this account type. Also don't ask when the username is missing.
* Also don't ask when the AuthType is EXTERNAL.
*/
boolean configureOutgoingServer = !AuthType.EXTERNAL
.equals(outgoing.authenticationType)
&& !WebDavStore.STORE_TYPE.equals(outgoing.type)
&& outgoing.username != null
&& !outgoing.username.isEmpty()
&& (outgoing.password == null || outgoing.password
.isEmpty());
boolean configureIncomingServer = !AuthType.EXTERNAL
.equals(incoming.authenticationType)
&& (incoming.password == null || incoming.password
.isEmpty());
// Create a ScrollView that will be used as container for the whole layout // Create a ScrollView that will be used as container for the whole layout
final ScrollView scrollView = new ScrollView(activity); final ScrollView scrollView = new ScrollView(activity);
@ -785,7 +803,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String incomingPassword = mIncomingPasswordView.getText().toString(); String incomingPassword = null;
if (mIncomingPasswordView != null) {
incomingPassword = mIncomingPasswordView.getText().toString();
}
String outgoingPassword = null; String outgoingPassword = null;
if (mOutgoingPasswordView != null) { if (mOutgoingPasswordView != null) {
outgoingPassword = (mUseIncomingView.isChecked()) ? outgoingPassword = (mUseIncomingView.isChecked()) ?
@ -818,19 +839,23 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// Set the intro text that tells the user what to do // Set the intro text that tells the user what to do
TextView intro = (TextView) layout.findViewById(R.id.password_prompt_intro); TextView intro = (TextView) layout.findViewById(R.id.password_prompt_intro);
String serverPasswords = activity.getResources().getQuantityString( String serverPasswords = activity.getResources().getQuantityString(
R.plurals.settings_import_server_passwords, R.plurals.settings_import_server_passwords,
(configureOutgoingServer) ? 2 : 1); (configureIncomingServer && configureOutgoingServer) ? 2 : 1);
intro.setText(activity.getString(R.string.settings_import_activate_account_intro, intro.setText(activity.getString(R.string.settings_import_activate_account_intro,
mAccount.getDescription(), serverPasswords)); mAccount.getDescription(), serverPasswords));
// Display the hostname of the incoming server if (configureIncomingServer) {
TextView incomingText = (TextView) layout.findViewById( // Display the hostname of the incoming server
R.id.password_prompt_incoming_server); TextView incomingText = (TextView) layout.findViewById(
incomingText.setText(activity.getString(R.string.settings_import_incoming_server, R.id.password_prompt_incoming_server);
incoming.host)); incomingText.setText(activity.getString(R.string.settings_import_incoming_server,
incoming.host));
mIncomingPasswordView = (EditText) layout.findViewById(R.id.incoming_server_password); mIncomingPasswordView = (EditText) layout.findViewById(R.id.incoming_server_password);
mIncomingPasswordView.addTextChangedListener(this); mIncomingPasswordView.addTextChangedListener(this);
} else {
layout.findViewById(R.id.incoming_server_prompt).setVisibility(View.GONE);
}
if (configureOutgoingServer) { if (configureOutgoingServer) {
// Display the hostname of the outgoing server // Display the hostname of the outgoing server
@ -844,20 +869,27 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
mOutgoingPasswordView.addTextChangedListener(this); mOutgoingPasswordView.addTextChangedListener(this);
mUseIncomingView = (CheckBox) layout.findViewById( mUseIncomingView = (CheckBox) layout.findViewById(
R.id.use_incoming_server_password); R.id.use_incoming_server_password);
mUseIncomingView.setChecked(true);
mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() { if (configureIncomingServer) {
@Override mUseIncomingView.setChecked(true);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
if (isChecked) { @Override
mOutgoingPasswordView.setText(null); public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mOutgoingPasswordView.setEnabled(false); if (isChecked) {
} else { mOutgoingPasswordView.setText(null);
mOutgoingPasswordView.setText(mIncomingPasswordView.getText()); mOutgoingPasswordView.setEnabled(false);
mOutgoingPasswordView.setEnabled(true); } else {
mOutgoingPasswordView.setText(mIncomingPasswordView.getText());
mOutgoingPasswordView.setEnabled(true);
}
} }
} });
}); } else {
mUseIncomingView.setChecked(false);
mUseIncomingView.setVisibility(View.GONE);
mOutgoingPasswordView.setEnabled(true);
}
} else { } else {
layout.findViewById(R.id.outgoing_server_prompt).setVisibility(View.GONE); layout.findViewById(R.id.outgoing_server_prompt).setVisibility(View.GONE);
} }
@ -871,15 +903,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
// Restore the contents of the password boxes and the checkbox (if the dialog was // Restore the contents of the password boxes and the checkbox (if the dialog was
// retained during a configuration change). // retained during a configuration change).
if (restore) { if (restore) {
mIncomingPasswordView.setText(mIncomingPassword); if (configureIncomingServer) {
mIncomingPasswordView.setText(mIncomingPassword);
}
if (configureOutgoingServer) { if (configureOutgoingServer) {
mOutgoingPasswordView.setText(mOutgoingPassword); mOutgoingPasswordView.setText(mOutgoingPassword);
mUseIncomingView.setChecked(mUseIncoming); mUseIncomingView.setChecked(mUseIncoming);
} }
} else { } else {
// Trigger afterTextChanged() being called if (configureIncomingServer) {
// Work around this bug: https://code.google.com/p/android/issues/detail?id=6360 // Trigger afterTextChanged() being called
mIncomingPasswordView.setText(mIncomingPasswordView.getText()); // Work around this bug: https://code.google.com/p/android/issues/detail?id=6360
mIncomingPasswordView.setText(mIncomingPasswordView.getText());
} else {
mOutgoingPasswordView.setText(mOutgoingPasswordView.getText());
}
} }
} }
@ -887,17 +925,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
public void afterTextChanged(Editable arg0) { public void afterTextChanged(Editable arg0) {
boolean enable = false; boolean enable = false;
// Is the password box for the incoming server password empty? // Is the password box for the incoming server password empty?
if (mIncomingPasswordView.getText().length() > 0) { if (mIncomingPasswordView != null) {
// Do we need to check the outgoing server password box? if (mIncomingPasswordView.getText().length() > 0) {
if (mOutgoingPasswordView == null) { // Do we need to check the outgoing server password box?
enable = true; if (mOutgoingPasswordView == null) {
} enable = true;
// If the checkbox to use the incoming server password is checked we need to make }
// sure that the password box for the outgoing server isn't empty. // If the checkbox to use the incoming server password is checked we need to make
else if (mUseIncomingView.isChecked() || // sure that the password box for the outgoing server isn't empty.
mOutgoingPasswordView.getText().length() > 0) { else if (mUseIncomingView.isChecked() ||
enable = true; mOutgoingPasswordView.getText().length() > 0) {
enable = true;
}
} }
} else {
enable = mOutgoingPasswordView.getText().length() > 0;
} }
// Disable "OK" button if the user hasn't specified all necessary passwords. // Disable "OK" button if the user hasn't specified all necessary passwords.
@ -948,12 +990,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
try { try {
// Set incoming server password if (mIncomingPassword != null) {
String storeUri = mAccount.getStoreUri(); // Set incoming server password
ServerSettings incoming = Store.decodeStoreUri(storeUri); String storeUri = mAccount.getStoreUri();
ServerSettings newIncoming = incoming.newPassword(mIncomingPassword); ServerSettings incoming = Store.decodeStoreUri(storeUri);
String newStoreUri = Store.createStoreUri(newIncoming); ServerSettings newIncoming = incoming.newPassword(mIncomingPassword);
mAccount.setStoreUri(newStoreUri); String newStoreUri = Store.createStoreUri(newIncoming);
mAccount.setStoreUri(newStoreUri);
}
if (mOutgoingPassword != null) { if (mOutgoingPassword != null) {
// Set outgoing server password // Set outgoing server password

View File

@ -379,9 +379,11 @@ public class SettingsImporter {
String storeUri = Store.createStoreUri(incoming); String storeUri = Store.createStoreUri(incoming);
putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Utility.base64Encode(storeUri)); putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Utility.base64Encode(storeUri));
// Mark account as disabled if the settings file didn't contain a password // Mark account as disabled if the AuthType isn't EXTERNAL and the
boolean createAccountDisabled = (incoming.password == null || // settings file didn't contain a password
incoming.password.isEmpty()); boolean createAccountDisabled = !AuthType.EXTERNAL
.equals(incoming.authenticationType)
&& (incoming.password == null || incoming.password.isEmpty());
if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) { if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) {
// All account types except WebDAV need to provide outgoing server settings // All account types except WebDAV need to provide outgoing server settings
@ -394,8 +396,19 @@ public class SettingsImporter {
String transportUri = Transport.createTransportUri(outgoing); String transportUri = Transport.createTransportUri(outgoing);
putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri)); putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri));
// Mark account as disabled if the settings file didn't contain a password /*
if (outgoing.password == null || outgoing.password.isEmpty()) { * Mark account as disabled if the settings file contained a
* username but no password. However, no password is required for
* the outgoing server for WebDAV accounts, because incoming and
* outgoing servers are identical for this account type. Nor is a
* password required if the AuthType is EXTERNAL.
*/
if (!AuthType.EXTERNAL.equals(outgoing.authenticationType)
&& !WebDavStore.STORE_TYPE.equals(outgoing.type)
&& outgoing.username != null
&& !outgoing.username.isEmpty()
&& (outgoing.password == null || outgoing.password
.isEmpty())) {
createAccountDisabled = true; createAccountDisabled = true;
} }
} }