Search in sources :

Example 56 with InternetAddress

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

the class WSSmtpAgentConfig method buildDomains.

protected void buildDomains() {
    domains = new ArrayList<String>();
    domainPostmasters = new HashMap<String, DomainPostmaster>();
    // get the domain list first
    try {
        int domainCount = cfService.getDomainCount();
        lookedupWSDomains = cfService.listDomains(null, domainCount);
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting domains list: " + e.getMessage(), e);
    }
    if (lookedupWSDomains != null) {
        for (Domain dom : lookedupWSDomains) {
            domains.add(dom.getDomainName());
            try {
                String configuredAddress = dom.getPostMasterEmail();
                configuredAddress = (configuredAddress == null || configuredAddress.trim().isEmpty()) ? DomainPostmaster.getDefaultPostmaster(dom.getDomainName()) : configuredAddress;
                domainPostmasters.put(dom.getDomainName().toUpperCase(Locale.getDefault()), new DomainPostmaster(dom.getDomainName(), new InternetAddress(configuredAddress)));
            } catch (AddressException e) {
            }
        }
    }
    if (domains.size() == 0)
        throw new SmtpAgentException(SmtpAgentError.MissingDomains);
    // now get the trust anchors
    buildTrustAnchorResolver();
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) DomainPostmaster(org.nhindirect.gateway.smtp.DomainPostmaster) Domain(org.nhind.config.Domain) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 57 with InternetAddress

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

the class XMLSmtpAgentConfig method buildDomains.

/*
	 * Builds the list of domains managed by the agent.
	 */
private void buildDomains(Node domainsNode) {
    domains = new ArrayList<String>();
    domainPostmasters = new HashMap<String, DomainPostmaster>();
    // get all domains
    Node domainNode = domainsNode.getFirstChild();
    Node anchorStoreNode = null;
    Map<String, Collection<String>> incomingAnchorHolder = new HashMap<String, Collection<String>>();
    Map<String, Collection<String>> outgoingAnchorHolder = new HashMap<String, Collection<String>>();
    do {
        // get an individual domain
        String domain = "";
        String postmasterAddr = "";
        if (domainNode.getNodeType() == Node.ELEMENT_NODE) {
            if (domainNode.getNodeName().equalsIgnoreCase("domain")) {
                Element domainEl = (Element) domainNode;
                domain = domainEl.getAttribute("name");
                if (domain == null || domain.trim().length() == 0)
                    throw new SmtpAgentException(SmtpAgentError.MissingDomainName);
                postmasterAddr = domainEl.getAttribute("postmaster");
                if (postmasterAddr == null || postmasterAddr.trim().length() == 0)
                    postmasterAddr = DomainPostmaster.getDefaultPostmaster(domain);
                domains.add(domain);
                try {
                    domainPostmasters.put(domain.toUpperCase(Locale.getDefault()), new DomainPostmaster(domain, new InternetAddress(postmasterAddr)));
                } catch (AddressException e) {
                }
                // get the trust anchors configured for this domain
                Node anchorsNode = domainNode.getFirstChild();
                do {
                    if (anchorsNode.getNodeType() == Node.ELEMENT_NODE) {
                        /*
							 * Incoming trust anchors
							 */
                        if (anchorsNode.getNodeName().equalsIgnoreCase("incomingtrustanchors"))
                            incomingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
                        else /*
							 * Outgoing trust anchors
							 */
                        if (anchorsNode.getNodeName().equalsIgnoreCase("outgoingtrustanchors"))
                            outgoingAnchorHolder.put(domain, getConfiguredTrustAnchorNames(anchorsNode));
                    }
                    anchorsNode = anchorsNode.getNextSibling();
                } while (anchorsNode != null);
            } else if (domainNode.getNodeName().equalsIgnoreCase("anchorstore")) {
                // save off for later configuration
                anchorStoreNode = domainNode;
            }
        }
        domainNode = domainNode.getNextSibling();
    } while (domainNode != null);
    if (domains.size() == 0)
        throw new SmtpAgentException(SmtpAgentError.MissingDomains);
    buildTrustAnchorResolver((Element) anchorStoreNode, incomingAnchorHolder, outgoingAnchorHolder);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) AddressException(javax.mail.internet.AddressException) DomainPostmaster(org.nhindirect.gateway.smtp.DomainPostmaster) Collection(java.util.Collection)

Example 58 with InternetAddress

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

the class AbstractNotificationAwareMailet method getSender.

/**
	 * Gets the sender attribute of a Mail message
	 * @param mail The message to retrive the sender from
	 * @return The message sender.
	 */
public static InternetAddress getSender(Mail mail) {
    InternetAddress retVal = null;
    if (mail.getSender() != null)
        retVal = mail.getSender().toInternetAddress();
    else {
        // try to get the sender from the message
        Address[] senderAddr = null;
        try {
            if (mail.getMessage() == null)
                return null;
            senderAddr = mail.getMessage().getFrom();
            if (senderAddr == null || senderAddr.length == 0)
                return null;
        } catch (MessagingException e) {
            return null;
        }
        // not the best way to do this
        retVal = (InternetAddress) senderAddr[0];
    }
    return retVal;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) MailAddress(org.apache.mailet.MailAddress) InternetAddress(javax.mail.internet.InternetAddress) NHINDAddress(org.nhindirect.stagent.NHINDAddress) MessagingException(javax.mail.MessagingException)

Example 59 with InternetAddress

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

the class IsNotificationTest method testIsNotification_ecryptedMessage_assertNull.

@SuppressWarnings("unchecked")
public void testIsNotification_ecryptedMessage_assertNull() throws Exception {
    MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("EncryptedMessage.txt")));
    IsNotSMIMEEncrypted matcher = new IsNotSMIMEEncrypted();
    final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
    for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
    final MockMail mockMail = new MockMail(msg);
    mockMail.setRecipients(initialRecips);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(null, matchAddresses);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail) ArrayList(java.util.ArrayList)

Example 60 with InternetAddress

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

the class IsNotificationTest method testIsNotification_DSNMessage_assertAllRecips.

@SuppressWarnings("unchecked")
public void testIsNotification_DSNMessage_assertAllRecips() throws Exception {
    MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("DSNMessage.txt")));
    IsNotification matcher = new IsNotification();
    final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
    for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
    final MockMail mockMail = new MockMail(msg);
    mockMail.setRecipients(initialRecips);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals(initialRecips.iterator().next().toString(), matchAddresses.iterator().next().toString());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail) ArrayList(java.util.ArrayList)

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