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.