JS PreProc Task: Dynamically add subject directives to assign a project

Summary

Here, we show how to test against to/cc addressees for given sets of addresses, where matches are found we set a projectKey that is then used in a Directive of a format to drive JEMHC Subject based field processor.

You can add more new ‘blocks’ (like 18-26) for new projects with their own CSV addressee list.

This solution requires the Profile to only have Subject Based Field Processor enabled, Field Processors go through an Election they are not all applied.

PreProc Script

let projectKey; const headers = ['to', 'cc']; for (let id in headers) { print('testing header: '+headers[id]); const header = headers[id]; if (message.getHeader(header)!=null) { const headerVal = message.getHeader(header).toLowerCase(); let addresses = ['support@thepluginpeople.com']; //csv add more for (let id in addresses) { if (headerVal.indexOf(addresses[id])!=-1) { projectKey='ABC'; break; } } if (projectKey!='') { addresses = ['other@thepluginpeople.com']; //csv add more for (let id in addresses) { if (headerVal.indexOf(addresses[id])!=-1) { projectKey='DEF'; break; } } } } } if (projectKey!=null) { let oldSubject=message.getHeader('subject'); let newSubject; if (oldSubject!==null) { newSubject=oldSubject+' #project='+projectKey; message.setHeader('subject', newSubject); } }

Scenario 1: support@

Output : support@thepluginpeople.com

image-20241115-123713.png

Example Mail : support@thepluginpeople.com

See line 6, to: usedassert(message.getHeader('subject').indexOf("#project=DEF") != -1, "expected issue key to be found: "+message.getHeader('subject'));

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: noreply@other.com To: support@thepluginpeople.com Content-Type: text/plain; charset=UTF-8 Hello world

 

Testing Script

assert(message.getHeader('subject').indexOf("#project=ABC") != -1, "expected issue key to be found: "+message.getHeader('subject'));

Scenario 2: other@

Output: other@thepluginpeople.com

 

image-20241115-125042.png

Example mail : other@thepluginpeople.com

See line 6, cc: used

Testing Script