Filter emails by subject on a per-project basis
Scenario
You may want to drop mail with specific subjects on a per project basis, the global approach won’t work.
Approach
A single script that tests for an ‘issue’ in scope (i.e. its a reply) and that the key of the related project is the one wanted, then check a sub-string of the supplied project.
Example Mail
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 DCSP-2 drop me
From: admin@localhost
To: helpdesk@nn.net
Content-Type: text/plain; charset=UTF-8
some text
Example Script
if ( relatedIssue!=null && subject!=null) {
var projectKey = relatedIssue.getProjectObject().getKey();
print('project is: '+projectKey);
switch (projectKey) {
case 'DCSP':
if (subject.indexOf('drop me') != -1) {
jemhUtils.dropMessage('dropped because of DCSP:[drop me]...');
print('mail was dropped by subject script '+projectKey);
} else {
print('add more tests');
}
break;
case 'SW':
print('add SW tests');
break;
default:
print('unfiltered project: '+projectKey);
}
}
Validate the script
Using the Test Case associated with the Profile, we can evaluate the script at edit time:
Outcome
Executing the script should result in a clear outcome: