JavaScript Pre-Processing Examples
Available Script Context
message.getBody()
is not available within the JavaScript Script Pre-Processing Task. Only header values can be extracted/set.
API | Notes |
---|---|
| Get all headers of a message. |
| Get value of a message header Parameters
|
| Set the value of a message header Parameters
|
| Adds output that is recorded during execution and shown in the processing report. Parameters
|
| Set the processing outcome of the script Parameters
|
| See below. Assert | Node.js v23.3.0 Documentation |
| Regular expressions can be evaluated within the script. This is often used for searches within string values for matching content. See RegExp - JavaScript | MDN for more information. |
Assertions
Textual Assertions
See Assert | Node.js v23.3.0 Documentation for full Assert API documentation.
assert.equal('The actual value', 'An expected value', 'Helpful message');
Where the first value is an expression which captures a value in the email after it has been processed by your script, the second value is an expression indicating the value you expect to receive, and the third value is any message you wish to set. This final value will be output when an assertion fails, so it is recommended to set the message to something you will find useful.
Running the above Test Script example against any email will produce the following output (if you do not with to provide a message you can simply omit it)
assert.equal('The actual value', 'An expected value');
A more realistic example is as follows.
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
Subject: Some other subject
From: andy@thepluginpeople.com
To: test@example.com
Content-Type: text/plain; charset=UTF-8
CHANGE BODY!!!
Test Script:
Here we assert that the Subject has a certain value.