Replicate Body Delimiter functionality and modify regular expression pattern flags as desired.

Disclaimer

Please do not attempt this without considering the following!

Why the default Regular Expression flags are fixed and newlines are added

Historically, JEMH allowed users the freedom to put any expression in, this led many many times to ‘but why did you let me shoot myself in the foot’ (e.g. multiple uses of .* on small emails have no discernible performance impact. However for a larger payload it is possible that Jira mail processing (and possibly Jira) will stop responding for some hours/indefinitely (from the perspective of the user). Due to the high processing demands.

After which Default Expressions always matched a new line, because email attributions always start on a new line. In order to address the regular occurrence of system outages.

New lines meant simpler expressions for users, they always start on a new line, period. The way JEMH interprets the expression is simply to get the index of the first match, it doesn't need to match ‘all’ the trailing content as well, its a delimiter. By prefixing any delimiter expression by a new line we restrict the maximum regexp engine matches to be a function of line count, not line character count as well, reducing to regexp engine search range by a factor of 80+.

If you are going to use and modify this script then is possibility that a System outage can occur.

Introduction

NOTE: If the Body Delimiter feature is enabled in the Project Mapping then it will be applied in addition to this script! If you do not want this outcome then disable the Body Delimiter by either having disabling the regular expressions by unchecking their comment and create checkboxes or by deleting the expressions entirely. More information on the Body Delimiter feature here: https://thepluginpeople.atlassian.net/wiki/spaces/JEMH/pages/446431241.

This guide will show you how to customise the behaviour of the Regexp Expression flags in case the default regular expression flags related to the Body Delimiter do not fit your requirements.

First determine whether you want this script (which replicates the Body Delimiter) to apply on a single project mapping or the whole profile.

While it is possible to do both in the Script Field Processor, if you require this functionality for specific project mappings then using this script in the Script Rule will easily scope the script it’s related project mapping.

More information on both the Script Field Processor and Script Rule can be found here:

The Script

Using this in the Script Field Processor will require directives to be enabled! More information regarding this here: .

More information on the flags available to the regular expression engine here: .

Source code is here: . If you need the Flag values.

 

var modifiedBody = body; var bodyDelimiters = ["Your expression 1", "Your expression 2"]; //These correspond to the flags mentioned in https://docs.oracle.com/javase/tutorial/essential/regex/pattern.html var dotAllFlag = 0x20; var multilineFlag = 0x08; var unicodeCaseFlag= 0x40; //Add the desired flags here var regexpFlags = dotAllFlag | multilineFlag | unicodeCaseFlag print('Number of body delimiters [' + bodyDelimiters.length + '].'); //Each delimeter is processed in this for loop for (var i = 0; i < bodyDelimiters.length; i++) { var aBodyDelimiter= bodyDelimiters[i]; print('Processing the following delimiter [' + aBodyDelimiter + '].'); var matcherClass = Java.type("java.util.regex.Matcher"); var quotedBody = matcherClass.quoteReplacement(modifiedBody); var pattern = Java.type("java.util.regex.Pattern").compile(aBodyDelimiter, regexpFlags); var matcher = pattern.matcher(quotedBody); if(matcher.find()) { var startIndex = matcher.start(); //If the expression applied to the body(comment or summary of the issue) results in empty then prevent the expression from applying (determine if you want this behaviour NOTE: if comment is empty then no comment is added to the issue.) if(startIndex === 0) { print('Body Delimiter expression [' + aBodyDelimiter + '] would remove all content! Ignoring this Delimiter') } //Actually applying the expression to the body else { print('Body Delimiter expression [' + aBodyDelimiter + '] was applied!') var sub = quotedBody.substring(0, startIndex); if(quotedBody.length() > body.length()) { sub = quotedBody.replace("\\\\", "\\").replace("\\$", "$"); } modifiedBody = sub; //condition for create and commenting remove either/none depending on your requirements if(relatedIssue) { resultMap.put("comment", modifiedBody); } else { result.put("description", modifiedBody); } print('[' + aBodyDelimiter + '] result was [' + modifiedBody + ']'); } } }


Your regular expressions would be added to the bodyDelimiters list variable feel free to remove the place holders. Add your desired flags to the regexpFlags using a | for each new flag.