Created
April 25, 2019 07:44
-
-
Save zmousm/e1bb2c8cbbdf061531c845c9bc40c873 to your computer and use it in GitHub Desktop.
phabricator mail address header normalization: To: -> differential reviewers or maniphest task owner, Cc: subscribers (up to 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require [ "regex", "editheader", "relational", "variables" ]; | |
if header :is "X-Phabricator-Sent-This-Message" "Yes" { | |
# assumption: common mail domain | |
set "msfx" "@example.com"; | |
# match up to 3 subscribers | |
if header :regex "X-Phabricator-Stamps" "subscriber\\([@#]([^\\)]+)\\)(.+subscriber\\([@#]([^\\)]+)\\))?(.+subscriber\\([@#]([^\\)]+)\\))?" { | |
set "psub" "${1}${msfx}"; | |
if string :count "ne" "${3}" ["0"] { | |
set "psub" "${psub}, ${3}${msfx}"; | |
if string :count "ne" "${5}" ["0"] { | |
set "psub" "${psub}, ${5}${msfx}"; | |
} | |
} | |
} | |
# match up to 3 reviewers | |
if header :regex "X-Phabricator-Stamps" "application\\(Differential\\).+reviewer\\([@#]([^)]+)\\)(.+reviewer\\([@#]([^)]+)\\))?(.+reviewer\\([@#]([^)]+)\\).+)?" { | |
set "prev" "${1}${msfx}"; | |
if string :count "ne" "${3}" ["0"] { | |
set "prev" "${prev}, ${3}${msfx}"; | |
if string :count "ne" "${5}" ["0"] { | |
set "prev" "${prev}, ${5}${msfx}"; | |
} | |
} | |
} | |
# match task assignee | |
if header :regex "X-Phabricator-Stamps" "application\\(Maniphest\\).+task-owner\\(@([^)]+)\\)" { | |
set "pass" "${1}${msfx}"; | |
} | |
if string :count "ne" "${pass}" ["0"] { | |
deleteheader "To"; | |
addheader :last "To" "${pass}"; | |
} elsif string :count "ne" "${prev}" ["0"] { | |
deleteheader "To"; | |
addheader :last "To" "${prev}"; | |
} | |
if string :count "ne" "${psub}" ["0"] { | |
deleteheader "Cc"; | |
addheader :last "Cc" "${psub}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment