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:
parent
6d8497a3c3
commit
373c7569ed
@ -14,7 +14,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@+id/password_prompt_incoming_server"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
@ -26,8 +32,10 @@
|
||||
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
|
||||
android:id="@+id/outgoing_server_prompt"
|
||||
android:orientation="vertical"
|
||||
|
@ -75,6 +75,7 @@ import com.fsck.k9.activity.setup.Prefs;
|
||||
import com.fsck.k9.activity.setup.WelcomeMessage;
|
||||
import com.fsck.k9.controller.MessagingController;
|
||||
import com.fsck.k9.helper.SizeFormatter;
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.Store;
|
||||
import com.fsck.k9.mail.Transport;
|
||||
@ -743,7 +744,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
public boolean retain() {
|
||||
if (mDialog != null) {
|
||||
// Retain entered passwords and checkbox state
|
||||
if (mIncomingPasswordView != null) {
|
||||
mIncomingPassword = mIncomingPasswordView.getText().toString();
|
||||
}
|
||||
if (mOutgoingPasswordView != null) {
|
||||
mOutgoingPassword = mOutgoingPasswordView.getText().toString();
|
||||
mUseIncoming = mUseIncomingView.isChecked();
|
||||
@ -770,9 +773,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
ServerSettings incoming = Store.decodeStoreUri(mAccount.getStoreUri());
|
||||
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.
|
||||
boolean configureOutgoingServer = !WebDavStore.STORE_TYPE.equals(outgoing.type);
|
||||
/*
|
||||
* Don't ask for the password to the outgoing server for WebDAV
|
||||
* 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
|
||||
final ScrollView scrollView = new ScrollView(activity);
|
||||
@ -785,7 +803,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
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;
|
||||
if (mOutgoingPasswordView != null) {
|
||||
outgoingPassword = (mUseIncomingView.isChecked()) ?
|
||||
@ -819,10 +840,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
TextView intro = (TextView) layout.findViewById(R.id.password_prompt_intro);
|
||||
String serverPasswords = activity.getResources().getQuantityString(
|
||||
R.plurals.settings_import_server_passwords,
|
||||
(configureOutgoingServer) ? 2 : 1);
|
||||
(configureIncomingServer && configureOutgoingServer) ? 2 : 1);
|
||||
intro.setText(activity.getString(R.string.settings_import_activate_account_intro,
|
||||
mAccount.getDescription(), serverPasswords));
|
||||
|
||||
if (configureIncomingServer) {
|
||||
// Display the hostname of the incoming server
|
||||
TextView incomingText = (TextView) layout.findViewById(
|
||||
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.addTextChangedListener(this);
|
||||
} else {
|
||||
layout.findViewById(R.id.incoming_server_prompt).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (configureOutgoingServer) {
|
||||
// Display the hostname of the outgoing server
|
||||
@ -845,6 +870,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
|
||||
mUseIncomingView = (CheckBox) layout.findViewById(
|
||||
R.id.use_incoming_server_password);
|
||||
|
||||
if (configureIncomingServer) {
|
||||
mUseIncomingView.setChecked(true);
|
||||
mUseIncomingView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
@ -858,6 +885,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mUseIncomingView.setChecked(false);
|
||||
mUseIncomingView.setVisibility(View.GONE);
|
||||
mOutgoingPasswordView.setEnabled(true);
|
||||
}
|
||||
} else {
|
||||
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
|
||||
// retained during a configuration change).
|
||||
if (restore) {
|
||||
if (configureIncomingServer) {
|
||||
mIncomingPasswordView.setText(mIncomingPassword);
|
||||
}
|
||||
if (configureOutgoingServer) {
|
||||
mOutgoingPasswordView.setText(mOutgoingPassword);
|
||||
mUseIncomingView.setChecked(mUseIncoming);
|
||||
}
|
||||
} else {
|
||||
if (configureIncomingServer) {
|
||||
// Trigger afterTextChanged() being called
|
||||
// Work around this bug: https://code.google.com/p/android/issues/detail?id=6360
|
||||
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) {
|
||||
boolean enable = false;
|
||||
// Is the password box for the incoming server password empty?
|
||||
if (mIncomingPasswordView != null) {
|
||||
if (mIncomingPasswordView.getText().length() > 0) {
|
||||
// Do we need to check the outgoing server password box?
|
||||
if (mOutgoingPasswordView == null) {
|
||||
@ -899,6 +938,9 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
enable = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enable = mOutgoingPasswordView.getText().length() > 0;
|
||||
}
|
||||
|
||||
// Disable "OK" button if the user hasn't specified all necessary passwords.
|
||||
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enable);
|
||||
@ -948,12 +990,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
try {
|
||||
if (mIncomingPassword != null) {
|
||||
// Set incoming server password
|
||||
String storeUri = mAccount.getStoreUri();
|
||||
ServerSettings incoming = Store.decodeStoreUri(storeUri);
|
||||
ServerSettings newIncoming = incoming.newPassword(mIncomingPassword);
|
||||
String newStoreUri = Store.createStoreUri(newIncoming);
|
||||
mAccount.setStoreUri(newStoreUri);
|
||||
}
|
||||
|
||||
if (mOutgoingPassword != null) {
|
||||
// Set outgoing server password
|
||||
|
@ -379,9 +379,11 @@ public class SettingsImporter {
|
||||
String storeUri = Store.createStoreUri(incoming);
|
||||
putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Utility.base64Encode(storeUri));
|
||||
|
||||
// Mark account as disabled if the settings file didn't contain a password
|
||||
boolean createAccountDisabled = (incoming.password == null ||
|
||||
incoming.password.isEmpty());
|
||||
// Mark account as disabled if the AuthType isn't EXTERNAL and the
|
||||
// settings file didn't contain a password
|
||||
boolean createAccountDisabled = !AuthType.EXTERNAL
|
||||
.equals(incoming.authenticationType)
|
||||
&& (incoming.password == null || incoming.password.isEmpty());
|
||||
|
||||
if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) {
|
||||
// All account types except WebDAV need to provide outgoing server settings
|
||||
@ -394,8 +396,19 @@ public class SettingsImporter {
|
||||
String transportUri = Transport.createTransportUri(outgoing);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user