User-IDs are identities that users go by. A User-ID might be a name, an email address or both. User-IDs can also contain both and even have a comment.
In general, the format of a User-ID is not fixed, so it can contain arbitrary strings. However, it is agreed upon to use the Below is a selection of possible User-IDs:
Firstname Lastname (Comment) <email@example.com> Firstname Lastname Firstname Lastname (Comment) <firstname.lastname@example.org>
PGPainless comes with a builder class
UserId, which can be used to safely construct User-IDs:
UserId nameAndEMail = UserId.nameAndEmail("Jane Doe", "email@example.com"); assertEquals("Jane Doe <firstname.lastname@example.org>", nameAndEmail.toString()): UserId onlyEmail = UserId.onlyEmail("email@example.com"); assertEquals("<firstname.lastname@example.org>", onlyEmail.toString()); UserId full = UserId.newBuilder() .withName("Peter Pattern") .withEmail("email@example.com") .withComment("Work Address") .build(); assertEquals("Peter Pattern (Work Address) <firstname.lastname@example.org>", full.toString());