Skip to content

Commit

Permalink
[FIX] AbstractValidRcptHandler fix error handling on invalid username (
Browse files Browse the repository at this point in the history
…apache#2122)

Syntactically valid email address but invalid username.
The best is to advertise "no such person here".
  • Loading branch information
chibenwa authored and samiulsami committed Apr 30, 2024
1 parent 710fee9 commit 51e7c76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rc
return reject(rcpt);
}
return HookResult.DECLINED;
} catch (IllegalAccessException e) {
LOGGER.warn("Encounter an error upon RCPT validation ({}), deny-soft", rcpt.asString());
} catch (IllegalArgumentException e) {
LOGGER.info("Encounter an error upon RCPT validation ({}), deny", rcpt.asString());
return HookResult.builder()
.hookReturnCode(HookReturnCode.deny())
.smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS)
.smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX) + " Unexpected error for " + rcpt.asString())
.smtpReturnCode(SMTPRetCode.MAILBOX_PERM_UNAVAILABLE)
.smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.asString())
.build();
} catch (Exception e) {
LOGGER.error("Encounter an error upon RCPT validation ({}), deny-soft", rcpt.asString(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,12 @@ void doRcptShouldReturnDenySoftWhenUsersRepositoryError() throws Exception {
assertThat(rCode).isEqualTo(HookReturnCode.denySoft());
}

@Test
void doRcptShouldReturnDeclineWhenInvalidUsername() throws Exception {
SMTPSession session = setupMockedSMTPSession(!RELAYING_ALLOWED);

HookReturnCode rCode = handler.doRcpt(session, MAYBE_SENDER, new MailAddress("\"abc@\"@localhost")).getResult();

assertThat(rCode).isEqualTo(HookReturnCode.deny());
}
}

0 comments on commit 51e7c76

Please sign in to comment.