The basic qmail architecture, trimmed down to just the parts relevant to delivery (and thus filtering) of email, is shown in the following figure:
Almost any of qmail's components can be wrapped and used for filtering purposes. Which components to wrap depends on the specific behavior desired. In many cases there are multiple ways of achieving the same thing and choosing which method to use requires planning. For example, if some email needs to be blocked or rejected, it is better to catch that email earlier in its path through the system rather than later. This reduces the amount of time and resources spent on email that is not delivered. Thus, the most common place to block mail is before it is queued for delivery. Filtering mail (i.e. modifying it) is often done in multiple places, depending on what kind of filtering is desired. For example, filtering for spam is sometimes done before mail is queued, though this makes it harder to implement user-specific...