How to write a custom rule.
As far as I've investigated, the basic steps are:
see this article
I've not dive into it so far now