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();
}
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);
}
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;
}
use of javax.mail.internet.AddressException in project zm-mailbox by Zimbra.
the class CalendarItem method processNewInviteReply.
boolean processNewInviteReply(Invite reply, String sender) throws ServiceException {
List<ZAttendee> attendees = reply.getAttendees();
String senderAddress = null;
if (sender != null && !sender.isEmpty()) {
try {
JavaMailInternetAddress address = new JavaMailInternetAddress(sender);
senderAddress = address.getAddress();
} catch (AddressException e) {
// ignore invalid sender address.
}
}
if (senderAddress != null && !attendees.isEmpty()) {
AccountAddressMatcher acctMatcher = null;
Account acct = Provisioning.getInstance().get(AccountBy.name, senderAddress);
if (acct != null) {
acctMatcher = new AccountAddressMatcher(acct);
}
Iterator<ZAttendee> iter = attendees.iterator();
while (iter.hasNext()) {
ZAttendee att = iter.next();
// Remove the attendee if not same as the sender.
if (!(att.addressMatches(senderAddress) || (acctMatcher != null && acctMatcher.matches(att.getAddress())))) {
iter.remove();
}
}
}
// trace logging
ZAttendee att1 = !attendees.isEmpty() ? attendees.get(0) : null;
if (att1 != null) {
String ptst = IcalXmlStrMap.sPartStatMap.toIcal(att1.getPartStat());
if (!reply.hasRecurId())
ZimbraLog.calendar.info("Processing CalendarItem reply: attendee=%s, partstat=%s, id=%d, folderId=%d, subject=\"%s\", UID=%s", att1.getAddress(), ptst, mId, getFolderId(), reply.isPublic() ? reply.getName() : "(private)", mUid);
else
ZimbraLog.calendar.info("Processing CalendarItem reply: attendee=%s, partstat=%s, id=%d, folderId=%d, subject=\"%s\", UID=%s, recurId=%s", att1.getAddress(), ptst, mId, getFolderId(), reply.isPublic() ? reply.getName() : "(private)", mUid, reply.getRecurId().getDtZ());
}
// Require private access permission only when we're replying to a private series/instance.
boolean requirePrivateCheck = requirePrivateCheck(reply);
OperationContext octxt = getMailbox().getOperationContext();
Account authAccount = octxt != null ? octxt.getAuthenticatedUser() : null;
boolean asAdmin = octxt != null ? octxt.isUsingAdminPrivileges() : false;
if (!canAccess(ACL.RIGHT_ACTION, authAccount, asAdmin, requirePrivateCheck))
throw ServiceException.PERM_DENIED("you do not have sufficient permissions to change this appointment/task's state");
boolean dirty = false;
// unique ID: UID+RECURRENCE_ID
// See RFC2446: 2.1.5 Message Sequencing
// UID already matches...next check if RecurId matches
// if so, then seqNo is next
// finally use DTStamp
Invite matchingInvite = matchingInvite(reply.getRecurId());
if (matchingInvite != null) {
// up to date with the organizer's event, provided there were no major changes.
if ((matchingInvite.isOrganizer() && (matchingInvite.getLastFullSeqNo() > reply.getSeqNo())) || (!matchingInvite.isOrganizer() && (matchingInvite.getSeqNo() > reply.getSeqNo()))) {
sLog.info("Invite-Reply %s is outdated (Calendar entry has higher SEQUENCE), ignoring!", reply);
return false;
}
// maybeStoreNewReply does some further checks which might invalidate this reply
// so, postpone updating attendee information until after that.
}
// they must be replying to a arbitrary instance)
for (ZAttendee at : attendees) {
if (mReplyList.maybeStoreNewReply(reply, at, this))
dirty = true;
}
if (!dirty) {
sLog.info("Invite-Reply %s is outdated ignoring!", reply);
return false;
}
if (matchingInvite != null) {
matchingInvite.updateMatchingAttendeesFromReply(reply);
updateLocalExceptionsWhichMatchSeriesReply(reply);
} else {
createPseudoExceptionForSingleInstanceReplyIfNecessary(reply);
}
saveMetadata();
return true;
}
use of javax.mail.internet.AddressException in project spring-framework by spring-projects.
the class MimeMessageHelper method parseAddress.
private InternetAddress parseAddress(String address) throws MessagingException {
InternetAddress[] parsed = InternetAddress.parse(address);
if (parsed.length != 1) {
throw new AddressException("Illegal address", address);
}
InternetAddress raw = parsed[0];
try {
return (getEncoding() != null ? new InternetAddress(raw.getAddress(), raw.getPersonal(), getEncoding()) : raw);
} catch (UnsupportedEncodingException ex) {
throw new MessagingException("Failed to parse embedded personal name to correct encoding", ex);
}
}
Aggregations