JAMES-2366 remove a duplicate condition in mappings logic
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/949594cf Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/949594cf Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/949594cf Branch: refs/heads/master Commit: 949594cfd6ba6414ba885649acf1c40b96caee4a Parents: f8c43ad Author: Matthieu Baechler <matth...@apache.org> Authored: Tue Apr 17 15:00:27 2018 +0200 Committer: Matthieu Baechler <matth...@apache.org> Committed: Tue Apr 24 14:45:26 2018 +0200 ---------------------------------------------------------------------- .../rrt/lib/AbstractRecipientRewriteTable.java | 93 +++++++++----------- 1 file changed, 44 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/949594cf/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java ---------------------------------------------------------------------- diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java index 69370c6..7249250 100644 --- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java +++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTable.java @@ -107,66 +107,61 @@ public abstract class AbstractRecipientRewriteTable implements RecipientRewriteT Mappings targetMappings = mapAddress(user, domain); - // Only non-null mappings are translated - if (!targetMappings.isEmpty()) { - if (targetMappings.contains(Type.Error)) { - throw new ErrorMappingException(targetMappings.getError().getErrorMessage()); - } else { - MappingsImpl.Builder mappings = MappingsImpl.builder(); - - for (String target : targetMappings.asStrings()) { - Type type = Mapping.detectType(target); - Optional<String> maybeAddressWithMappingApplied = applyMapping(user, domain, target, type); - - if (!maybeAddressWithMappingApplied.isPresent()) { - continue; - } - String addressWithMappingApplied = maybeAddressWithMappingApplied.get(); - LOGGER.debug("Valid virtual user mapping {}@{} to {}", user, domain.name(), addressWithMappingApplied); - - if (recursive) { - - String userName; - Domain targetDomain; - String[] args = addressWithMappingApplied.split("@"); - - if (args.length > 1) { - userName = args[0]; - targetDomain = Domain.of(args[1]); - } else { - // TODO Is that the right todo here? - userName = addressWithMappingApplied; - targetDomain = domain; - } + if (targetMappings.contains(Type.Error)) { + throw new ErrorMappingException(targetMappings.getError().getErrorMessage()); + } else { + MappingsImpl.Builder mappings = MappingsImpl.builder(); - // Check if the returned mapping is the same as the - // input. If so return null to avoid loops - if (userName.equalsIgnoreCase(user) && targetDomain.equals(domain)) { - if (type.equals(Type.Forward)) { - mappings.add(toMapping(addressWithMappingApplied, type)); - continue; - } - return MappingsImpl.empty(); - } + for (String target : targetMappings.asStrings()) { + Type type = Mapping.detectType(target); + Optional<String> maybeAddressWithMappingApplied = applyMapping(user, domain, target, type); + + if (!maybeAddressWithMappingApplied.isPresent()) { + continue; + } + String addressWithMappingApplied = maybeAddressWithMappingApplied.get(); + LOGGER.debug("Valid virtual user mapping {}@{} to {}", user, domain.name(), addressWithMappingApplied); + + if (recursive) { - Mappings childMappings = getMappings(userName, targetDomain, mappingLimit - 1); + String userName; + Domain targetDomain; + String[] args = addressWithMappingApplied.split("@"); - if (childMappings.isEmpty()) { - // add mapping + if (args.length > 1) { + userName = args[0]; + targetDomain = Domain.of(args[1]); + } else { + // TODO Is that the right todo here? + userName = addressWithMappingApplied; + targetDomain = domain; + } + + // Check if the returned mapping is the same as the + // input. If so return null to avoid loops + if (userName.equalsIgnoreCase(user) && targetDomain.equals(domain)) { + if (type.equals(Type.Forward)) { mappings.add(toMapping(addressWithMappingApplied, type)); - } else { - mappings = mappings.addAll(childMappings); + continue; } + return MappingsImpl.empty(); + } - } else { + Mappings childMappings = getMappings(userName, targetDomain, mappingLimit - 1); + + if (childMappings.isEmpty()) { + // add mapping mappings.add(toMapping(addressWithMappingApplied, type)); + } else { + mappings = mappings.addAll(childMappings); } + + } else { + mappings.add(toMapping(addressWithMappingApplied, type)); } - return mappings.build(); } + return mappings.build(); } - - return MappingsImpl.empty(); } private Mapping toMapping(String mappedAddress, Type type) { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org