Search in sources :

Example 26 with MailAddress

use of org.apache.mailet.MailAddress 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;
}
Also used : MailetContext(org.apache.mailet.MailetContext) MailAddress(org.apache.mailet.MailAddress) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 27 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class RecipientIsNotXd method match.

/**
     * {@inheritDoc}
     */
@SuppressWarnings("unchecked")
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
    LOGGER.info("Attempting to match non-XD recipients");
    Collection<MailAddress> recipients = new ArrayList<MailAddress>();
    for (MailAddress addr : (Collection<MailAddress>) mail.getRecipients()) {
        if (!routingResolver.isXdEndpoint(addr.toString())) {
            recipients.add(addr);
        }
    }
    if (recipients.isEmpty())
        LOGGER.info("Matched no recipients");
    else
        for (MailAddress addr : recipients) LOGGER.info("Matched recipient " + addr.toString());
    return recipients;
}
Also used : MailAddress(org.apache.mailet.MailAddress) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 28 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class RecipientIsXdAndNotSMIME method match.

/**
     * {@inheritDoc}
     */
@SuppressWarnings("unchecked")
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
    LOGGER.info("Attempting to match XD recipients");
    Collection<MailAddress> recipients = new ArrayList<MailAddress>();
    MimeMessage message = mail.getMessage();
    if (message.isMimeType("application/x-pkcs7-mime") || message.isMimeType("application/pkcs7-mime")) {
        LOGGER.info("MimeMessage is SMIME, skipping");
        return Collections.<MailAddress>emptyList();
    }
    for (MailAddress addr : (Collection<MailAddress>) mail.getRecipients()) {
        if (routingResolver.isXdEndpoint(addr.toString())) {
            recipients.add(addr);
        }
    }
    if (recipients.isEmpty()) {
        LOGGER.info("Matched no recipients");
    } else {
        for (MailAddress addr : recipients) {
            LOGGER.info("Matched recipient " + addr.toString());
        }
    }
    return recipients;
}
Also used : MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

MailAddress (org.apache.mailet.MailAddress)28 MimeMessage (javax.mail.internet.MimeMessage)17 ArrayList (java.util.ArrayList)11 Mail (org.apache.mailet.Mail)11 InternetAddress (javax.mail.internet.InternetAddress)8 MockMail (org.nhindirect.gateway.smtp.james.mailet.MockMail)8 SmtpAgent (org.nhindirect.gateway.smtp.SmtpAgent)7 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 Collection (java.util.Collection)5 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)5 Address (javax.mail.Address)4 MessagingException (javax.mail.MessagingException)4 MatcherConfig (org.apache.mailet.MatcherConfig)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Message (org.nhindirect.stagent.mail.Message)4 Tx (org.nhindirect.common.tx.model.Tx)2 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)2