mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 03:32:16 -05:00
block server entries in AccountSetupIncoming.java and AccountSetupOutgoing.java that are not valid domain names.
This commit is contained in:
parent
b877a52b01
commit
171648aa41
@ -10,6 +10,7 @@ import java.util.Date;
|
|||||||
import com.fsck.k9.codec.binary.Base64;
|
import com.fsck.k9.codec.binary.Base64;
|
||||||
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class Utility {
|
public class Utility {
|
||||||
@ -75,11 +76,22 @@ public class Utility {
|
|||||||
public static boolean requiredFieldValid(TextView view) {
|
public static boolean requiredFieldValid(TextView view) {
|
||||||
return view.getText() != null && view.getText().length() > 0;
|
return view.getText() != null && view.getText().length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean requiredFieldValid(Editable s) {
|
public static boolean requiredFieldValid(Editable s) {
|
||||||
return s != null && s.length() > 0;
|
return s != null && s.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean domainFieldValid(EditText view) {
|
||||||
|
if (view.getText() != null) {
|
||||||
|
String s = view.getText().toString();
|
||||||
|
if (s.matches("^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}$")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the given string starts and ends with the double quote character. The string is not modified in any way except to add the
|
* Ensures that the given string starts and ends with the double quote character. The string is not modified in any way except to add the
|
||||||
* double quote character to start and end if it's not already there.
|
* double quote character to start and end if it's not already there.
|
||||||
@ -173,4 +185,5 @@ public class Utility {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import java.net.URI;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -254,7 +256,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
|
|||||||
mNextButton
|
mNextButton
|
||||||
.setEnabled(Utility.requiredFieldValid(mUsernameView)
|
.setEnabled(Utility.requiredFieldValid(mUsernameView)
|
||||||
&& Utility.requiredFieldValid(mPasswordView)
|
&& Utility.requiredFieldValid(mPasswordView)
|
||||||
&& Utility.requiredFieldValid(mServerView)
|
&& Utility.domainFieldValid(mServerView)
|
||||||
&& Utility.requiredFieldValid(mPortView));
|
&& Utility.requiredFieldValid(mPortView));
|
||||||
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
|
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
|
||||||
}
|
}
|
||||||
@ -301,31 +303,32 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onNext() {
|
private void onNext() {
|
||||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||||
try {
|
try {
|
||||||
String path = null;
|
String path = null;
|
||||||
if (mAccountSchemes[securityType].startsWith("imap")) {
|
if (mAccountSchemes[securityType].startsWith("imap")) {
|
||||||
path = "/" + mImapPathPrefixView.getText();
|
path = "/" + mImapPathPrefixView.getText();
|
||||||
}
|
}
|
||||||
URI uri = new URI(
|
URI uri = new URI(
|
||||||
mAccountSchemes[securityType],
|
mAccountSchemes[securityType],
|
||||||
mUsernameView.getText() + ":" + mPasswordView.getText(),
|
mUsernameView.getText() + ":" + mPasswordView.getText(),
|
||||||
mServerView.getText().toString(),
|
mServerView.getText().toString(),
|
||||||
Integer.parseInt(mPortView.getText().toString()),
|
Integer.parseInt(mPortView.getText().toString()),
|
||||||
path, // path
|
path, // path
|
||||||
null, // query
|
null, // query
|
||||||
null);
|
null);
|
||||||
mAccount.setStoreUri(uri.toString());
|
mAccount.setStoreUri(uri.toString());
|
||||||
} catch (URISyntaxException use) {
|
} catch (URISyntaxException use) {
|
||||||
/*
|
/*
|
||||||
* It's unrecoverable if we cannot create a URI from components that
|
* It's unrecoverable if we cannot create a URI from components that
|
||||||
* we validated to be safe.
|
* we validated to be safe.
|
||||||
*/
|
*/
|
||||||
throw new Error(use);
|
throw new Error(use);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAccount.setDeletePolicy((Integer)((SpinnerOption)mDeletePolicyView.getSelectedItem()).value);
|
||||||
|
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
|
||||||
|
|
||||||
mAccount.setDeletePolicy((Integer)((SpinnerOption)mDeletePolicyView.getSelectedItem()).value);
|
|
||||||
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -222,7 +222,7 @@ public class AccountSetupOutgoing extends Activity implements OnClickListener,
|
|||||||
private void validateFields() {
|
private void validateFields() {
|
||||||
mNextButton
|
mNextButton
|
||||||
.setEnabled(
|
.setEnabled(
|
||||||
Utility.requiredFieldValid(mServerView) &&
|
Utility.domainFieldValid(mServerView) &&
|
||||||
Utility.requiredFieldValid(mPortView) &&
|
Utility.requiredFieldValid(mPortView) &&
|
||||||
(!mRequireLoginView.isChecked() ||
|
(!mRequireLoginView.isChecked() ||
|
||||||
(Utility.requiredFieldValid(mUsernameView) &&
|
(Utility.requiredFieldValid(mUsernameView) &&
|
||||||
|
Loading…
Reference in New Issue
Block a user