@ThreadSafe public class IDPair extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static IDPair |
NOBODY
An ID pair for a non-existent user.
|
Modifier | Constructor and Description |
---|---|
protected |
IDPair(IDPair other)
Constructs an IDPair by copying from another.
|
|
IDPair(String _email,
String _username,
boolean _isFromEmail)
Constructs an IDPair.
|
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
appendUsername(String email,
StringBuilder b)
Translates an email address to a mailish username, and appends the result to the
specified string builder.
|
static StringBuilder |
buildUserMnemonic(String username,
StringBuilder sB)
Appends a short abbreviation of the username to the string builder.
|
String |
email()
Identifies the user by canonical email address.
|
static String |
emailOrNobody(String email,
ResourceBundle resA)
Returns the same email address; or, if it is null or NOBODY,
the localized string for "nobody".
|
boolean |
equals(Object o)
True iff o is an ID pair constructed from the same (equals) email address.
|
boolean |
equalsEmail(Object o)
Returns true iff o is an ID pair with the same email address.
|
static IDPair |
fromEmail(String email)
Constructs an IDPair from a canonical email address.
|
static IDPair |
fromUsername(String username)
Constructs an IDPair from a username, which will automatically be translated to
normal form.
|
boolean |
isFromEmail()
Deprecated.
as an unecessary complexity and source of potential bugs.
|
static String |
normalUsername(String name)
Translates the mailish username to normal form by shifting the first letter to
uppercase and substituting spaces for underscores.
|
static InternetAddress |
toInternetAddress(String username)
Translates a username to a canonical email address.
|
String |
toString()
Returns the same identifier from which the ID pair was constructed.
|
static String |
toUsername(String email)
Translates a canonical email address to a mailish username in normal form.
|
String |
username()
Identifies the user by mailish username.
|
public IDPair(String _email, String _username, boolean _isFromEmail)
email()
,
username()
,
isFromEmail()
public static IDPair fromEmail(String email)
email()
,
InternetAddressX.canonicalAddress(String)
public static IDPair fromUsername(String username) throws AddressException
AddressException
username()
public static StringBuilder appendUsername(String email, StringBuilder b)
Email address Mailish username ----------------------- ------------------------------ Smith@acme.com Smith AcmeCom smith@acme.com Smith-AcmeCom ThomasvonderElbe@gmx.de ThomasvonderElbe GmxDe mike@zelea.com Mike-ZeleaCom
Note that MediaWiki ignores the case of the first letter of the username, forcing all names to begin with an uppercase letter, wheras the local part of an email address (before the @) is case sensitive. We therefore encode the fact of lowercase by mapping the '@' symbol to a dash '-' surrogate, and of uppercase by mapping it to a space ' ' surrogate. We might have tried using $wgCapitalLinks in MediaWiki, but, despite that, calls to ucfirst() in includes/User.php methods isValidUserName() and getCanonicalName() (and maybe elsewhere) block the creation of any username having a lowercase first character.
This translation should work with all email addresses in common use today. Here are the strict requirements:
a) No '/' in address - invalid in MediaWiki username b) No ' ' in address - MediaWiki cannot distinguish '_' and ' ' in page names c) Only ASCII characters in domain name - only ASCII domain names are considered case insensitive and we use lower-to-uppercase boundaries in place of '.' to separate the component labels of the name d) No '-' or digit (or anything else non-lowercase) at start of a domain label - we encode label with leading uppercase e) No '-' at end of a domain label - next label is encoded with leading uppercase, so we have internal sequence '-U', where U is an uppercase letter; but we use '-U' to encode '@' (though only for email addresses that begin with lowercase) f) No '_' in domain name - we use it (or equivalently ' ') in place of '@' (though only for email addresses that begin with uppercase)
References: - http://tools.ietf.org/html/rfc1035 - http://tools.ietf.org/html/rfc2181#section-11 - no chars *abolutely* restricted in components (labels) of a domain name - http://tools.ietf.org/html/rfc1035#section-2.3.1 - but mail hosts *ought* to follow the preferred name syntax - http://tools.ietf.org/html/rfc4343#section-3.2 - case-insensitivity applies only to ASCII labels
email
- a canonical email address.toUsername(String)
,
InternetAddressX.canonicalAddress(String)
public static StringBuilder buildUserMnemonic(String username, StringBuilder sB)
public final String email()
public static String emailOrNobody(String email, ResourceBundle resA)
resA
- a resource bundle of type application (A)public final boolean equalsEmail(Object o)
equals(Object)
@Deprecated public final boolean isFromEmail()
public static String normalUsername(String name)
username()
,
MediaWiki.normalUsername(String)
public static InternetAddress toInternetAddress(String username) throws AddressException
username
- the username encoded with either a space (or equivalently
underscore) or dash at-surrogate.AddressException
username()
,
InternetAddressX.canonicalAddress(String)
public static String toUsername(String email)
email
- the canonical email address of the user.username()
,
appendUsername(String,StringBuilder)
,
InternetAddressX.canonicalAddress(String)
public final String username()
public final boolean equals(Object o)
public final String toString()
toString
in class Object
isFromEmail()