-
Notifications
You must be signed in to change notification settings - Fork 723
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update delimiter fix-up for personal parts
Updated the delimiter fix-up to take into account personal names in email addresses (e.g., Slide O Mix <someone@email.com>). See JENKINS-69681
- Loading branch information
Showing
2 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/java/hudson/plugins/emailext/EmailRecipientUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hudson.plugins.emailext; | ||
|
||
import jakarta.mail.internet.InternetAddress; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class EmailRecipientUtilsTest { | ||
@Test | ||
public void testFixupDelimiters() throws Exception { | ||
String output; | ||
output = EmailRecipientUtils.fixupDelimiters(" Name Surname <n.Surname@mymail.com> "); | ||
assertEquals("Name Surname <n.Surname@mymail.com>", output); | ||
InternetAddress[] addresses = InternetAddress.parse(output); | ||
assertEquals(1, addresses.length); | ||
assertEquals("Name Surname", addresses[0].getPersonal()); | ||
assertEquals("n.Surname@mymail.com", addresses[0].getAddress()); | ||
|
||
output = EmailRecipientUtils.fixupDelimiters("user0, user1@email.com User Two <user2@email.com> user3@email.com "); | ||
assertEquals("user0, user1@email.com, User Two <user2@email.com>, user3@email.com", output); | ||
addresses = InternetAddress.parse(output); | ||
assertEquals(4, addresses.length); | ||
|
||
assertNull(addresses[0].getPersonal()); | ||
assertEquals("user0", addresses[0].getAddress()); | ||
|
||
assertNull(addresses[1].getPersonal()); | ||
assertEquals("user1@email.com", addresses[1].getAddress()); | ||
|
||
assertEquals("User Two", addresses[2].getPersonal()); | ||
assertEquals("user2@email.com", addresses[2].getAddress()); | ||
|
||
assertNull(addresses[3].getPersonal()); | ||
assertEquals("user3@email.com", addresses[3].getAddress()); | ||
} | ||
} |