mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 09:42:16 -05:00
allow blank names and emails
This commit is contained in:
parent
603665976a
commit
a5aae930e5
@ -20,6 +20,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.Editable;
|
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])?",
|
"[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);
|
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) {
|
public void setCanEdit(boolean bCanEdit) {
|
||||||
if (!bCanEdit) {
|
if (!bCanEdit) {
|
||||||
mDeleteButton.setVisibility(View.INVISIBLE);
|
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 {
|
public static class InvalidEmailException extends Exception {
|
||||||
static final long serialVersionUID = 0xf812773345L;
|
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) {
|
public void setValue(String userId, boolean isMainID, boolean isNewId) {
|
||||||
|
|
||||||
mName.setText("");
|
mName.setText("");
|
||||||
mComment.setText("");
|
mComment.setText("");
|
||||||
mEmail.setText("");
|
mEmail.setText("");
|
||||||
mIsNewId = isNewId;
|
mIsNewId = isNewId;
|
||||||
|
|
||||||
//TODO: update this file for blank email/name?
|
String[] result = PgpKeyHelper.splitUserId(userId);
|
||||||
|
if (result[0] != null) {
|
||||||
Pattern withComment = Pattern.compile("^(.*) [(](.*)[)] <(.*)>$");
|
mName.setText(result[0]);
|
||||||
Matcher matcher = withComment.matcher(userId);
|
mOriginalName = result[0];
|
||||||
if (matcher.matches()) {
|
}
|
||||||
mName.setText(matcher.group(1));
|
if (result[1] != null) {
|
||||||
mOriginalName = matcher.group(1);
|
mComment.setText(result[1]);
|
||||||
mComment.setText(matcher.group(2));
|
mOriginalComment = result[1];
|
||||||
mOriginalComment = matcher.group(2);
|
}
|
||||||
mEmail.setText(matcher.group(3));
|
if (result[2] != null) {
|
||||||
mOriginalEmail = matcher.group(3);
|
mEmail.setText(result[2]);
|
||||||
return;
|
mOriginalEmail = result[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
mOriginallyMainUserID = isMainID;
|
mOriginallyMainUserID = isMainID;
|
||||||
setIsMainUserId(isMainID);
|
setIsMainUserId(isMainID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() throws NoNameException, NoEmailException, InvalidEmailException {
|
public String getValue() throws InvalidEmailException {
|
||||||
String name = ("" + mName.getText()).trim();
|
String name = ("" + mName.getText()).trim();
|
||||||
String email = ("" + mEmail.getText()).trim();
|
String email = ("" + mEmail.getText()).trim();
|
||||||
String comment = ("" + mComment.getText()).trim();
|
String comment = ("" + mComment.getText()).trim();
|
||||||
@ -191,16 +167,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
|||||||
// ok, empty one...
|
// ok, empty one...
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
//TODO: check gpg accepts an entirely empty ID packet. specs say this is allowed
|
||||||
// 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +177,7 @@ public class UserIdEditor extends LinearLayout implements Editor, OnClickListene
|
|||||||
boolean wasMainUserId = mIsMainUserId.isChecked();
|
boolean wasMainUserId = mIsMainUserId.isChecked();
|
||||||
parent.removeView(this);
|
parent.removeView(this);
|
||||||
if (mEditorListener != null) {
|
if (mEditorListener != null) {
|
||||||
mEditorListener.onDeleted(this, false); //TODO: WAS THIS A NEW ITEM
|
mEditorListener.onDeleted(this, mIsNewId);
|
||||||
}
|
}
|
||||||
if (wasMainUserId && parent.getChildCount() > 0) {
|
if (wasMainUserId && parent.getChildCount() > 0) {
|
||||||
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);
|
UserIdEditor editor = (UserIdEditor) parent.getChildAt(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user