split on first dot when using domain instead of black listed local part

This commit is contained in:
Daniel Gultsch 2019-07-15 19:09:48 +02:00
parent bc3e5f1dd4
commit 97598c63dc
1 changed files with 17 additions and 17 deletions

View File

@ -39,24 +39,24 @@ import rocks.xmpp.addr.Jid;
public class JidHelper {
private static List<String> LOCALPART_BLACKLIST = Arrays.asList("xmpp","jabber","me");
private static List<String> LOCAL_PART_BLACKLIST = Arrays.asList("xmpp", "jabber", "me");
public static String localPartOrFallback(Jid jid) {
if (LOCALPART_BLACKLIST.contains(jid.getLocal().toLowerCase(Locale.ENGLISH))) {
final String domain = jid.getDomain();
final int index = domain.lastIndexOf('.');
return index > 1 ? domain.substring(0,index) : domain;
} else {
return jid.getLocal();
}
}
public static String localPartOrFallback(Jid jid) {
if (LOCAL_PART_BLACKLIST.contains(jid.getLocal().toLowerCase(Locale.ENGLISH))) {
final String domain = jid.getDomain();
final int index = domain.indexOf('.');
return index > 1 ? domain.substring(0, index) : domain;
} else {
return jid.getLocal();
}
}
public static Jid parseOrFallbackToInvalid(String jid) {
try {
return Jid.of(jid);
} catch (IllegalArgumentException e) {
return InvalidJid.of(jid, true);
}
}
public static Jid parseOrFallbackToInvalid(String jid) {
try {
return Jid.of(jid);
} catch (IllegalArgumentException e) {
return InvalidJid.of(jid, true);
}
}
}