/** * Gets the sender of the message. * @param mail The mail object to get the mail information from. * @return The sender of the message. * @throws MessagingException */ public static NHINDAddress getMailSender(SMTPMailMessage mail) throws MessagingException { // get the sender final InternetAddress senderAddr = getSender(mail); if (senderAddr == null) throw new MessagingException("Failed to process message. The sender cannot be null or empty."); // not the best way to do this return new NHINDAddress(senderAddr, AddressSource.From); }
protected Map<String, Collection<InternetAddress>> groupByDomain(Collection<InternetAddress> recipients) { final HashMultimap<String, InternetAddress> groupByServerMultimap = HashMultimap.create(); for (InternetAddress recipient : recipients) { final NHINDAddress addr = new NHINDAddress(recipient); groupByServerMultimap.put(addr.getHost(), recipient); } return groupByServerMultimap.asMap(); } }
toAddrs.add(new NHINDAddress((InternetAddress)addr)); map(toAddr -> new NHINDAddress(toAddr.toInternetAddress())).collect(Collectors.toList());
/** * 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; }
retVal.add(new NHINDAddress(addr.getAddress(), source));
final String domainName = new NHINDAddress(smtpMessage.getRecipientAddresses().get(0)).getHost();
/** * Constructs an envelope from a message. * @param message The mime message. */ public DefaultMessageEnvelope(Message message) { if (message == null) throw new IllegalArgumentException(); this.message = message; this.setRecipients(this.collectRecipients()); try { if (message.getFrom() == null || message.getFrom().length == 0) throw new AgentException(AgentError.MissingFrom); this.setSender(new NHINDAddress((InternetAddress)message.getFrom()[0], AddressSource.From)); } catch (MessagingException e) { throw new AgentException(AgentError.MissingFrom, e); } }
xdRecipients.add(new NHINDAddress(s));