since 3.3.42
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.
Configuration page
Header Script
What each field means?
Script Type - All Script Engines and Languages installed that can process Scripts. For more information on adding new Scripting Engines, please see: Installing a Scripting runtime Engine like Groovy
Matching Headers - A CSV list of headers that can be processed and altered by the Script Pre-Processing task.
Header Script - The Script that will be run as a Pre-Processing task. Using the “Preview HeaderScript” button will run the script using the provided values and displayed below.
Test Case Selector - A list of all Test Cases that are linked to the given Profile. The selected Test Case will
Preview Header Script - Tests the Header Script against the selected Test Case. The result of the script test will be shown below the existing form. There are two tabs:
Console Output - displays the console result of the script. To add something to the console, use print. e.g.
print("Display this to the console Output please"); //or var x = "PrintVars"; print(x);
Affected Headers - Displays the Headers that have been changed by the script.
API Reference
$jemhUtils == http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/3.3.80/com/javahollic/jira/emh/api/IJEMHVelocityContextUtils.html
$headeBeans == https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
preProcHeader class == http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/3.3.80/com/javahollic/jira/emh/api/preproc/PreProcHeaderBean.html
Methods used to Alter Headers
headerBeans expects Lower case key, i.e. ‘subject’, ‘content-type’, etc.
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: var returnedAddressees = jemhUtils.getOriginalAddressees(headerBeans.get('to')); |
jemhUtils.updatePreProcHeader() | Updating To/Cc/Bcc/From/Delivered-To Header Values | Updating the Sender From address: 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: headerBeans.remove('cc'); |
jemhUtils.createInternetAddress(“nn”) | Creating a new Recipient to add to Header | Inserting a Bcc header: /*Remember to add Bcc into Matching Headers*/ |
aHeaderBean.getOriginalVal() | Non-Recipient Header values | Retrieving the Subject Header: /*Remember to add Subject into Matching Headers*/ var subject = headerBeans.get('subject').getOriginalVal()); |
aHeaderBean.setUpdatedVal(“nnnn”) | Non-Recipient Header values | Changing the Subject Header: /*Remember to add Subject into Matching Headers*/ headerBeans.get('subject').setUpdatedVal("This is the new Subject value"); |
Affected Headers display a list of all Headers from the Test Case that have been altered, added, or removed.
Don’t forget to Submit to save any changes to the Script Task!
Example Test Case
To test this feature out, create a new Test Case, using the following Test Case Content:
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
Altering Existing Header Values
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
This example will alter the first recipient in the To address header, changing its value:
/*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); }
Inserting new addresses into an existing Header
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
This example will alter the existing To address header, and will insert a new recipient into the To header:
/*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); }
Adding New Headers
Any new Headers you wish to add must be listed the “Matching Headers” csv, or they will not be processed!
This example will add the Bcc address header, with the provided values:
/* Adding a header */ var bccHeader = jemhUtils.addPreProcHeader('bcc', 'newBcc@newBcc.com'); if(bccHeader != null){ headerBeans.replace('bcc', bccHeader); print(headerBeans.get('bcc')); }
Example: Adding a Delivered-To header if one is not present
Script
if(headerBeans.get("Delivered-To") == null) { var hdr = jemhUtils.addPreProcHeader("Delivered-To", "yourmailbox@blah.com"); headerBeans.put("Delivered-To", hdr); print("created default Delivered-To: header : "+hdr.getUpdatedVal()); }
Config screenshot:
Inbound Mail Processing output, showing injected value
Removing Existing Headers
Any Headers you wish to remove must be in the Matching Headers csv, or they will not be processed!
This example will remove the unwanted Cc address header:
/*Removing a header!*/ if(headerBeans.get('cc') != null){ var ccAdd = jemhUtils.getOriginalAddressees(headerBeans.get('cc')); headerBeans.remove('cc'); }
Example of how to change Content-type of email
This example will show how to fix incorrect Content-Type of an email.
Test Case Example
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: "Andy Brook" <andy@localhost> To: changeme@thiswontwork.com Content-Type: text/plain; charset=UTF-8 some text
Script example
var fromAddress = jemhUtils.getOriginalAddressees(headerBeans.get('from')).get(0).getAddress(); if (fromAddress != null){ print('From address: ' + fromAddress); if (fromAddress.equals('andy@localhost')){ var ct = headerBeans.get('content-type'); var contentType = ct.getOriginalVal(); print('Old content-type:' + contentType); if (contentType.startsWith('text/plain')){ contentType = contentType.replace('text/plain','text/html'); ct.setUpdatedVal(contentType); contentType = ct.getUpdatedVal(); print('New content-type: ' + contentType); } } }
Example of how to fix invalid email address format
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
This example will show how to fix incorrect To header email address format to match the catch email address.
Test Case Example
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: admin@localhost.com To: changeme <changeme> Content-Type: text/plain; charset=UTF-8 some text
Script example
if (headerBeans.get('to')!=null) { print('originalTo:', headerBeans.get('to').getOriginalVal()); if (headerBeans.get('to').getOriginalVal() == "changeme <changeme>") { headerBeans.get('to').setUpdatedVal("changeme <changeme@domain.com>"); } print('updatedTo:', headerBeans.get('to').getUpdatedVal()); }
Example of how to fix invalid content-type header
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
This example will show how to fix the invalid Content-Type header when is missing a MIME subtype.
Test Case Example
MIME-Version: 1.0 Date: Thu, 12 Aug 2021 12:05:10 +0100 Message-ID: CACQqMReZmHMHG1XXWic6WthLBYHe223mth=ndmTNXnec_gt9XA@mail.gmail.com Subject: Testing Type-Content From: Vladyslav Zacharko vlad@thepluginpeople.com To: changeme@thiswontwork.com Content-Type: multipart/; boundary="0000000000005d46f805c95ab59d" --0000000000005d46f805c95ab59dContent-Type: text/plain; charset="UTF-8" What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesettingindustry. Lorem Ipsum has been the industry's standard dummy text eversince the 1500s, when an unknown printer took a galley of type andscrambled it to make a type specimen book. It has survived not only fivecenturies, but also the leap into electronic typesetting, remainingessentially unchanged. It was popularised in the 1960s with the release ofLetraset sheets containing Lorem Ipsum passages, and more recently withdesktop publishing software like Aldus PageMaker including versions ofLorem Ipsum. -- Vladyslav Zacharko The Plug in People Ltd. --0000000000005d46f805c95ab59d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div> <h2>What is Lorem Ipsum?</h2> <p><strong>Lorem Ipsum</strong> is simply dummy text of the printing andtypesetting industry. Lorem Ipsum has been the industry's standard=20dummy text ever since the 1500s, when an unknown printer took a galley=20of type and scrambled it to make a type specimen book. It has survived=20not only five centuries, but also the leap into electronic typesetting,=20remaining essentially unchanged. It was popularised in the 1960s with=20the release of Letraset sheets containing Lorem Ipsum passages, and morerecently with desktop publishing software like Aldus PageMaker=20including versions of Lorem Ipsum.</p></div> <div><br></div>-- <br><div dir==3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div =dir=3D"ltr"><div><div dir=3D"ltr"><div> <div dir=3D"ltr"><div>Vladyslav Zach=arko<br></div><div>The Plug in People Ltd.</div> <div> <img src=3D"https://do=http://cs.google.com/uc?export=3Ddownload&id=3D1GyXobViPNfUTuymze-Z37cfBrjrbB0= Js&revid=3D0B7BvsKsyMMv0SzFacStKOFl3NXIvTnBaREU1RkRqR05oQ0tjPQ"><br> </d=iv></div></div></div></div></div></div></div> --0000000000005d46f805c95ab59d--
Script example
if (headerBeans.get('content-type')!=null) { print('originalTo:', headerBeans.get('content-type').getOriginalVal()); if (headerBeans.get('content-type').getOriginalVal().equals('multipart/; boundary="0000000000005d46f805c95ab59d"')) { headerBeans.get('content-type').setUpdatedVal('multipart/alternative; boundary="0000000000005d46f805c95ab59d"'); } print('updatedTo:', headerBeans.get('content-type').getUpdatedVal()); }
Replace specific from address to target Address
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
This example shows how to find specific from address/addresses and replace them with a specified target address (ignoring Matching Jira Users).
Test Case Example
MIME-Version: 1.0 Date: Thu, 12 Aug 2021 12:05:10 +0100 Message-ID: CACQqMReZmHMHG1XXWic6WthLBYHe223mth=ndmTNXnec_gt9XA@mail.gmail.com Subject: Testing Type-Content From: "Test User" <testuser@test.com> To: changeme@thiswontwork.com Content-Type: multipart/; boundary="0000000000005d46f805c95ab59d" --0000000000005d46f805c95ab59dContent-Type: text/plain; charset="UTF-8" What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesettingindustry. Lorem Ipsum has been the industry's standard dummy text eversince the 1500s, when an unknown printer took a galley of type andscrambled it to make a type specimen book. It has survived not only fivecenturies, but also the leap into electronic typesetting, remainingessentially unchanged. It was popularised in the 1960s with the release ofLetraset sheets containing Lorem Ipsum passages, and more recently withdesktop publishing software like Aldus PageMaker including versions ofLorem Ipsum. -- Test User --0000000000005d46f805c95ab59d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div> <h2>What is Lorem Ipsum?</h2> <p><strong>Lorem Ipsum</strong> is simply dummy text of the printing andtypesetting industry. Lorem Ipsum has been the industry's standard=20dummy text ever since the 1500s, when an unknown printer took a galley=20of type and scrambled it to make a type specimen book. It has survived=20not only five centuries, but also the leap into electronic typesetting,=20remaining essentially unchanged. It was popularised in the 1960s with=20the release of Letraset sheets containing Lorem Ipsum passages, and morerecently with desktop publishing software like Aldus PageMaker=20including versions of Lorem Ipsum.</p></div> <div><br></div>-- <br><div dir==3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div =dir=3D"ltr"><div><div dir=3D"ltr"><div> <div dir=3D"ltr"><div>Test User<br></div> <div> <img src=3D"https://do=http://cs.google.com/uc?export=3Ddownload&id=3D1GyXobViPNfUTuymze-Z37cfBrjrbB0= Js&revid=3D0B7BvsKsyMMv0SzFacStKOFl3NXIvTnBaREU1RkRqR05oQ0tjPQ"><br> </d=iv></div></div></div></div></div></div></div> --0000000000005d46f805c95ab59d--
Script Example
/*Step 1: Deffine Matching Address Regexp*/ var targetPattern = Java.type("java.util.regex.Pattern").compile("[a-z0-9]+@test\.com"); /*Step 2: Get the From Address Header and validate the address*/ var fromAddressess = jemhUtils.getOriginalAddressees(headerBeans.get('from')); if(fromAddressess != null){ print('Found from addressess'); var fromAddress = fromAddressess.get(0); var from = fromAddress.getAddress(); /*Step 3: Assert the From Address is not your final target Address*/ if(from != 'final.address@test.com'){ var matcher = targetPattern.matcher(from); /*Step 4: Validate the From Addesses is a targeted Address*/ if(matcher.find()) { /*Step 5: Validate the From Addesses is not already a user*/ if(userSearchService.findUsersByEmail(from).iterator().hasNext()){ print('From address is already a Jira User'); }else{ /*Step 6: Replace the From Addesses with final target address*/ var finalAddress = jemhUtils.createInternetAddress('Final Target', 'final.address@test.com'); var updatedHeader = jemhUtils.updatePreProcHeader(finalAddress, headerBeans.get('from')); print('Target sender replaced with Final Address ' + updatedHeader); } }else{ print(fromAddress + ' is not a target email address.'); } }else{ print('From address is already the Final Target User'); } }else{ print('No From address found'); }
Dynamically changing the from address based on email content
SINCE: 3.3.103
You may have a remote system generated email (from: system@x.com) but want the from address to be something that is within the body of the email. By changing the from address JEMH can then auto create users and communicate directly to that user.
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 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: This is a starting email template, update as required From: system@x.com To: mailbox@localhost Content-Type: text/plain; charset=UTF-8 some text USER EMAIL: fred@flintsones.com some text more
Example script
/* Enter custom Script here (example below) -- USE LOWER CASE HEADER NAMES */ /*Step 1: retrieve current from email address*/ var senderAddressVal = headerBeans.get('from').getOriginalVal(); print('from: '+senderAddressVal); print('message body', jemhUtils.getMessageBody(message)); /*Step 2: Find new value from within body of email*/ if (senderAddressVal !=null && senderAddressVal == "system@x.com") { var pattern = Java.type("java.util.regex.Pattern").compile("USER EMAIL: ([a-zA-Z]+@[a-zA-Z]+\.com)"); var matcher = pattern.matcher(jemhUtils.getMessageBody(message)); /*Step 3: Check if a value is next to pattern in body*/ if(matcher.find() && matcher.group(1) != null){ var newSender = matcher.group(1); var fromHeader = jemhUtils.addPreProcHeader('from', matcher.group(1)); /* Step 4: Replace Original from header value with new value gathered from body*/ if(fromHeader != null) { headerBeans.replace('from', fromHeader); print('new from value:' + headerBeans.get('from').getUpdatedVal() ); } } } else { print('no sender address match: '+senderAddressVal); }
Script preview
Dropping a email using Pre-Proc Script
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
You may have a email sender that you do not want to create any new issues or comments. With this solution it does not use jemhUtils.dropMessage as this can not be used with the Pre-Proc tasks. This solution will alter the subject to a value that matches the global blacklist.
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 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: this message should be dropped when it is processed From: system@x.com To: mailbox@localhost Content-Type: text/plain; charset=UTF-8 will the comment be rejected since the field processor has been changed testbody
Example Script
/* Enter custom Script here (example below) -- USE LOWER CASE HEADER NAMES */ /*Retrieves the sender of the email*/ var sender = headerBeans.get('from').getOriginalVal(); print('sender: '+ sender); /*Retrieves the subject from email*/ var subjectVal = headerBeans.get('subject').getOriginalVal(); print('subject: '+ subjectVal); /*checks if sender is system@x.com*/ if(sender == "system@x.com"){ /*Alters the subject to Drop Me*/ headerBeans.get('subject').setUpdatedVal("Drop Me"); print('New subject: ' + headerBeans.get('subject').getUpdatedVal() ); }
Script Preview
Removing agent from Cc header when using Service Management
SINCE: 3.3.105
Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!
When receiving an email it may contain an agent email address in the Cc header which may add the agent as request participants. This solution will filter the email addresses from the Cc header and will remove any email addresses that are associated to a agent and will add any non agent Jira users as the request participant and any non Jira users as email participants.
This solution uses custom fields to store the email addresses. The custom fields used are:
Email Participants - Stores participants that are not users.
Sender Name - Store senders name.
Sender Address - Stores senders email Address.
Request Participants - Stores participants that are users.
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 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: Filtering out agents from CC header From: reporter@localhost.com To: mailbox@localhost Cc: "noAccount" <noAccount@localhost>, "agent" <agent@localhost.com>, "noAccount2" <noAccount2@localhost>, "Customer" <customer@localhost.com> Content-Type: text/plain; charset=UTF-8 Filtering out agents from CC header.
Example Script
print('ccAddresses : '+ccAddresses.length); var csvVal=""; for (i =0; i<ccAddresses.length; i++) { /*Checks if the email is a user*/ var ccInetAddr = ccAddresses[i]; var theUser = jemhUtils.getUserByEmail(ccInetAddr); /*Checks if theUser is null*/ if (theUser!==null) { /*Checks if theUser email is a user in service desk group*/ var isAgent = groupManager.isUserInGroup(theUser, "jira-servicedesk-users"); if (!isAgent) { /*If theUser is not in group it will add the email to csvVal*/ if (csvVal=="") { csvVal=ccInetAddr.getAddress(); } else { csvVal=csvVal+", "+ccInetAddr.getAddress(); } } else { /*Prints out the agents name and email address*/ print('Agent is in email Cc:['+i+'] = [email='+ccInetAddr.getAddress()+', user='+theUser.getName()+', isAgent='+ isAgent + "]" ); } } else { /*Adds the non jira user to csvVal*/ if (csvVal=="") { csvVal=ccInetAddr.getAddress(); } else { csvVal=csvVal+", "+ccInetAddr.getAddress(); } } } /*Updates the Cc header to the new filtered value of csvVal*/ print('New Filtered Cc: ' + csvVal); headerBeans.get('cc').setUpdatedVal(csvVal);
Agent Group
The Agent that this example is trying to filter out is “Agent” and this user is placed in the “jira-servicedesk-users” and the script will check if the email is linked to a user in that script. Below is the Agent’s user profile and shows that they are in the group.
Pre-Proc Script Preview
Preview HeaderScripts Console Output
When creating a Pre-processing script there is a Preview HeaderScripts section and this shows the Output of the script by running the script against a test case. The output will show the Agents that were in the Cc header and shows the new Cc header output with the Agents removed.
Report Output
The Report will have a Pre-Processing section that will show the information that the Pre-Processing task modified and what it modified.
Issue Preview
Custom Field values:
This is the Email Participants Custom Field. This stores the email addresses that are not a Jira user and these addresses are saved in the Email Participant Custom Field.
This is the Request Participants Custom Field. These addresses are users that have an account on Jira but they are not agents but are participants to this issue.
Filter Cc addresses if they are not in relevant domain
When you receive an email it may contain participants that are not in the relevant domain. This solution will retrieve all of the address from within the Cc header and will check if they match a domain that is saved within the domainList and if not it will remove that address from the Cc header.
Example Script
var newCc = ""; var removedCc = ""; var domainList = "@domain1.com,@domain2.com"; var domainArray = domainList.split(','); var ccList = headerBeans.get('cc').getOriginalVal(); var ccArray = ccList.split(','); print('domainList length: ' + domainArray.length); print('ccList length: '+ccArray.length); for (i =0; i<ccArray.length; i++) { var ccInetAddr = ccArray[i].toString(); for (a =0; a<domainArray.length; a++) { if (ccInetAddr.contains(domainArray[a])) { print(ccInetAddr + " contains valid domain"); if(newCc.isEmpty()) { newCc = ccInetAddr; } else { newCc = newCc + ", " + ccInetAddr; } } } } headerBeans.get('cc').setUpdatedVal(newCc); print("valid cc addresses: " +newCc);
Example Test Case
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: Example email From: reporter@domain1.com To: catch@domain1.com Cc: valid@domain2.com, notvalid@random.com Content-Type: text/plain; charset=UTF-8 This is an example for removing non matching domains.
Report Output
Once you have ran the Test Case you will see within a Pre-processing section that will identify that the Cc Header has been modified.
Issue page
On the issue page you will see that there is only the valid users being placed within the Custom Field. In this example the valid address is valid@domain2.com.
Setting Comment visibility based on the email sender
Within Jira software projects you are able to set the visibility of each comment that is made. By default this is set to all users so that everyone is able to view the comments that have been made. This script will allow you to set the visibility of the comment based on certain conditions. The conditions are:
The Subject must contain a Issue key.
The sender must be a Jira User.
The email must not contain any additional recipients within the email.
If all of these conditions are met then the Script will add “#viewable=Administrators” to the subject so that it can be matched by the Subject Field Processor which will set the visibility to Administrators. If any of these conditions are not met then the Script will not alter the email and as a result will not alter the comment visibility.
Note:
The value for “#viewable=Administrators” can be set to any Project Role/Group that can be set interactively on the issue page.
This Script will require Subject Field Processor to be enabled so that the visibility can be changed.
Example Script
var from = headerBeans.get('from').getOriginalVal(); var origSubject = headerBeans.get('subject').getOriginalVal(); if(origSubject.contains("[TEST-")) /*Project key to apply permission to */ { if(from !== null) { if(jemhUtils.getUserByEmail(from)) /*Checks if the sender is a Jira User*/ { print(jemhUtils.getUserByEmail(from)); if(ccAddresses == null && toAddresses.length == "1") /*Checks if the reply contains any extra Recipients*/ { var newSubject = origSubject + " " + "#viewable=Administrators"; /*Adds a viewable condition to be captured by Subject Field processor*/ headerBeans.get('subject').setUpdatedVal(newSubject); print(newSubject); } } } }
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 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: [TEST-40] This is an example issue From: admin@localhost To: mailbox@localhost Content-Type: text/plain; charset=UTF-8 This is a comment
Report Output
Within the report it will show what the subject was changed to and that the Field Processor has matched on the added content.
Issue Page
How to remove unsupported characters from email addresses
Sometimes JEMH may receives email’s that contain unsupported characters within the email addresses. When this occurs it will cause an error which will stop the issue/comment from being created.
For example the below email contains a bullet point within some of the email addresses which is unsupported. The following script will find and remove this character from the email address so that the email can successfully be processed.
Note: To use this script, to,cc,from will need to be added to Matching Headers within the Script Task configuration.
Error message:
Below is the error message that is shown within the Report when an email address contains an unsupported character.
javax.mail.internet.AddressExceptionAddressException: Local address contains control or whitespace: javax.mail.internet.AddressException: Local address contains control or whitespace in string ``• recipient@example.com'' at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1343) at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1191) at javax.mail.internet.InternetAddress.parseHeader(InternetAddress.java:753) at javax.mail.internet.MimeMessage.getAddressHeader(MimeMessage.java:723) at javax.mail.internet.MimeMessage.getRecipients(MimeMessage.java:549) at javax.mail.Message.getAllRecipients(Message.java:296) at javax.mail.internet.MimeMessage.getAllRecipients(MimeMessage.java:565) at com.javahollic.jira.emh.service.MessageMetaDataImpl.initRecipients(MessageMetaDataImpl.java:290) at com.javahollic.jira.emh.service.MessageMetaDataImpl.init(MessageMetaDataImpl.java:112) at com.javahollic.jira.emh.service.EMHProfileBasedConfigImpl.initWith(EMHProfileBasedConfigImpl.java:163) at com.javahollic.jira.emh.service.DefaultJEMHConfigFactory.getConfiguration(DefaultJEMHConfigFactory.java:233) at com.javahollic.jira.emh.service.DefaultJEMHConfigFactory.getConfigurations(DefaultJEMHConfigFactory.java:86) at com.javahollic.jira.emh.service.ProfileGroupRunner.handleMessage(ProfileGroupRunner.java:120) at com.javahollic.jira.emh.service.EnterpriseMessageHandlerImpl.reallyHandleMessage(EnterpriseMessageHandlerImpl.java:337) at com.javahollic.jira.emh.service.EnterpriseMessageHandlerImpl.handleMessage(EnterpriseMessageHandlerImpl.java:190) at com.javahollic.jira.emh.service.DefaultTestCaseService.runTestCase(DefaultTestCaseService.java:487) at com.javahollic.jira.emh.service.DefaultTestCaseService.runTestCase(DefaultTestCaseService.java:455) at com.javahollic.jira.emh.rest.ui.testcase.TestCaseResource.runTestCase(TestCaseResource.java:745) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
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 Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com> Subject: This is a starting email template, update as required From: "Admin Test" <• admin@test.com> To: "JEMH" <mailbox@localhost.com>, <• email@example.com> Cc: =?Windows-1252?Q?=95=09leras=40example=2Eco=2Eza?= <• recipient@example.com>, <test@example.com> Content-Type: text/plain; charset=UTF-8 some text
Script example:
if( headerBeans.get('from') !== null) /*Checks for bullet point within From address*/ { headerBeans.get('from').setUpdatedVal(headerBeans.get('from').getOriginalVal().replaceAll('• ','')); } if (headerBeans.get('to') !== null) /*Checks for bullet point within To address*/ { headerBeans.get('to').setUpdatedVal(headerBeans.get('to').getOriginalVal().replaceAll('• ','')); } if (headerBeans.get('cc') !== null) /*Checks for bullet point within Cc address*/ { headerBeans.get('cc').setUpdatedVal(headerBeans.get('cc').getOriginalVal().replaceAll('• ','')); }
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.
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 | Array of all addresses in the email | |
baseUrl | Jira application URL. For example | |
bccAddresses | Array of all addresses in Bcc header in the email | |
body | Email content from the body of the email | |
ccAddresses | Array of addresses from the Cc header in the email | |
commentManager | Creates or removes Jira comments in the given Issue | |
context | Map of all context keys and all related context items | |
customFieldManager | Manages Custom fields and their values | |
fromAddress | Sender address of the email | |
groupManager | com.atlassian.jira.security.groups.RequestCachingGroupManager | Manages Atlassian’s groups and it’s members |
headerBeans | Header values from the email for example the Sender address and subject | |
issueLinkService | 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 | The installed version of JEMH | |
log | Allows output into the JEMH log | |
message | The Email being processed | |
projectRoleManager | Manages the project roles of the sender | |
relatedIssue | 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 | Provides functionality related to searching in Jira using JQL. For example query string generation, parsing and validation | |
senderUser | The Jira User associated to the From address | |
subject | The subject of the email | |
toAddresses | Array of all addresses in the To header of the email | |
userManager | Manages Jira Users on the instance | |
userPropertyManager | 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. |
watcherManager | Allows watches to be added/removed from the Jira Issue |
Body Script
We are currently gathering interest in this Feature. Please see JEMH-7508 for updates.