Procmail is a powerful Mail Delivery Agent (MDA) capable of sorting and filtering mail based on rulesets called recipes. It's rather *nix-centric, terse, mature, and proven.
Procmail was Mail Delivery Agent that invoked when delivering message to do sorting and filtering. It can be used to put email into different folders based on keywords in from, to, subject, text of the mail.
Procmail use rulesets called recipes to control how an email should be processed. All procmail recipes have three components: flags, conditions, and an action. For complete documentation about the recipies, consults man 5 procmailrc.