Remove unsupported characters from email addresses

Sometimes JEMH may receives email’s that contain unsupported characters within the email addresses. When this occurs it will cause an error which will stop the issue/comment from being created.

For example the below email contains a bullet point within some of the email addresses which is unsupported. The following script will find and remove this character from the email address so that the email can successfully be processed.

Note: To use this script, to,cc,from will need to be added to Matching Headers within the Script Task configuration.

 

Error message:

Below is the error message that is shown within the Report when an email address contains an unsupported character.

javax.mail.internet.AddressExceptionAddressException: Local address contains control or whitespace: javax.mail.internet.AddressException: Local address contains control or whitespace in string ``• recipient@example.com'' at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1343) at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1191) at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:753) at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:723) at javax.mail.internet.MimeMessage.getRecipients(MimeMessage.java:549) at javax.mail.Message.getAllRecipients(Message.java:296) at javax.mail.internet.MimeMessage.getAllRecipients(MimeMessage.java:565) at com.javahollic.jira.emh.service.MessageMetaDataImpl.initRecipients(MessageMetaDataImpl.java:290) at com.javahollic.jira.emh.service.MessageMetaDataImpl.init(MessageMetaDataImpl.java:112) at com.javahollic.jira.emh.service.EMHProfileBasedConfigImpl.initWith(EMHProfileBasedConfigImpl.java:163) at com.javahollic.jira.emh.service.DefaultJEMHConfigFactory.getConfiguration(DefaultJEMHConfigFactory.java:233) at com.javahollic.jira.emh.service.DefaultJEMHConfigFactory.getConfigurations(DefaultJEMHConfigFactory.java:86) at com.javahollic.jira.emh.service.ProfileGroupRunner.handleMessage(ProfileGroupRunner.java:120) at com.javahollic.jira.emh.service.EnterpriseMessageHandlerImpl.reallyHandleMessage(EnterpriseMessageHandlerImpl.java:337) at com.javahollic.jira.emh.service.EnterpriseMessageHandlerImpl.handleMessage(EnterpriseMessageHandlerImpl.java:190) at com.javahollic.jira.emh.service.DefaultTestCaseService.runTestCase(DefaultTestCaseService.java:487) at com.javahollic.jira.emh.service.DefaultTestCaseService.runTestCase(DefaultTestCaseService.java:455) at com.javahollic.jira.emh.rest.ui.testcase.TestCaseResource.runTestCase(TestCaseResource.java:745) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Example Email:

MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: This is a starting email template, update as required From: "Admin Test" <• admin@test.com> To: "JEMH" <mailbox@localhost.com>, <• email@example.com> Cc: =?Windows-1252?Q?=95=09leras=40example=2Eco=2Eza?= <• recipient@example.com>, <test@example.com> Content-Type: text/plain; charset=UTF-8 some text

Script example:

if( headerBeans.get('from') !== null) /*Checks for bullet point within From address*/ { headerBeans.get('from').setUpdatedVal(headerBeans.get('from').getOriginalVal().replaceAll('• ','')); } if (headerBeans.get('to') !== null) /*Checks for bullet point within To address*/ { headerBeans.get('to').setUpdatedVal(headerBeans.get('to').getOriginalVal().replaceAll('• ','')); } if (headerBeans.get('cc') !== null) /*Checks for bullet point within Cc address*/ { headerBeans.get('cc').setUpdatedVal(headerBeans.get('cc').getOriginalVal().replaceAll('• ','')); }