Search in sources :

Example 46 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class DomainPolicyResolver_getPolicyTest method testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty.

public void testGetPolicy_outgoingPolicyDoesNotExist_assertEmpty() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final List<PolicyExpression> expressions = Arrays.asList(expression);
    final Map<String, Collection<PolicyExpression>> policies = new HashMap<String, Collection<PolicyExpression>>();
    policies.put("testdomain.com", expressions);
    final DomainPolicyResolver resolver = new DomainPolicyResolver(policies);
    Collection<PolicyExpression> retrievedExpressions = resolver.getOutgoingPolicy(new InternetAddress("me@testdomainother.com"));
    assertNotNull(retrievedExpressions);
    assertEquals(0, retrievedExpressions.size());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) Collection(java.util.Collection) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 47 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class UniversalPolicyResolver_getPolicyTest method testGetOutgoingPolicy_assertPolicyRetrieved.

public void testGetOutgoingPolicy_assertPolicyRetrieved() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final UniversalPolicyResolver resolver = new UniversalPolicyResolver(expression);
    final Collection<PolicyExpression> policies = resolver.getOutgoingPolicy(new InternetAddress("me@you.com"));
    assertEquals(1, policies.size());
    assertEquals(expression, policies.iterator().next());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 48 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class UniversalPolicyResolver_getPolicyTest method testGetIncomingPolicy_assertPolicyRetrieved.

public void testGetIncomingPolicy_assertPolicyRetrieved() throws Exception {
    final PolicyExpression expression = mock(PolicyExpression.class);
    final UniversalPolicyResolver resolver = new UniversalPolicyResolver(expression);
    final Collection<PolicyExpression> policies = resolver.getIncomingPolicy(new InternetAddress("me@you.com"));
    assertEquals(1, policies.size());
    assertEquals(expression, policies.iterator().next());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) PolicyExpression(org.nhindirect.policy.PolicyExpression)

Example 49 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class AbstractCompletionCondition method normalizeFinalRecip.

/**
	 * Final recipients may begin with something like rfc822;.  This removes the prefix and just returns the final
	 * recipient as an address.
	 * @param recip  The final recipient
	 * @return Normalized version of the final recipient that only contains the email address.
	 */
public static String normalizeFinalRecip(String recip) {
    String normalizedString = recip;
    final int index = recip.indexOf(";");
    if (index > -1) {
        normalizedString = recip.substring(index + 1).trim();
    }
    // we need to just get the email address for comparison
    try {
        InternetAddress addr = new InternetAddress(normalizedString);
        normalizedString = addr.getAddress();
    } catch (AddressException e) {
    /* noop */
    }
    return normalizedString;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException)

Example 50 with InternetAddress

use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.

the class DSNMessageGenerator method generateDSNFailureMessage.

/**
	 * Generates the DSN message a replacing the existing exchange in body with the DSN message as a MimeMessage object.
	 * @param txs Collection of correlated Tx objects.
	 * @param ex The message exchange.
	 * @throws Exception
	 */
@Handler
public void generateDSNFailureMessage(Collection<Tx> txs, Exchange ex) throws Exception {
    // change the inbound message body to null
    ex.getIn().setBody(null);
    // get the message that is being tracked so we can generate an error message for it
    Tx messageToTrack = AbstractCompletionCondition.getMessageToTrack(txs);
    if (messageToTrack != null) {
        // make sure we have incomplete recipients
        final Collection<String> incompleteRecips = conditionChecker.getIncompleteRecipients(txs);
        if (incompleteRecips != null && !incompleteRecips.isEmpty()) {
            InternetAddress originalSender = null;
            String originalSubject = "";
            InternetAddress postmaster = null;
            String originalMessageId = "";
            Enumeration<Header> fullMessageHeaders = null;
            final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
            final List<Address> failedRecipAddresses = new ArrayList<Address>();
            final TxDetail sender = messageToTrack.getDetail(TxDetailType.FROM);
            if (sender != null) {
                originalSender = new InternetAddress(sender.getDetailValue());
                postmaster = new InternetAddress(postmasterMailbox + "@" + getAddressDomain(originalSender));
            }
            final TxDetail subject = messageToTrack.getDetail(TxDetailType.SUBJECT);
            if (subject != null)
                originalSubject = subject.getDetailValue();
            for (String incompleteRecip : incompleteRecips) {
                final Address failedRecipAddress = new InternetAddress(incompleteRecip);
                DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS), failedRecipAddress);
                recipientDSNHeaders.add(dsnRecipHeaders);
                failedRecipAddresses.add(failedRecipAddress);
            }
            ///CLOVER:OFF
            final TxDetail origMessId = messageToTrack.getDetail(TxDetailType.MSG_ID);
            if (origMessId != null)
                originalMessageId = origMessId.getDetailValue();
            ///CLOVER:ON
            final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
            final TxDetail fullHeaders = messageToTrack.getDetail(TxDetailType.MSG_FULL_HEADERS);
            if (fullHeaders != null)
                fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
            final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
            final MimeMessage dnsMessage = generator.createDSNMessage(originalSender, originalSubject, postmaster, recipientDSNHeaders, messageDSNHeaders, textBodyPart);
            ex.getIn().setBody(dnsMessage);
        }
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Tx(org.nhindirect.common.tx.model.Tx) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) DSNRecipientHeaders(org.nhindirect.common.mail.dsn.DSNRecipientHeaders) ArrayList(java.util.ArrayList) TxDetail(org.nhindirect.common.tx.model.TxDetail) Header(javax.mail.Header) MimeMessage(javax.mail.internet.MimeMessage) DSNMessageHeaders(org.nhindirect.common.mail.dsn.DSNMessageHeaders) MimeBodyPart(javax.mail.internet.MimeBodyPart) Handler(org.apache.camel.Handler)

Aggregations

InternetAddress (javax.mail.internet.InternetAddress)255 MimeMessage (javax.mail.internet.MimeMessage)106 MessagingException (javax.mail.MessagingException)69 Session (javax.mail.Session)49 Properties (java.util.Properties)45 ArrayList (java.util.ArrayList)42 Address (javax.mail.Address)41 Message (javax.mail.Message)40 Date (java.util.Date)38 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)36 AddressException (javax.mail.internet.AddressException)34 X509Certificate (java.security.cert.X509Certificate)32 MimeBodyPart (javax.mail.internet.MimeBodyPart)30 Test (org.junit.Test)29 IOException (java.io.IOException)26 MimeMultipart (javax.mail.internet.MimeMultipart)26 PolicyExpression (org.nhindirect.policy.PolicyExpression)18 HashMap (java.util.HashMap)17 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)17 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)17