Search in sources :

Example 6 with AddressException

use of javax.mail.internet.AddressException 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 7 with AddressException

use of javax.mail.internet.AddressException 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 8 with AddressException

use of javax.mail.internet.AddressException 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 9 with AddressException

use of javax.mail.internet.AddressException in project opennms by OpenNMS.

the class JavaMailAckReaderIT method workingWithSimpleTextMessages.

/**
     * tests the ability to create acknowledgments from an email for plain text.  This test
     * creates a message from scratch rather than reading from an inbox. 
     */
@Test
public void workingWithSimpleTextMessages() {
    Properties props = new Properties();
    Message msg = new MimeMessage(Session.getDefaultInstance(props));
    try {
        Address[] addrs = new Address[1];
        addrs[0] = new InternetAddress("david@opennms.org");
        msg.addFrom(addrs);
        msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, addrs[0]);
        msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
        msg.setText("ACK");
    } catch (AddressException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    List<Message> msgs = new ArrayList<Message>(1);
    msgs.add(msg);
    List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
    Assert.assertEquals(1, acks.size());
    Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
    Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
    Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
    Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) Message(javax.mail.Message) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) MimeMessage(javax.mail.internet.MimeMessage) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) Properties(java.util.Properties) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) Test(org.junit.Test)

Example 10 with AddressException

use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.

the class AttributeInfo method validEmailAddress.

public static void validEmailAddress(String addr, boolean personal) throws ServiceException {
    if (addr.indexOf('@') == -1)
        throw AccountServiceException.INVALID_ATTR_VALUE("address '" + addr + "' does not include domain", null);
    try {
        InternetAddress ia = new JavaMailInternetAddress(addr, true);
        // is this even needed?
        ia.validate();
        if (!personal && ia.getPersonal() != null && !ia.getPersonal().equals(""))
            throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, null);
    } catch (AddressException e) {
        throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, e);
    }
}
Also used : JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress)

Aggregations

AddressException (javax.mail.internet.AddressException)46 InternetAddress (javax.mail.internet.InternetAddress)37 MimeMessage (javax.mail.internet.MimeMessage)18 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)17 MessagingException (javax.mail.MessagingException)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Date (java.util.Date)7 Address (javax.mail.Address)7 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 Properties (java.util.Properties)4 Session (javax.mail.Session)4 MimeBodyPart (javax.mail.internet.MimeBodyPart)4 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 Invite (com.zimbra.cs.mailbox.calendar.Invite)3 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)3 Locale (java.util.Locale)3