1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -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,7 +14,13 @@
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
user names or accounts with AuthType EXTERNAL! -->
<LinearLayout
android:id="@+id/incoming_server_prompt"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/password_prompt_incoming_server" android:id="@+id/password_prompt_incoming_server"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
@ -26,8 +32,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_marginBottom="10dip"/> 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
if (mIncomingPasswordView != null) {
mIncomingPassword = mIncomingPasswordView.getText().toString(); 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()) ?
@ -819,10 +840,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
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));
if (configureIncomingServer) {
// Display the hostname of the incoming server // Display the hostname of the incoming server
TextView incomingText = (TextView) layout.findViewById( TextView incomingText = (TextView) layout.findViewById(
R.id.password_prompt_incoming_server); R.id.password_prompt_incoming_server);
@ -831,6 +853,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
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
@ -845,6 +870,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
mUseIncomingView = (CheckBox) layout.findViewById( mUseIncomingView = (CheckBox) layout.findViewById(
R.id.use_incoming_server_password); R.id.use_incoming_server_password);
if (configureIncomingServer) {
mUseIncomingView.setChecked(true); mUseIncomingView.setChecked(true);
mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() { mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
@ -858,6 +885,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
} }
} }
}); });
} 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) {
if (configureIncomingServer) {
mIncomingPasswordView.setText(mIncomingPassword); mIncomingPasswordView.setText(mIncomingPassword);
}
if (configureOutgoingServer) { if (configureOutgoingServer) {
mOutgoingPasswordView.setText(mOutgoingPassword); mOutgoingPasswordView.setText(mOutgoingPassword);
mUseIncomingView.setChecked(mUseIncoming); mUseIncomingView.setChecked(mUseIncoming);
} }
} else { } else {
if (configureIncomingServer) {
// Trigger afterTextChanged() being called // Trigger afterTextChanged() being called
// Work around this bug: https://code.google.com/p/android/issues/detail?id=6360 // Work around this bug: https://code.google.com/p/android/issues/detail?id=6360
mIncomingPasswordView.setText(mIncomingPasswordView.getText()); mIncomingPasswordView.setText(mIncomingPasswordView.getText());
} else {
mOutgoingPasswordView.setText(mOutgoingPasswordView.getText());
}
} }
} }
@ -887,6 +925,7 @@ 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 != null) {
if (mIncomingPasswordView.getText().length() > 0) { if (mIncomingPasswordView.getText().length() > 0) {
// Do we need to check the outgoing server password box? // Do we need to check the outgoing server password box?
if (mOutgoingPasswordView == null) { if (mOutgoingPasswordView == null) {
@ -899,6 +938,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
enable = true; 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.
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enable); mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enable);
@ -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 {
if (mIncomingPassword != null) {
// Set incoming server password // Set incoming server password
String storeUri = mAccount.getStoreUri(); String storeUri = mAccount.getStoreUri();
ServerSettings incoming = Store.decodeStoreUri(storeUri); ServerSettings incoming = Store.decodeStoreUri(storeUri);
ServerSettings newIncoming = incoming.newPassword(mIncomingPassword); ServerSettings newIncoming = incoming.newPassword(mIncomingPassword);
String newStoreUri = Store.createStoreUri(newIncoming); String newStoreUri = Store.createStoreUri(newIncoming);
mAccount.setStoreUri(newStoreUri); 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;
} }
} }