aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget
diff options
context:
space:
mode:
authorAshley Hughes <spirit.returned@gmail.com>2014-02-06 13:28:59 +0000
committerAshley Hughes <spirit.returned@gmail.com>2014-02-06 13:28:59 +0000
commita5aae930e5e857005563c21fb2c7ca86d6e235da (patch)
tree33b2e1058a0ea98137783d6a0ca204cd5450e51b /OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget
parent603665976a3a75918fb9838361b7194c5def6968 (diff)
downloadopen-keychain-a5aae930e5e857005563c21fb2c7ca86d6e235da.tar.gz
open-keychain-a5aae930e5e857005563c21fb2c7ca86d6e235da.tar.bz2
open-keychain-a5aae930e5e857005563c21fb2c7ca86d6e235da.zip
allow blank names and emails
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java67
1 files changed, 17 insertions, 50 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java
index 0509e69f2..641b710a9 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/UserIdEditor.java
@@ -20,6 +20,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import android.content.Context;
import android.text.Editable;
@@ -56,14 +57,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
Pattern.CASE_INSENSITIVE);
- public static class NoNameException extends Exception {
- static final long serialVersionUID = 0xf812773343L;
-
- public NoNameException(String message) {
- super(message);
- }
- }
-
public void setCanEdit(boolean bCanEdit) {
if (!bCanEdit) {
mDeleteButton.setVisibility(View.INVISIBLE);
@@ -74,14 +67,6 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
}
}
- public static class NoEmailException extends Exception {
- static final long serialVersionUID = 0xf812773344L;
-
- public NoEmailException(String message) {
- super(message);
- }
- }
-
public static class InvalidEmailException extends Exception {
static final long serialVersionUID = 0xf812773345L;
@@ -133,40 +118,31 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
}
public void setValue(String userId, boolean isMainID, boolean isNewId) {
+
mName.setText("");
mComment.setText("");
mEmail.setText("");
mIsNewId = isNewId;
- //TODO: update this file for blank email/name?
-
- Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$");
- Matcher matcher = withComment.matcher(userId);
- if (matcher.matches()) {
- mName.setText(matcher.group(1));
- mOriginalName = matcher.group(1);
- mComment.setText(matcher.group(2));
- mOriginalComment = matcher.group(2);
- mEmail.setText(matcher.group(3));
- mOriginalEmail = matcher.group(3);
- return;
+ String[] result = PgpKeyHelper.splitUserId(userId);
+ if (result[0] != null) {
+ mName.setText(result[0]);
+ mOriginalName = result[0];
}
-
- Pattern withoutComment = Pattern.compile("^(.*) <(.*)>$");
- matcher = withoutComment.matcher(userId);
- if (matcher.matches()) {
- mName.setText(matcher.group(1));
- mOriginalName = matcher.group(1);
- mEmail.setText(matcher.group(2));
- mOriginalEmail = matcher.group(2);
- mOriginalComment = "";
- return;
+ if (result[1] != null) {
+ mComment.setText(result[1]);
+ mOriginalComment = result[1];
+ }
+ if (result[2] != null) {
+ mEmail.setText(result[2]);
+ mOriginalEmail = result[2];
}
+
mOriginallyMainUserID = isMainID;
setIsMainUserId(isMainID);
}
- public String getValue() throws NoNameException, NoEmailException, InvalidEmailException {
+ public String getValue() throws InvalidEmailException {
String name = ("" + mName.getText()).trim();
String email = ("" + mEmail.getText()).trim();
String comment = ("" + mComment.getText()).trim();
@@ -191,16 +167,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
// ok, empty one...
return userId;
}
-
- // otherwise make sure that name and email exist
- if (name.equals("")) {
- throw new NoNameException("need a name");
- }
-
- if (email.equals("")) {
- throw new NoEmailException("need an email");
- }
-
+ //TODO: check gpg accepts an entirely empty ID packet. specs say this is allowed
return userId;
}
@@ -210,7 +177,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
boolean wasMainUserId = mIsMainUserId.isChecked();
parent.removeView(this);
if (mEditorListener != null) {
- mEditorListener.onDeleted(this, false); //TODO: WAS THIS A NEW ITEM
+ mEditorListener.onDeleted(this, mIsNewId);
}
if (wasMainUserId && parent.getChildCount() > 0) {
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);