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();
}
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);
}
}
}
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;
}
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;
}
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");
}
}
Aggregations