/** * Generates an instance of an NHINDAddressCollection from a collection of NHINDAddress addresses. * @param source A collection of NHINDAddress addresses to seed this object with. * @return n instance of an NHINDAddressCollection object containing all of the source addresses. */ public static NHINDAddressCollection create(Collection<NHINDAddress> source) { NHINDAddressCollection addresses = new NHINDAddressCollection(); addresses.addAll(source); return addresses; }
/** * Categorizes recipients as either trusted or untrusted (rejected). * @param minTrustStatus The minimum level of trust a recipient must have in order to be considered trusted. */ protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) { rejectedRecipients = NHINDAddressCollection.create(getRecipients().getUntrusted(minTrustStatus)); getRecipients().removeUntrusted(minTrustStatus); } }
/** * Removes all addresses from the collection that do not meet the minimum trust status. */ public void removeUntrusted(TrustEnforcementStatus minTrustStatus) { // Remove anybody who is not trusted for (int i = this.size() - 1; i >=0; --i) if (!this.get(i).isTrusted(minTrustStatus)) this.remove(i); }
@Override /** * Converts the collection to a list of addresses compatible with an message routing header message (including the standard delimiter). * @return The collection as an RFC compliant message routing header. */ public String toString() { return InternetAddress.toString(this.toArray(new InternetAddress[this.size()])); }
final NHINDAddressCollection xdRecipients = new NHINDAddressCollection(); final MimeMessage msg = smtpMailMessage.getMimeMessage(); xdRecipients.add(new NHINDAddress(s)); msg.setRecipients(RecipientType.TO, xdRecipients.toArray(new Address[0])); notificationProducer.produce(new Message(msg), xdRecipients.toInternetAddressCollection()); if (notifications != null && notifications.size() > 0)
/** * Splits recipients into domain recipients and external recipients. The agent's domains are used to determine a recipients category. * @param domain A collection of local domains supported by the agent. */ protected void categorizeRecipients(Collection<String> domains) { if (domains == null || domains.size() == 0) { throw new IllegalArgumentException(); } NHINDAddressCollection recipients = this.getRecipients(); this.domainRecipients = new NHINDAddressCollection(); this.otherRecipients = new ArrayList<NHINDAddress>(); for (NHINDAddress address : recipients) { if (address.isInDomain(domains)) { this.domainRecipients.add(address); } else { this.otherRecipients.add(address); } } }
if (rejectedRecipients == null || rejectedRecipients.size() == 0) this.getTo().removeAll(rejectedRecipients); if(this.getTo().isEmpty()) { this.getMessage().removeHeader(MailStandard.Headers.To); this.getMessage().setHeader(MailStandard.Headers.To, this.getTo().toString()); this.getCC().removeAll(rejectedRecipients); if(this.getCC().isEmpty()) { this.getMessage().removeHeader(MailStandard.Headers.CC); this.getMessage().setHeader(MailStandard.Headers.CC, this.getCC().toString()); this.getBCC().removeAll(rejectedRecipients); if(this.getBCC().isEmpty()) { this.getMessage().removeHeader(MailStandard.Headers.BCC); this.getMessage().setHeader(MailStandard.Headers.BCC, this.getBCC().toString());
final NHINDAddressCollection originalRecipList = NHINDAddressCollection.create(recipients); (List<InternetAddress>)recipients.toInternetAddressCollection(), (InternetAddress)sender); result.getProcessedMessage().getRejectedRecipients().size() > 0 && smtpMessage.getRecipientAddresses() != null && smtpMessage.getRecipientAddresses().size() > 0)
/** * Indicates if the message has any recipients. * @return True if the message has recipients. False otherwise. */ public boolean hasRecipients() { return (recipients != null && recipients.size() > 0); }
/** * Gets a list of recipients in the message that are not trusted by the address. * @return A list of recipients in the message that are not trusted by the address. */ public NHINDAddressCollection getRejectedRecipients() { if (this.rejectedRecipients == null) { this.rejectedRecipients = new NHINDAddressCollection(); } return rejectedRecipients; }
protected void checkEnvelopeAddresses(NHINDAddressCollection recipients, NHINDAddress sender) { if (recipients == null || recipients.size() == 0) { throw new AgentException(AgentError.NoRecipients); } if (sender == null) { throw new AgentException(AgentError.NoSender); } recipients.setSource(AddressSource.RcptTo); sender.setSource(AddressSource.MailFrom); }
/** * Produces an ack MDN message for the incoming message. * @param envelope The incoming message that will have an MDN ack message sent to the senders. * @return A collection of notification messages that will be sent to the incoming message senders. */ public Collection<NotificationMessage> produce(IncomingMessage envelope) { if (envelope == null) { throw new IllegalArgumentException(); } if (!settings.isAutoResponse() || !envelope.hasDomainRecipients() || NotificationHelper.isMDN(envelope.getMessage())) { LOGGER.info("No MDN messages to send."); return Collections.emptyList(); } LOGGER.info("Generating MDN \"processed\" messages"); Collection<InternetAddress> senders = envelope.getDomainRecipients().toInternetAddressCollection(); Collection<NotificationMessage> notifications = NotificationHelper.createNotificationMessages(envelope.getMessage(), senders, this); return notifications; }
NHINDAddressCollection retVal = new NHINDAddressCollection(); retVal.add(new NHINDAddress(addr.getAddress(), source));
/** * Sets the collection of message recipients. * @param recipients The collection of message recipients. */ protected void setRecipients(NHINDAddressCollection recipients) { if (recipients == null || recipients.size() == 0) throw new AgentException(AgentError.NoRecipients); this.recipients = recipients; }
notificationProducer.produce(new Message(msg), recipients.toInternetAddressCollection()); if (notifications != null && notifications.size() > 0)
/** * Get the recipients of a message by retrieving the recipient list from the SMTP envelope first, then falling back to the recipients * in the message if the recipients cannot be retrieved from the SMTP envelope. * @param mail The mail object that contains information from the SMTP envelope. * @return Collection of message recipients. * @throws MessagingException */ public static NHINDAddressCollection getMailRecipients(SMTPMailMessage mail) throws MessagingException { final NHINDAddressCollection recipients = new NHINDAddressCollection(); // uses the RCPT TO commands final Collection<InternetAddress> recips = mail.getRecipientAddresses(); if (recips == null || recips.size() == 0) { // fall back to the mime message list of recipients final Address[] recipsAddr = mail.getMimeMessage().getAllRecipients(); for (Address addr : recipsAddr) { recipients.add(new NHINDAddress(addr.toString(), (AddressSource)null)); } } else for (InternetAddress addr : recips) recipients.add(new NHINDAddress(addr)); return recipients; }
/** * Creates a collection of recipients based on the TO, CC, and BCC headers in the wrapped message. * @return A collection of recipients. */ protected NHINDAddressCollection collectRecipients() { NHINDAddressCollection addresses = new NHINDAddressCollection(); if (this.getTo() != null) { addresses.addAll(this.getTo()); } if (this.getCC() != null) { addresses.addAll(this.getCC()); } if (this.getBCC() != null) { addresses.addAll(this.getBCC()); } return addresses; }
/** * Indicates if the message has recipients that are not trusted by the address. * @return True if the message has recipients that are not trusted by the address. False otherwise. */ public boolean hasRejectedRecipients() { NHINDAddressCollection rejRecipients = this.getRejectedRecipients(); return (rejRecipients != null && rejRecipients.size() > 0); }