Versions Compared

Key

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

...

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().toLowerCase()) ##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"))

(info) Yes, it would be handy to show ‘debug’ render output where #if #else are used ,

Jira Legacy
serverSystem JIRA
serverId31e1f342-5dce-3979-a43c-85899d565476
keyJEMHC-2936
has been logged for this.

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:

...

Extract address from name part of sender address

If you are receiving emails that contain a system address with the personal part containing the actual sender address then you can use the following address to extract and set this value from the name part as the sender.

Example Script:

Code Block
#set ($original = $taskUtils.getHeaderValue($message, "from").toString()) ##Extracts the Value found within the From header
#if ($original.contains("system@external.com"))  ##checks if sender address is a specific address
    #set ($address = $stringUtils.substringBetween($original, "(", ")")) ##Extracts the address from between the two brackets "("")"
    #set ($personal = $stringUtils.substringBetween($original, '"', "(")) ##Extracts the real senders personal part (Name)
    $message.setFrom('"' + $personal + '"' + "<"+ $address +">") ##Changes original from address to be the extracted name and email address
#end

Example Test Case:

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: "ryan example (ryan@example.com)" <system@external.com>
To: test@test.com
Content-Type: text/plain; charset=UTF-8

CHANGE BODY!!!

Test Script:

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

Proof:

...

Processing Report:

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

...

Filter by label (Content by label)
showLabelsfalse
max5
spacesJEMHC
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "JEMHC"
labelskb-how-to-article

...