/** * Return the service type which will be used in the Received headers. * * @param session * @param heloMode * @return type */ protected String getServiceType(SMTPSession session, String heloMode) { // Check if EHLO was used if (EHLO.equals(heloMode)) { // Not successful auth if (session.getUser() == null) { return ESMTP; } else { // See RFC3848 // The new keyword "ESMTPA" indicates the use of ESMTP when // the // SMTP // AUTH [3] extension is also used and authentication is // successfully // achieved. return ESMTPA; } } else { return SMTP; } }
private boolean senderMatchSessionUser(MaybeSender maybeSender, SMTPSession session) { Preconditions.checkArgument(!maybeSender.isNullSender()); String authUser = session.getUser().toLowerCase(Locale.US); String username = getUser(maybeSender.get()); return username.equals(authUser); }
@Override public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { final MailImpl mailImpl = (MailImpl) mail; mailImpl.setRemoteHost(session.getRemoteAddress().getHostName()); mailImpl.setRemoteAddr(session.getRemoteAddress().getAddress().getHostAddress()); if (session.getUser() != null) { mail.setAttribute(Mail.SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser()); } if (session.isRelayingAllowed()) { mail.setAttribute(SMTP_AUTH_NETWORK_NAME, "true"); } } return HookResult.DECLINED; }
if (session.getUser() != null) { return ALREADY_AUTH; } else if (argument == null) {
@Override public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { if (session.getUser() != null) { MaybeSender senderAddress = (MaybeSender) session.getAttachment(SMTPSession.SENDER, ProtocolSession.State.Transaction); // 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 (isAnonymous(sender) || !senderMatchSessionUser(sender, session) || !belongsToLocalDomain(senderAddress)) { return INVALID_AUTH; } } return HookResult.DECLINED; }
public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { final MailImpl mailImpl = (MailImpl) mail; mailImpl.setRemoteHost(session.getRemoteHost()); mailImpl.setRemoteAddr(session.getRemoteIPAddress()); if (session.getUser() != null) { mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser()); } if (session.isRelayingAllowed()) { mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true"); } } return new HookResult(HookReturnCode.DECLINED); }