Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

message.getBody() is not available within the JavaScript Script Pre-Processing Task. Only header values can be extracted/set.

API

Notes

message.getAllHeaders()

Get all headers of a message.

message.getHeader(name)

Get value of a message header

Parameters

  • name the name of the header to get

message.setHeader(key, value)

Set the value of a message header

Parameters

  • key (String) the name of the header to set

  • value (String) the value of the header to set

print(str)

Adds output that is recorded during execution and shown in the processing report.

Parameters

  • str (String) the string to be recorded

setOutcome(outcome, reason)

Set the processing outcome of the script

Parameters

  • outcome (String) the outcome type available outcome values: DROP, IGNORE, FORWARD

  • reason (String) the reason for the outcome

assert

See below. https://nodejs.org/api/assert.html

RegExp

Regular expressions can be evaluated within the script. This is often used for searches within string values for matching content. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp for more information.

Assertions

See https://nodejs.org/api/assert.html for full Assert API documentation.

...

Code Block
assert.equal(message.getHeader("example"), '10', 'example header value not found');

Using Regex to match a Lower Case Issue Key and remove the Issue Key from the Subject

Currently, the Regexp that is used by JEMHC to search for matching Issue Key’s is case insensitive which means that even if a Lowercase version of the issuekey is within the subject then it will be used for commenting. The below script will check for a lowercase Issue Key and if one is found then it will remove the matching Issue Key from the email subject, which then allows the issue to be created instead of commenting.

Example Script:

Code Block
var pattern = new RegExp("([a-z0-9]+-[0-9]+)").exec(message.getSubject());

if (pattern !== null)
{
    print("matched value is: " + pattern[1]);
    message.setHeader("Subject", message.getSubject().replace(pattern[1],""));
}

Example Test Case:

“cm-4” is the example Issuekey

Code Block
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
Subject: CHANGE_SUBJECT!!! cm-4
From: ryan@thepluginpeople.com
To: test@test.com
Content-Type: text/plain; charset=UTF-8

CHANGE BODY!!!

Example Test Script:

Code Block
assert.equal(message.getSubject(), 'CHANGE_SUBJECT!!! ', 'example header value not found');