Velocity Pre-Proc Task: Conditionally remove References and In-Reply-To headers

Summary

If you would like to conditionally stop Thread Matching by removing the References and In-Reply-To headers, then this can be done by using a Velocity Pre-Proc Script that will run the relevant condition (e.g. if subject contains a forward Prefix “Fwd:”) and if that condition is true then it will need to remove the References and In-Reply-To headers (if they exist). Once these headers are removed it will stop Thread Matching from occurring and will result in a new ticket being created.

Note: If a Issue Key is associated through other methods, e.g. a valid Issue Key within the subject or through a Directive, then a comment will still be added.

Example Script:

#if($message.getSubject().contains("Fwd:")) #if($message.getHeader('References')) $message.removeHeader('References') #end #if($message.getHeader('In-Reply-To')) $message.removeHeader('In-Reply-To') #end #end

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 Subject: Fwd: This is the subject From: ryan@thepluginpeople.com To: test@test.com In-Reply-To: <JEMHCloud.prod.SER-27@script.atlassian.net> References: <JEMHCloud.prod.PROJ-27@script.atlassian.net> Content-Type: text/plain; charset=UTF-8 This is the email body

Example Test Script:

This script is used to evaluate if the Script above, is applied correctly by checking if $message.getHeader() returns null to indicate the that the headers were removed.

$assert.assertNull($message.getHeader('References')) $assert.assertNull($message.getHeader('In-Reply-To'))