/
Useful scripts

Useful scripts

Javascript vs Groovy

Scripts provided here are typically Javascript so will likely not work if directly pasted into a Groovy script editor, some tweaking may be required.

Groovy: getting a Regexp Pattern Class:

import java.util.regex.Pattern; def pattern = Pattern.compile("([Gg])roovy") assert pattern.class == Pattern; print('pattern class: '+pattern.class);

Nashorn

Creating a pattern

var p = java.util.regex.Pattern.compile("test");

Creating Lists

var x = java.util.List.of("this","that"); print(x.getClass() + " has "+x.size() +" elements"); print("0 = "+x.get(0)); print("1 = "+x.get(1));

Working with recipient lists

Reuse of common loop variables in ‘for’ seems to break, use unique name for different loops.

Some javascript functions are not available in the Java ScriptEngine implementation, eg ‘in' and ‘list.includes’ are not supported, in such cases, you should implement a script to do the work, eg, here we work on to: and cc: to test if they are mailbox addresses referred in the common list:

Example Scripts

The following are scripts to solve some cases, may help you toward a solution, feel free to submit yours through support or comments!



 

Related content