Search in sources :

Example 1 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 2 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 3 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 4 with AddressException

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;
}
Also used : Account(com.zimbra.cs.account.Account) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZAttendee(com.zimbra.cs.mailbox.calendar.ZAttendee) AddressException(javax.mail.internet.AddressException) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 5 with AddressException

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);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

AddressException (javax.mail.internet.AddressException)114 InternetAddress (javax.mail.internet.InternetAddress)99 MimeMessage (javax.mail.internet.MimeMessage)40 MessagingException (javax.mail.MessagingException)34 ArrayList (java.util.ArrayList)22 Address (javax.mail.Address)21 IOException (java.io.IOException)19 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)18 UnsupportedEncodingException (java.io.UnsupportedEncodingException)17 Properties (java.util.Properties)16 Date (java.util.Date)14 Session (javax.mail.Session)13 MimeBodyPart (javax.mail.internet.MimeBodyPart)13 File (java.io.File)11 MimeMultipart (javax.mail.internet.MimeMultipart)11 Message (javax.mail.Message)10 Multipart (javax.mail.Multipart)8 DataHandler (javax.activation.DataHandler)7 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 Locale (java.util.Locale)5