1
0
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:
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 {
@ -75,11 +76,22 @@ public class Utility {
public static boolean requiredFieldValid(TextView view) {
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);
}
@ -301,31 +303,32 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
}
private void onNext() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
try {
String path = null;
if (mAccountSchemes[securityType].startsWith("imap")) {
path = "/" + mImapPathPrefixView.getText();
}
URI uri = new URI(
mAccountSchemes[securityType],
mUsernameView.getText() + ":" + mPasswordView.getText(),
mServerView.getText().toString(),
Integer.parseInt(mPortView.getText().toString()),
path, // path
null, // query
null);
mAccount.setStoreUri(uri.toString());
} catch (URISyntaxException use) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
throw new Error(use);
}
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
try {
String path = null;
if (mAccountSchemes[securityType].startsWith("imap")) {
path = "/" + mImapPathPrefixView.getText();
}
URI uri = new URI(
mAccountSchemes[securityType],
mUsernameView.getText() + ":" + mPasswordView.getText(),
mServerView.getText().toString(),
Integer.parseInt(mPortView.getText().toString()),
path, // path
null, // query
null);
mAccount.setStoreUri(uri.toString());
} catch (URISyntaxException use) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
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) {

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) &&