diff options
author | mar-v-in <github@rvin.mooo.com> | 2014-06-05 23:56:29 +0200 |
---|---|---|
committer | mar-v-in <github@rvin.mooo.com> | 2014-06-05 23:56:29 +0200 |
commit | e2164f571ed80928527cfdebaf3e2655350e9471 (patch) | |
tree | 4d74a1726a6281fc582e215804499900bda8cbf4 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java | |
parent | 36312b950aa2e3150ec9381c91850c63ed1c604b (diff) | |
parent | 255462def4830fa6ad3f7ab164d207501dbed36c (diff) | |
download | open-keychain-e2164f571ed80928527cfdebaf3e2655350e9471.tar.gz open-keychain-e2164f571ed80928527cfdebaf3e2655350e9471.tar.bz2 open-keychain-e2164f571ed80928527cfdebaf3e2655350e9471.zip |
Merge branch 'master' into automatic-contact-discovery
Conflicts:
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java
OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java index dc0c722b9..47b827677 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java @@ -2,6 +2,9 @@ package org.sufficientlysecure.keychain.pgp; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** An abstract KeyRing. * * This is an abstract class for all KeyRing constructs. It serves as a common @@ -19,6 +22,10 @@ public abstract class KeyRing { abstract public String getPrimaryUserId() throws PgpGeneralException; + public String[] getSplitPrimaryUserId() throws PgpGeneralException { + return splitUserId(getPrimaryUserId()); + } + abstract public boolean isRevoked() throws PgpGeneralException; abstract public boolean canCertify() throws PgpGeneralException; @@ -33,4 +40,39 @@ public abstract class KeyRing { abstract public int getVerified() throws PgpGeneralException; + private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); + + /** + * Splits userId string into naming part, email part, and comment part + * + * @param userId + * @return array with naming (0), email (1), comment (2) + */ + public static String[] splitUserId(String userId) { + String[] result = new String[]{null, null, null}; + + if (userId == null || userId.equals("")) { + return result; + } + + /* + * User ID matching: + * http://fiddle.re/t4p6f + * + * test cases: + * "Max Mustermann (this is a comment) <max@example.com>" + * "Max Mustermann <max@example.com>" + * "Max Mustermann (this is a comment)" + * "Max Mustermann [this is nothing]" + */ + Matcher matcher = USER_ID_PATTERN.matcher(userId); + if (matcher.matches()) { + result[0] = matcher.group(1); + result[1] = matcher.group(3); + result[2] = matcher.group(2); + } + + return result; + } + } |