Difference between revisions of "Procmail"

From ArchWiki
Jump to: navigation, search
(Change waring to stub.)
Line 14: Line 14:
 
===Assignments===
 
===Assignments===
 
The assignments section provides variables for procmail
 
The assignments section provides variables for procmail
<pre>
+
{{bc|
PATH=/bin:/usr/bin
+
<nowiki>PATH=/bin:/usr/bin
 
MAILDIR=$HOME/Mail
 
MAILDIR=$HOME/Mail
 
DEFAULT=$HOME/Mail/inbox
 
DEFAULT=$HOME/Mail/inbox
 
LOGFILE=/dev/null
 
LOGFILE=/dev/null
SHELL=/bin/sh
+
SHELL=/bin/sh</nowiki>
</pre>
+
}}
 
===Recipes===
 
===Recipes===
 
Recipes have the following format:
 
Recipes have the following format:
<pre>
+
{{bc|
 
:0 [flags] [ : [locallockfile] ]
 
:0 [flags] [ : [locallockfile] ]
 
<zero or more conditions (one per line)>
 
<zero or more conditions (one per line)>
 
<exactly one action line>
 
<exactly one action line>
</pre>
+
}}
 
The conditions are extended regular expressions, with some few extra options. Conditions always start with an asterisk.
 
The conditions are extended regular expressions, with some few extra options. Conditions always start with an asterisk.
  
Line 38: Line 38:
 
====Conditions====
 
====Conditions====
 
A condition is an extended regexp, starting with an asterisk, like this one:
 
A condition is an extended regexp, starting with an asterisk, like this one:
* ^From.* someperson@\w+.com
+
{{bc|* ^From.* someperson@\w+.com}}
 
====Action====
 
====Action====
 
An action can be something as simple as  
 
An action can be something as simple as  
work
+
{{bc|work}}
 
in that case, the mail that complies with the condition will be saved on the {{ic|work}} inbox.
 
in that case, the mail that complies with the condition will be saved on the {{ic|work}} inbox.
  
 
It could also start with a pipe, which means the message is going to be passed to the standard input of the command following the pipe. A line like that could be something like this:
 
It could also start with a pipe, which means the message is going to be passed to the standard input of the command following the pipe. A line like that could be something like this:
| /usr/bin/vendor_perl/spamc
+
{{bc|<nowiki>| /usr/bin/vendor_perl/spamc</nowiki>}}
 
The command can alter the message. In this example, the spamassassin command will add headers to the mail, with its spam status level, which later can be used by '''another recipe''' to block it, or store it on a different mailbox.
 
The command can alter the message. In this example, the spamassassin command will add headers to the mail, with its spam status level, which later can be used by '''another recipe''' to block it, or store it on a different mailbox.

Revision as of 05:39, 29 August 2012

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: Still unfinished. Need to fix style according to Help:Style. (Discuss in Talk:Procmail#)

Procmail is a program for filtering, sorting and storing email. It can be used both on mail clients and mail servers. It can be used to filter out spam, checking for viruses, to send automatic replies, etc.

The goal of this article is to teach the configuration of procmail. This article asumes you already have either a email client (mutt, nmh, etc) or a mail server (sendmail, postfix, etc) working, that can use (or requires) procmail. It also assumes you have at least basic knowleadge on regular expressions. This article will give only a minimal explanation, for a complete manual, check the man procmailrc

Installation

Install the package procmail from the official repositories.

Configuration format

The configuration is going to be saved on ~/.procmailrc if this is the configuration for an email client, or on /etc/procmailrc if is going to be used by an email server.

The configuration is composed of two sections; assignments and recipes.

Assignments

The assignments section provides variables for procmail

PATH=/bin:/usr/bin
MAILDIR=$HOME/Mail
DEFAULT=$HOME/Mail/inbox
LOGFILE=/dev/null
SHELL=/bin/sh

Recipes

Recipes have the following format:

:0 [flags] [ : [locallockfile] ]
<zero or more conditions (one per line)>
<exactly one action line>

The conditions are extended regular expressions, with some few extra options. Conditions always start with an asterisk.

The action can be only a mailbox name, or an external program.

Flags and lockfile

For basic recipes, you don't need any flags. But they can be necessary if your script calls an external command. Here is a list of some of the most used flags:

  • f Consider the pipe as a filter.
  • w Wait for the filter or program to finish and check its exitcode (normally ignored); if the filter is unsuccessful, then the text will not have been filtered.

Conditions

A condition is an extended regexp, starting with an asterisk, like this one:

* ^From.* someperson@\w+.com

Action

An action can be something as simple as

work

in that case, the mail that complies with the condition will be saved on the work inbox.

It could also start with a pipe, which means the message is going to be passed to the standard input of the command following the pipe. A line like that could be something like this:

| /usr/bin/vendor_perl/spamc

The command can alter the message. In this example, the spamassassin command will add headers to the mail, with its spam status level, which later can be used by another recipe to block it, or store it on a different mailbox.