This is an automated email from the ASF dual-hosted git repository. Arsnael pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit a2632375e6a307a7201e23f83285fc7aa638fca6 Author: Felix Auringer <[email protected]> AuthorDate: Wed Jun 24 18:23:07 2026 +0200 refactor: split mailbox and RRT checks into two methods This enhances the extensibility as only one of them can be overwritten without having to touch the logic of the other. --- .../james/smtpserver/fastfail/ValidRcptHandler.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java index f435f30571..c4f6110eed 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java @@ -24,7 +24,6 @@ import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.james.core.Domain; import org.apache.james.core.MailAddress; -import org.apache.james.core.Username; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.api.DomainListException; import org.apache.james.protocols.api.handler.ProtocolHandler; @@ -64,17 +63,21 @@ public class ValidRcptHandler extends AbstractValidRcptHandler implements Protoc @Override protected boolean isValidRecipient(SMTPSession session, MailAddress recipient) throws UsersRepositoryException, RecipientRewriteTableException { - Username username = users.getUsername(recipient); - - if (users.contains(username)) { + // Check existence of mailbox first to use RRT less often. + if (mailboxExists(recipient)) { return true; } else { - return supportsRecipientRewriteTable && isRedirected(recipient, username.asString()); + // Check whether there is a valid RRT entry for the recipient. + return supportsRecipientRewriteTable && hasValidRRTEntry(recipient); } } - private boolean isRedirected(MailAddress recipient, String username) throws RecipientRewriteTableException { - LOGGER.debug("Unknown user {} check if it's an alias", username); + protected boolean mailboxExists(MailAddress recipient) throws UsersRepositoryException { + return users.contains(users.getUsername(recipient)); + } + + protected boolean hasValidRRTEntry(MailAddress recipient) throws RecipientRewriteTableException { + LOGGER.debug("Unknown recipient {}, resolving it via RRT", recipient); try { Mappings targetString = recipientRewriteTable.getResolvedMappings(recipient.getLocalPart(), recipient.getDomain()); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
