Source for comment notification emails

There keep being weird things that happen with comment notification emails. Some of them really do look like bugs. Can anyone tell me where the source code for generating comment notifications lives? I've tried a few places, but I don't understand how to track the perl being executed from a bml module back to where it came from. So, how do you do the more general thing as well?