Skip to content

Instantly share code, notes, and snippets.

@zmousm
Last active December 29, 2015 10:39
Show Gist options
  • Save zmousm/7658486 to your computer and use it in GitHub Desktop.
Save zmousm/7658486 to your computer and use it in GitHub Desktop.
jira mail address header sanitization
require [ "regex", "editheader", "relational", "variables" ];
if header :regex "X-JIRA-FingerPrint" "^(jira-server1-fingerprint|server2-fingerprint)$" {
# assumption: common mail domain
set "msfx" "@example.com";
# match up to 3 g.assignees
if header :regex "X-JIRA-GroupAssignee" "^(([^ ]+) ?)(([^ ]+) ?)?(([^ ]+) ?)?$" {
set "gass" "${2}${msfx}";
if string :count "ne" "${4}" ["0"] {
set "gass" "${gass}, ${4}${msfx}";
if string :count "ne" "${6}" ["0"] {
set "gass" "${gass}, ${6}${msfx}";
}
}
}
# match up to 3 assignees
if header :regex "X-JIRA-Assignee" "^(([^ ]+):[0-9]+ ?)(([^ ]+):[0-9]+ ?)?(([0-9]+):[^ ]+ ?)?$" {
set "ass" "${2}${msfx}";
if string :count "ne" "${4}" ["0"] {
set "ass" "${ass}, ${4}${msfx}";
if string :count "ne" "${6}" ["0"] {
set "ass" "${ass}, ${6}${msfx}";
}
}
}
if string :count "ne" "${ass}" ["0"] {
deleteheader "To";
addheader :last "To" "${ass}";
if string :count "ne" "${gass}" ["0"] {
deleteheader "Cc";
addheader :last "Cc" "${gass}";
}
} elsif string :count "ne" "${gass}" ["0"] {
deleteheader "To";
addheader :last "To" "${gass}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment