*/
public HookResult doRcpt(SMTPSession session, MailAddress sender,
MailAddress rcpt) {
if (session.getUser() != null) {
String authUser = (session.getUser()).toLowerCase(Locale.US);
MailAddress senderAddress = (MailAddress) session.getState().get(
SMTPSession.SENDER);
String username= null;
if (senderAddress != null) {
if (useVirtualHosting()) {
username = senderAddress.toString();
} else {
username = senderAddress.getLocalPart();
}
}
// Check if the sender address is the same as the user which was used to authenticate.
// Its important to ignore case here to fix JAMES-837. This is save todo because if the handler is called
// the user was already authenticated
if ((senderAddress == null)
|| (!authUser.equalsIgnoreCase(username))
|| (!isLocalDomain(senderAddress.getDomain()))) {
return new HookResult(HookReturnCode.DENY,
SMTPRetCode.BAD_SEQUENCE,
DSNStatus.getStatus(DSNStatus.PERMANENT,
DSNStatus.SECURITY_AUTH)
+ " Incorrect Authentication for Specified Email Address");