Versions Compared

Key

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

...

  1. Enable pre-processing tasks by going to Profiles-> Cog icon > Edit and check Use PreProcessed Message


  2. Select the the tasks you want to enable.

Scripted Task Configuration

The Scripted Task allows you to change message with a Velocity script. 

...

After enabling the task you will be able to write your own script. This tutorial will show several examples on how to modify a message. Please note this is an advance feature and minimal programming skill are necessary (you may learn here!). Some examples:

Code Block
 
Code Block
$taskUtils.getHeader($message, 'Change-Me-If-I-Am-In-The-Message').setValue('new value') // header is changed if it exists
$taskUtils.getHeaderOrCreate($message, 'Change-Or-Create-Me').setValue('new value') // header is changed or created replacing existing value
$taskUtils.getHeaderOrCreate($message, 'Update-Me').addValue('Add This Value') // header is changed or created adding a new value to existing value
$taskUtils.getHeader($message, 'Remove-Me').remove() // headers is removed
$taskUtils.getHeader($message, 'Remove-Me-Too').setValue(null) // headers is removed
$taskUtils.getHeader($message, 'Remove-Me').setValue('  ') // headers is removed
 
$taskUtils.getHeader($message, 'CC').remove() // Removes CC
$taskUtils.getHeaderOrCreate($message, 'To').addValue('add.me.as.email.user@mycompany.com') // Adds an email user to all the issues created/updated by email.
 
//A way to fix the encoding problem, replacing the problematic encoding (ISO-8859-8-x) in all the Content-Type headers in all mime parts to UTF-8 (Content Type Mapper Task is the recommended way to fix this problem)
#foreach ($header in $taskUtils.getHeaders($message, 'Content-Type', true)) // Second parameters defines which headers to be loaded. True means include sub-parts.
   $header.setValue($header.getValues().get(0).replaceAll('ISO-8859-8-x','UTF-8'))	
#end
 

Test Case and Test Script

...

You can test your script pressing the validate button or when you submit the profile configuration. A profile with failing assertions cannot be saved. It's highly recommended to test your script adding many assertions to verify it works properly. If an assertion fails, the error below the script editor will show you the line and column number in the script that is failing.

...

...

Velocity Context

You can expand the velocity context to find links to javadoc for published Java classes:

...

Content Type Mapper

...

PreProc task configuration

Sometimes, email clients refer to the encoding of content within the email in such a way as to make it unprocessable by JEMHC /Javamail.  Sometimes, it is because an illegal value is presented in the email, for example 7-bit which is not legal but 7bit is (see Oracle page referring RFC-2045 supported types).  JEMHC can fix problems like this but they need to be configured:

...

In our example, $taskUtils.getHeaders($message, 'Content-Type', true) returns the list of all Content-Type headers any part level.

Example Pre Proc Scripts

Replace From: Address

This example shows how to manipulate the From: address, to detect one domain and swap it out for another.

Script

Code Block
#set ($original = $message.getFrom()[0].getAddress()) ##Extracts the Value found within the From header
#if ($original.endsWith("@thepluginpeople.com"))  ##checks if sender address is a specific address
    #set ($name = $original.split("@")[0])
    $message.setFrom($name + "@replaced.com") ##Changes original from address to be the extracted name and email address
#end

Example Email

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!!!
From: andy@thepluginpeople.com
To: test@example.com
Content-Type: text/plain; charset=UTF-8

CHANGE BODY!!!

Test script

Code Block
$assert.assertTrue($message.getFrom()[0].getAddress().equalsIgnoreCase("andy@replaced.com"))

Proof

...

Processing Report

Here you can see the example mail processing report generated by JEMHC for our support project, a user would have been associated if it didn’t exist, in this case, we’ve simply created a new portal user:

...