use of org.apache.mailet.MailetContext in project nhin-d by DirectProject.
the class RecipientIsLocalAndSMTPAuthUserIs method match.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
LOGGER.info("Servicing RecipientIsLocalAndSMTPAuthUserIs matcher");
String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
if (authUser == null || !StringUtils.equalsIgnoreCase(user, authUser)) {
LOGGER.info("Auth user is not " + user + ", skipping");
return Collections.<MailAddress>emptyList();
}
MailetContext mailetContext = getMailetContext();
Collection<MailAddress> recipients = new ArrayList<MailAddress>();
for (MailAddress recipient : (Collection<MailAddress>) mail.getRecipients()) {
if (mailetContext.isLocalServer(recipient.getHost()) && mailetContext.isLocalUser(recipient.getUser()))
recipients.add(recipient);
}
if (recipients.isEmpty())
LOGGER.info("Matched no recipients");
else
for (MailAddress addr : recipients) LOGGER.info("Matched recipient " + addr.toString());
return recipients;
}
Aggregations