Sendmail includes a facility for plugging in custom mail filters, called milters. It's documented here. This milter is intended as an example, to show how they work, and as a base for building your own milters.
The basic idea of a milter is, you initialize and specify a set of callback routines. Then as each message is received, sendmail will pass pieces of it to the appropriate callbacks. The callbacks can decide whether to accept or reject the message, and can also modify it in various ways.
In sample_milter, all the callbacks do is syslog that they were called and what their arguments were. This lets you see in realtime how the milter is working.
This is very abbreviated, intended mainly as a reminder for those who have worked with milters before. If it's your first milter, you should look on the web for more thorough documentation.
If you don't see MILTER in the compilation options, you will have to re-build sendmail.
sendmail -d0.1 -bt < /dev/null | grep MILTER
Rebuild and install sendmail.cf.
# sample_milter unix:/var/run/sample.sock
ACME Labs / Software / sample_milter