Handle Wiki-Markup with Comment Only Body Delimiters

Problem Scenario

Your incoming emails contain wiki formatting mark-up for email fields such as "From", "Sent", "To" and "Subject". You wish to have a comment only body delimiter Regular Expression set up in order to isolate just the comment section of an email. However, due to the wiki mark-up in the email content this is not currently working.

For this guide, lets say that you have an issue that has been created, but the description is incorrectly created as:

*From:* John Smith *Sent:* Friday, August 11, 2015 09:58 AM *To:* Example Support <example.support@example.com> *Subject:* RE: JIRA (EX-1) Test This is an example of an emails body text. Kind regards, John Smith Example Company *From:* Example Support *Sent:* Monday, August 09, 2015 07:13 AM *To:* John Smith <example@example.com> *Subject:* JIRA (EX-1) Test TEST TEST TEST TEST TEST

Solution

By default, you may have the following as one of your "Comment Only Body Delimiter Regexps":

\nFrom:.*\nSent:.*\nTo:.*\nSubject:.*\n

This would work correctly if you did not have any wiki mark-up being applied to the emails that are inbound to JEMH. However, in the scenario example we have the asterisk "*" being used to apply strong text formatting.

Here is the resulting comment in JIRA using our example email:

In order for the regexp to function correctly we need to ensure that it is expecting these asterisks by adding it to our regexp. The complication here is that the asterisk is already being used in regexp syntax as a special character, to match 0 or more of the preceding regexp token. Therefore, we need to escape the character. This is done by using the backslash character "\" before the asterisk:

\n\*From:\*.*\n\*Sent:\*.*\n\*To:\*.*\n\*Subject:\*.*\n

With this regexp being used instead of the previous one, we now get the following result in our issue:

 

 

The above solution can be applied for any wiki syntax that may be there, so long as the special characters that the syntax uses are appropriately escaped in your regexp.

Related articles