Versions Compared

Key

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

(info) since 3.3.42

Table of Contents
Info

Please refer to the Pre-Processing Task page for setting up and configuring Pre-Processing Tasks: How To Use Pre-Processing Tasks

After enabling Script Task, return to the profile configuration page and select the edit (pen) icon for Script Task.

...

Pre-Processing Scope : Headers Only

Pre-processing only currently applies to Headers, not the body content, owing to the encoding complexities therein. If this is of interest, please reach out to support@thepluginpeople.com.

Configuration

The edit icon launches the pre-proc script editor.

...

Evaluates the Header Script against the selected Test Case. The result of the script test will be shown below the existing form.

...

Matching Headers:

Code Block
subject,x-subject

Script:

Code Block
 var subject = headerBeans.get('subject').getOriginalVal(); 
 var hdr = jemhUtils.addPreProcHeader("x-subject", "NEW "+subject); 
 print('new header: '+hdr.getUpdatedVal());
 headerBeans.put("x-subject", hdr); 

...

Affected Headers will show changes and additions:

...

Preview Context

This section is to explain what context keys are in the Script Pre-Processing task. Also explains what they are used for when making a script.

Note

Currently three of the context keys are not working and are showing a console error. The three context key’s that are not working are Body, Subject and Related Issue.

Key

Class

Description

allAddresses

javax.mail.internet.InternetAddress []

Array of all addresses in the email

baseUrl

java.lang.String

Jira application URL. For example http://localhost:8080

bccAddresses

javax.mail.internet.InternetAddress []

Array of all addresses in Bcc header in the email

body

java.lang.String

Email content from the body of the email

ccAddresses

javax.mail.internet.InternetAddress []

Array of addresses from the Cc header in the email

commentManager

com.atlassian.jira.issue.comments.DefaultCommentManager

Creates or removes Jira comments in the given Issue

context

java.util.HashMap

Map of all context keys and all related context items

customFieldManager

com.atlassian.jira.issue.managers.CachingCustomFieldManager

Manages Custom fields and their values

fromAddress

javax.mail.internet.InternetAddress

Sender address of the email

groupManager

com.atlassian.jira.security.groups.RequestCachingGroupManager

Manages Atlassian’s groups and it’s members

headerBeans

java.util.HashMap

Header values from the email for example the Sender address and subject

issueLinkService

com.atlassian.jira.bc.issue.link.DefaultIssueLinkService

Creates Issue links between Jira issues

issueManager

com.atlassian.jira.issue.managers.RequestCachingIssueManager

Provides a number of methods for managing Jira Issues

jemhUtils

com.javahollic.jira.emh.service.DefaultJEMHVelocityContextUtils

Provides a range of scripting utils including managed of headers shown on this page

jemhVersion

java.lang.String

The installed version of JEMH

log

org.apache.log4j.Logger

Allows output into the JEMH log

message

javax.mail.internet.MimeMessage

The Email being processed

projectRoleManager

com.atlassian.jira.security.roles.DefaultProjectRoleManager

Manages the project roles of the sender

relatedIssue

com.atlassian.jira.mail.TemplateIssue

The Issue that is being commented on (null if creating a new Issue)

remoteIssueLinkService

com.atlassian.jira.bc.issue.link.DefaultRemoteIssueLinkService

Creates Remote Issue Links that are used in external for example in a third party helpdesk

searchService

com.atlassian.jira.bc.issue.search.DefaultSearchService

Provides functionality related to searching in Jira using JQL. For example query string generation, parsing and validation

senderUser

com.atlassian.jira.user.DelegatingApplicationUser

The Jira User associated to the From address

subject

java.lang.String

The subject of the email

toAddresses

javax.mail.internet.InternetAddress []

Array of all addresses in the To header of the email

userManager

com.atlassian.jira.user.util.DefaultUserManager

Manages Jira Users on the instance

userPropertyManager

com.atlassian.jira.user.ZDUUserPropertyManager

Manages all of the Property sets that are associated with Jira users

userSearchService

com.atlassian.jira.bc.user.search.DefaultUserPickerSearchService

Provides search functionality for Jira User e.g. findUserByEmail()

watcherManager

com.atlassian.jira.issue.watchers.DefaultWatcherManager

Allows watches to be added/removed from the Jira Issue

Changing Headers

Example Test Case

To test this feature out, create a new Test Case, using the following Test Case Content:

Image Modified

 

 

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
Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: This is a starting email template, update as required
From: from@from.com
To: oldTo@oldTo.com, changeme@thiswontwork.com
cc: removeme@cc.com
Content-Type: text/plain; charset=UTF-8

some text 

...

Code Block
/*Edit Headers*/ 
if(headerBeans.get('to') != null){
  var toAddress = jemhUtils.getOriginalAddressees(headerBeans.get('to')); 
  print('To Address Header values:', toAddress); 
  var firstRecipient = toAddress.get(0);
  /*Set Address and Personal values of selected recipient*/
  firstRecipient.setPersonal("changed recipient");
  firstRecipient.setAddress("changed@changed.com");

  var updatedHeader = jemhUtils.updatePreProcHeader(toAddress, headerBeans.get('to')); 
  print(updatedHeader.getUpdatedVal()); 
  print(updatedHeader.getUpdatedVal()); 
  
  /*Replace Header with new value here*/ 
  headerBeans.replace("to", updatedHeader); 
}
Image Modified

 

Inserting new addresses into an existing Header

...

Code Block
/*Edit Headers*/ 
if(headerBeans.get('to') != null){
  var toAddress = jemhUtils.getOriginalAddressees(headerBeans.get('to')); 
  print('To Address Header values:', toAddress); 
  
  /*create new address*/ 
  var newAddress = jemhUtils.createInternetAddress('new', 'new@new.com'); 
  /*adding new address to To header*/
  toAddress.add(newAddress); 
  var updatedHeader = jemhUtils.updatePreProcHeader(toAddress, headerBeans.get('to')); 
  print(updatedHeader.getUpdatedVal()); 
  print(updatedHeader.getUpdatedVal()); 
  
  /*Replace Header with new value here*/ 
  headerBeans.replace("to", updatedHeader); 
}
Image Modified

 

Adding New Headers

Note

Any new Headers you wish to add must be listed the “Matching Headers” csv, or they will not be processed!

...

Code Block
/* Adding a header */ 
var bccHeader = jemhUtils.addPreProcHeader('bcc', 'newBcc@newBcc.com'); 
if(bccHeader != null){ 
  headerBeans.replace('bcc', bccHeader); 
  print(headerBeans.get('bcc')); 
} 
Image Modified

 

Use Auditing to see the post-change email content

Once the mail is changed you can download both the original mail, and the Edited mail:

image-20240312-112950.pngImage Added

API Reference

...

Method

Used for

Example

jemhUtils.getOriginalAddressees()

Retrieving To/Cc/Bcc/From/Delivered-To Header Values

Retrieving addresses from a specific header to compare against or edit:

Code Block
var returnedAddressees = jemhUtils.getOriginalAddressees(headerBeans.get('to'));

jemhUtils.updatePreProcHeader()

Updating To/Cc/Bcc/From/Delivered-To Header Values

Updating the Sender From address:

Code Block
jemhUtils.updatePreProcHeader(editedAddressees, headerBeans.get('from'))

/* OR non recipient example */
jemhUtils.updatePreProcHeader(editedValue, headerBeans.get('subject'));

headerBeans.remove(“cc”)

Removing Headers

Removing unwanted Cc address:

Code Block
headerBeans.remove('cc');

jemhUtils.createInternetAddress(“nn”)

Creating a new Recipient to add to Header

Inserting a Bcc header:

Code Block
/*Remember to add Bcc into Matching Headers*/

aHeaderBean.getOriginalVal()

Non-Recipient Header values

Retrieving the Subject Header:

Code Block
/*Remember to add Subject into Matching Headers*/
var subject = headerBeans.get('subject').getOriginalVal());

aHeaderBean.setUpdatedVal(“nnnn”)

Non-Recipient Header values

Changing the Subject Header:

Code Block
/*Remember to add Subject into Matching Headers*/
headerBeans.get('subject').setUpdatedVal("This is the new Subject value");

Body Script

...