1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 05:02:26 -05:00

block server entries in AccountSetupIncoming.java and AccountSetupOutgoing.java that are not valid domain names.

This commit is contained in:
Bradley Young 2008-12-16 23:54:02 +00:00
parent b877a52b01
commit 171648aa41
3 changed files with 42 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import java.util.Date;
import com.fsck.k9.codec.binary.Base64;
import android.text.Editable;
import android.widget.EditText;
import android.widget.TextView;
public class Utility {
@ -76,10 +77,21 @@ public class Utility {
return view.getText() != null && view.getText().length() > 0;
}
public static boolean requiredFieldValid(Editable s) {
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
* double quote character to start and end if it's not already there.
@ -173,4 +185,5 @@ public class Utility {
// }
// }
}
}

View File

@ -5,6 +5,8 @@ import java.net.URI;
import java.net.URISyntaxException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
@ -254,7 +256,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
mNextButton
.setEnabled(Utility.requiredFieldValid(mUsernameView)
&& Utility.requiredFieldValid(mPasswordView)
&& Utility.requiredFieldValid(mServerView)
&& Utility.domainFieldValid(mServerView)
&& Utility.requiredFieldValid(mPortView));
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
@ -326,6 +328,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
mAccount.setDeletePolicy((Integer)((SpinnerOption)mDeletePolicyView.getSelectedItem()).value);
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
}
public void onClick(View v) {

View File

@ -222,7 +222,7 @@ public class AccountSetupOutgoing extends Activity implements OnClickListener,
private void validateFields() {
mNextButton
.setEnabled(
Utility.requiredFieldValid(mServerView) &&
Utility.domainFieldValid(mServerView) &&
Utility.requiredFieldValid(mPortView) &&
(!mRequireLoginView.isChecked() ||
(Utility.requiredFieldValid(mUsernameView) &&