Using procmail With PMDF

procmail can be used to filter or sort incoming mail messages. The processing of the incoming mail can be invoked via a user's .forward file, through the PMDF pipe channel, or via the PMDF profile database.

Using a .forward file

The user's $HOME/.forward file will need to look like:

"|IFS=' '&&exec /usr/local/bin/procmail -f-||exit 75 #USER"

noting that the #USER construct is typically changed to reflect the username used. This is done to prevent optimization of mail delivery (typically perpetrated by sendmail) dropping what would otherwise appear to be duplicate .forward which may be interpreted as multiple deliveries to one user. This is not required under PMDF.

The the user will need to setup a $HOME/.procmailrc file. An example of such is shown below:

# Please check if all the paths in PATH are reachable, remove the  
# ones thatare not.
PATH=$HOME/bin:/usr/bin:/usr/ucb:/bin:/usr/local/bin:. MAILDIR=$HOME/mail 
# You'd better make sure it exists DEFAULT=$MAILDIR/Inbox 
# We don't use a global lockfile here now. 
# Instead we use local lockfiles everywhere. 
# This allows mail to arrive in all mailboxes 
# concurrently, or allows you to read one mailbox 
# while mail arrives in another.
# The next recipe will split up Digests into their individual messages. 
# Don't do this if you use a global lockfile before this recipe 
#(deadlock)
:0 
* ^Subject:.*Trash 
|formail +1 -d -s procmail

LOGFILE=$MAILDIR/Trash 


:0: # Anything addressed to mike+test
* ^TOmike\+test@* 
test # will go to $MAILDIR/test
:0:
myfile # All 'questions' will go to 
* ^Subject:.*questions 
toread # $MAILDIR/toread

For further information on .procmailrc files, please refer to the procmail documentation.

Using the Pipe Channel

The pipe channel option file, /pmdf/table/pipe_option, will need an appropriate entry to invoke the processing of the message by procmail, shown here for user mike.

mike@pipe.maxerva.process.com=/usr/local/bin/procmail -d mike < %s

Then mail delivered to mike@pipe.maxerva.process.com will be delivered via procmail according to the .procmailrc file in the user's home directory.

Please refer to the PMDF System Manager's Guide, for details on establishing a pipe channel.

Large Numbers of Users

Both of the above methods can become cumbersome as the number of users increases. The PMDF user profile database can simplify the administrative effort required.

# pmdf profile
profile> set method PROCMAIL "|/usr/local/bin/procmail -d %s" 
profile> set delivery PROCMAIL -user=mike 
profile> exit 

Then, delivery to user mike, will be via procmail without need for a .forward file or the administrator having to setup a number of entries in the pipe channel's option file.

Subaddresses

Using a PMDF user profile database has an important additional benefit over using a .forward file. By using a supplemental form of the profile entry, procmail can process the messages according to the delivery address or subaddress.

For example, setting the profile as:

# pmdf profile
profile> set method PROCMAIL "|/usr/local/bin/procmail -a %+ -d %s"
profile> set delivery PROCMAIL -user=mike
profile> exit 

and delivering mail to mike+sun@xyz.com would see the procmail call expanded to:

/usr/local/bin/procmail -a mike+sun -d mike

directing delivery to the intended recipient, but passing the subaddressing onto procmail for processing via the following .procmailrc script excerpt

SUBADDR = $1

:0:
* SUBADDR ?? sun
sun
    

thereby placing the mail into the sun mail folder.

Note that unsafe characters after a + are not allowed and are stripped by PMDF.

File Locking

It is advisable to utilise the file locking capabilities of procmail when delivering mail, although it should be noted that some mail agents (e.g., Netscape Communicator's mail agent, Mozilla) do not lock the files or folders when reading them from a local file system. Therefore, there can be issues when procmail has locked a folder and delivered a message, but Mozilla has proceeded to simultaneously modify the folder, sans locking.

This can be avoided by using a mail server as an intermediary between the offending agent and the file system. For example, configure the client to use an IMAP server rather than have direct access to the filesystem without locking.

Obtaining Procmail

procmail is maintend by Stephen R. van den Berg (berg@pool.informatik.rwth-aachen.de) and may be obtained via anonymous ftp from ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/. The procmail examples shown in this document were tested using procmail v3.10 (1994/10/31).


Search: