public static void addAddressesFromRecipientList(Set<InternetAddress> to, Set<InternetAddress> cc, Set<InternetAddress> bcc, String recipientList, EnvVars envVars, TaskListener listener) { try { Set<InternetAddress> internetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.TO, listener); to.addAll(internetAddresses); if(bcc != null) { Set<InternetAddress> bccInternetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.BCC, listener); bcc.addAll(bccInternetAddresses); } if(cc != null) { Set<InternetAddress> ccInternetAddresses = convertRecipientString(recipientList, envVars, EmailRecipientUtils.CC, listener); cc.addAll(ccInternetAddresses); } } catch (AddressException ae) { LOGGER.log(Level.WARNING, "Could not create email address.", ae); listener.getLogger().println("Failed to create e-mail address for " + ae.getRef()); } catch(UnsupportedEncodingException e) { LOGGER.log(Level.WARNING, "Could not create email address.", e); listener.getLogger().println("Failed to create e-mail address because of invalid encoding"); } }
public FormValidation validateFormRecipientList(String recipientList) { // Try and convert the recipient string to a list of InternetAddress. If this fails then the validation fails. try { convertRecipientString(recipientList, new EnvVars(), TO); convertRecipientString(recipientList, new EnvVars(), BCC); convertRecipientString(recipientList, new EnvVars(), CC); return FormValidation.ok(); } catch (AddressException e) { return FormValidation.error(e.getMessage() + ": \"" + e.getRef() + "\""); } catch(UnsupportedEncodingException e) { return FormValidation.error(e.getMessage()); } }