Search in sources :

Example 61 with AddressException

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

the class RESTSmtpAgentConfig method buildDomains.

@Override
protected void buildDomains() {
    domains = new ArrayList<String>();
    domainPostmasters = new HashMap<String, DomainPostmaster>();
    // get the domain list first
    try {
        lookedupRESTServiceDomains = domainService.searchDomains("", null);
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting domains list: " + e.getMessage(), e);
    }
    if (lookedupRESTServiceDomains != null) {
        for (Domain dom : lookedupRESTServiceDomains) {
            domains.add(dom.getDomainName());
            try {
                String configuredAddress = (dom.getPostmasterAddress() == null) ? "" : dom.getPostmasterAddress().getEmailAddress();
                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.nhindirect.config.model.Domain) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 62 with AddressException

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

the class TrustChainValidator method resolveIssuers.

protected void resolveIssuers(X509Certificate certificate, /*in-out*/
Collection<X509Certificate> issuers, int chainLength, Collection<X509Certificate> anchors) {
    X500Principal issuerPrin = certificate.getIssuerX500Principal();
    if (issuerPrin.equals(certificate.getSubjectX500Principal())) {
        // no intermediate between me, myself, and I
        return;
    }
    // look in the issuer list and see if the certificate issuer already exists in the list
    for (X509Certificate issuer : issuers) {
        if (issuerPrin.equals(issuer.getSubjectX500Principal()))
            // already found the certificate issuer... done
            return;
    }
    if (chainLength >= maxIssuerChainLength) {
        // bail out with what we have now
        return;
    }
    // first check to see there is an AIA extension with one ore more caIssuer entries and attempt to resolve the
    // intermediate via the URL
    final Collection<X509Certificate> issuerCerts = getIntermediateCertsByAIA(certificate);
    // of using resolvers
    if (issuerCerts.isEmpty()) {
        final String address = this.getIssuerAddress(certificate);
        if (address == null || address.isEmpty())
            // not much we can do about this... the resolver interface only knows how to work with addresses
            return;
        // multiple resolvers
        for (CertificateResolver publicResolver : certResolvers) {
            Collection<X509Certificate> holdCerts = null;
            try {
                holdCerts = publicResolver.getCertificates(new InternetAddress(address));
            } catch (AddressException e) {
                continue;
            } catch (Exception e) {
            /* no-op*/
            }
            if (holdCerts != null && holdCerts.size() > 0)
                issuerCerts.addAll(holdCerts);
        }
    }
    if (issuerCerts.size() == 0)
        // no intermediates.. just return
        return;
    boolean issuerFoundInAnchors = false;
    Collection<X509Certificate> searchForParentIssuers = new ArrayList<X509Certificate>();
    for (X509Certificate issuerCert : issuerCerts) {
        if (issuerCert.getSubjectX500Principal().equals(issuerPrin) && !isIssuerInCollection(issuers, issuerCert) && !isIssuerInAnchors(anchors, issuerCert)) /* if we hit an anchor then stop */
        {
            searchForParentIssuers.add(issuerCert);
        } else if (isIssuerInAnchors(anchors, issuerCert)) {
            issuerFoundInAnchors = true;
            break;
        }
    }
    // the go up the next level in the chain
    if (!issuerFoundInAnchors) {
        for (X509Certificate issuerCert : searchForParentIssuers) {
            issuers.add(issuerCert);
            // see if this issuer also has intermediate certs
            resolveIssuers(issuerCert, issuers, chainLength + 1, anchors);
        }
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException) ArrayList(java.util.ArrayList) X500Principal(javax.security.auth.x500.X500Principal) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate) CertificateParsingException(java.security.cert.CertificateParsingException) AddressException(javax.mail.internet.AddressException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) NHINDException(org.nhindirect.stagent.NHINDException)

Example 63 with AddressException

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

the class NHINDAddressCollection method parse.

/**
     * Parses an message router header to a collection of address.  The addressline may or may not include the header name.
     * @param addressesLine The raw message header.  The header name does not need to be included, but should use the proper header delimiter
     * if it is included.
     * @param source The address source type of the address line.
     * @return A collection of addresses parsed from the address line.
     */
public static NHINDAddressCollection parse(String addressesLine, AddressSource source) {
    NHINDAddressCollection retVal = new NHINDAddressCollection();
    if (addressesLine != null) {
        // strip the header separator if it exists
        int index = addressesLine.indexOf(':');
        String addressString = index > -1 ? addressesLine.substring(index + 1) : addressesLine;
        // split out the address using the standard delimiter
        //String[] addresses = addressString.split(String.valueOf(MailStandard.MailAddressSeparator));
        InternetAddress[] addresses = null;
        try {
            addresses = InternetAddress.parseHeader(addressString, true);
        } catch (AddressException e) {
            throw new NHINDException("Invalid email address format.", e);
        }
        for (InternetAddress addr : addresses) retVal.add(new NHINDAddress(addr.getAddress(), source));
    }
    return retVal;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException)

Example 64 with AddressException

use of javax.mail.internet.AddressException in project Lucee by lucee.

the class MailUtil method parseEmail.

/**
 * returns an InternetAddress object or null if the parsing fails.  to be be used in multiple places.
 * @param value
 * @return
 */
public static InternetAddress parseEmail(Object value) {
    String str = Caster.toString(value, "");
    if (str.indexOf('@') > -1) {
        try {
            InternetAddress addr = new InternetAddress(str);
            fixIDN(addr);
            return addr;
        } catch (AddressException ex) {
        }
    }
    return null;
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException)

Example 65 with AddressException

use of javax.mail.internet.AddressException in project theskeleton by codenergic.

the class TokenStoreServiceImpl method sendEmail.

private void sendEmail(TokenStoreEntity token, UserEntity user) {
    Map<String, Object> params = new HashMap<>();
    String subject;
    String template;
    if (TokenStoreType.USER_ACTIVATION.equals(token.getType())) {
        params.put("activationUrl", baseUrl + "/registration/activate?at=" + token.getToken());
        subject = "Registration Confirmation";
        template = "email/registration.html";
    } else {
        params.put("changepassUrl", baseUrl + "/changepass/update?rt=" + token.getToken());
        subject = "Reset Password Confirmation";
        template = "email/changepass.html";
    }
    try {
        emailService.sendEmail(null, new InternetAddress(user.getEmail()), subject, params, template);
    } catch (AddressException e) {
        throw new RegistrationException("Unable to send activation link");
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) AddressException(javax.mail.internet.AddressException)

Aggregations

AddressException (javax.mail.internet.AddressException)130 InternetAddress (javax.mail.internet.InternetAddress)108 MimeMessage (javax.mail.internet.MimeMessage)43 MessagingException (javax.mail.MessagingException)38 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)21 UnsupportedEncodingException (java.io.UnsupportedEncodingException)21 Address (javax.mail.Address)21 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)18 Properties (java.util.Properties)18 Session (javax.mail.Session)15 Date (java.util.Date)14 MimeBodyPart (javax.mail.internet.MimeBodyPart)14 MimeMultipart (javax.mail.internet.MimeMultipart)12 File (java.io.File)11 Message (javax.mail.Message)10 Multipart (javax.mail.Multipart)9 DataHandler (javax.activation.DataHandler)8 Test (org.junit.Test)7 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5