in resolver/src/main/java/org/apache/james/jspf/core/MacroExpand.java [220:252]
private String expandDomain(String input, MacroData macroData) throws PermErrorException, RequireClientDomainException {
LOGGER.debug("Start expand domain: {}", input);
Matcher inputMatcher = domainSpecPattern.matcher(input);
if (!inputMatcher.matches() || inputMatcher.groupCount() != 2) {
throw new PermErrorException("Invalid DomainSpec: "+input);
}
StringBuffer res = new StringBuffer();
if (inputMatcher.group(1) != null && inputMatcher.group(1).length() > 0) {
res.append(expandMacroString(inputMatcher.group(1), macroData, false));
}
if (inputMatcher.group(2) != null && inputMatcher.group(2).length() > 0) {
if (inputMatcher.group(2).startsWith(".")) {
res.append(inputMatcher.group(2));
} else {
res.append(expandMacroString(inputMatcher.group(2), macroData, false));
}
}
String domainName = expandMacroString(input, macroData, false);
// reduce to less than 255 characters, deleting subdomains from left
int split = 0;
while (domainName.length() > 255 && split > -1) {
split = domainName.indexOf(".");
domainName = domainName.substring(split + 1);
}
LOGGER.debug("Domain expanded: {}", domainName);
return domainName;
}