Skip to content
Permalink
Browse files
Fix JENKINS-32889
Change semicolons to commas to support InternetAddress.parse
  • Loading branch information
slide committed Feb 13, 2016
1 parent fdcda73 commit 1fe01dadf454de9a7e49b0b547b4a05485a89313
@@ -1,20 +1,16 @@
package hudson.plugins.emailext;

import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.logging.Logger;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;

import hudson.EnvVars;
import hudson.model.TaskListener;
import hudson.model.User;
import hudson.plugins.emailext.ExtendedEmailPublisherContext;
import hudson.plugins.emailext.ExtendedEmailPublisherDescriptor;
import hudson.plugins.emailext.plugins.ContentBuilder;
import hudson.tasks.Mailer;
import hudson.util.FormValidation;
@@ -28,8 +24,6 @@ public class EmailRecipientUtils {

private static final Logger LOGGER = Logger.getLogger(EmailRecipientUtils.class.getName());

public static final String COMMA_SEPARATED_SPLIT_REGEXP = "[,\\s]+";

public static final int TO = 0;
public static final int CC = 1;
public static final int BCC = 2;
@@ -43,7 +37,7 @@ public static Set<InternetAddress> convertRecipientString(String recipientList,
throws AddressException, UnsupportedEncodingException {
final Set<InternetAddress> internetAddresses = new LinkedHashSet<InternetAddress>();
if (!StringUtils.isBlank(recipientList)) {
final String expandedRecipientList = fixupSpaces(envVars.expand(recipientList));
final String expandedRecipientList = fixupDelimiters(envVars.expand(recipientList));
InternetAddress[] all = InternetAddress.parse(expandedRecipientList.replace("bcc:", "").replace("cc:", ""));
final Set<InternetAddress> to = new LinkedHashSet<InternetAddress>();
final Set<InternetAddress> cc = new LinkedHashSet<InternetAddress>();
@@ -130,11 +124,13 @@ public FormValidation validateFormRecipientList(String recipientList) {
}
}

private static String fixupSpaces(String input) {
private static String fixupDelimiters(String input) {
input = input.replaceAll("\\s+", " ");
if(input.contains(" ") && !input.contains(",")) {
input = input.replace(" ", ",");
}

input = input.replace(';', ',');
return input;
}

@@ -16,9 +16,12 @@

import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import org.junit.Rule;
import org.junit.Test;

import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class EmailRecipientUtilsTest {
@@ -36,6 +39,20 @@ public void before() throws Throwable {
private EmailRecipientUtils emailRecipientUtils;
private EnvVars envVars;

@Test
@Issue("JENKINS-32889")
public void testDelimiters() throws Exception {
String[] testStrings = { "mickey@disney.com;donald@disney.com;goofy@disney.com;pluto@disney.com",
"mickey@disney.com donald@disney.com goofy@disney.com pluto@disney.com",
"mickey@disney.com,donald@disney.com,goofy@disney.com,pluto@disney.com" };
for(String testString : testStrings) {
Set<InternetAddress> addresses = emailRecipientUtils.convertRecipientString(testString, envVars, EmailRecipientUtils.TO);

assertFalse(addresses.isEmpty());
assertEquals(addresses.size(), 4);
}
}

@Test
public void testConvertRecipientList_emptyRecipientStringShouldResultInEmptyEmailList()
throws AddressException, UnsupportedEncodingException {

0 comments on commit 1fe01da

Please sign in to comment.