Using Procmail   «Prev  Next»

Lesson 6Recipe conditions
ObjectiveIdentify recipe conditions.

Recipe Conditions for Linux Email maildrop

Question: What are the recipe conditions for the Linux email service known as maildrop?
Maildrop is a powerful and flexible email delivery agent that allows for advanced filtering and processing of incoming emails on Linux systems. In order to filter and sort emails according to specific conditions, maildrop uses a set of rules known as "recipes." Recipes in maildrop consist of conditions and actions that are applied to incoming emails. The conditions specify the criteria that an email must meet in order for the recipe to be applied, while the actions define what should be done with the email once the condition is met.
Some common recipe conditions used in maildrop include:
  1. Sender: The sender condition filters emails based on the address of the sender. For example, you could use this condition to route all emails from a particular sender to a specific folder.
  2. Recipient: The recipient condition filters emails based on the address of the recipient. This condition is useful for sorting emails that are addressed to a particular user or group of users.
  3. Subject: The subject condition filters emails based on the subject line of the email. This can be useful for identifying and sorting emails related to a specific topic.
  4. Size: The size condition filters emails based on their size in bytes. This can be useful for sorting large or small emails into separate folders.
  5. Content: The content condition filters emails based on the text content of the message. This can be useful for identifying and sorting emails that contain specific keywords or phrases.

These are just a few examples of the many conditions that can be used in maildrop recipes. By combining conditions and actions, you can create complex and powerful filtering rules that help you manage your email more effectively.
Conditions are the crucial components to a recipe. A recipe's conditions describe what kind of email will match the recipe, so you have to be careful that your conditions exactly identify only mail you're interested in and no other.
Every recipe can have zero or more conditions. If you specify no conditions, the recipe matches vacuously[1]. If you specify multiple conditions, they all must match for the recipe to match.

Regular expressions

Regular expressions describe conditions. A regular expression is a pattern against which text in the email is compared. If the regular expression matches part of the email, the condition is satisfied. If the regular expression doesn't match, the condition is not satisfied.
Regular expressions use metacharacters to describe desired patterns. Metacharacters are characters you can type on your keyboard, but they have special meaning to the regular expression.
The following table shows the allowed metacharacters, their meanings, and an example.
Metacharacter Description Example
. A period matches any single character. A.C matches ABC, AbC, AxC, and A%C
? A question mark matches either zero or one occurrences of the previous regular expression. A?C matches AAC (one occurrence) and AC (zero occurrences), but not AAAC (two occurrences)
* An asterisk matches zero or more occurrences of the previous regular expression. A* matches A (one occurrence), AA (two occurrences), AAAAAA (six occurrences) and "" (zero occurrences)
+ A plus sign matches one or more occurrences of the previous regular expression. A+ matches A (one occurrence), AA (two occurrences), AAAAAA (six occurrences) but not "" (zero occurrences)
[ An open square bracket introduces a character range, which is shorthand for any of a certain set of characters. Close the range with a closed square bracket. Any metacharacter that appears inside a range loses its special meaning. To include a closed square bracket (]) in the range, place it at the beginning of the range. A[xyz]C matches AxC, AyC, and AzC A[.]C matches only A.C A[[]C matches only A[C
( An open parenthesis introduces an option group. Separate each option with a vertical bar (|) and end the option group with a closed parenthesis. Any metacharacter that appears inside a range loses its special meaning. A(foo|b)C matches AfooC or AbC
^ A caret means the regular expression must match at the beginning of a line. ^ABC will match ABC only if the "A" is the first character on the line
$ A dollar sign means the regular expression must match at the end of a line. ABC$ will match ABC only if the "C" is the last character on the line
\ A slash in front of any metacharacter removes that metacharacter's special meaning. A\.C will match only A.C
! An exclamation point at the start of a condition negates the condition's meaning. !A\.C will match everything but A.C

Note: There are various other options described in the procmailrc man page. Additionally, the egrep man page is a good source for information about regular expressions.
The next lesson describes recipe actions.
[1]Vacuously: A statement applies vacuously when it is obviously true in all contexts.