Next: , Previous: How to support alternative command names, Up: Overview of ezmlm function


4.30 How to add your own commands

The qmail/ezmlm mechanism makes it very easy to add your own commands. You can add them to DIR/manager, but this requires great care in terms of ordering and exit codes. Easier is to set them up separately with a .qmail-list-command file.

Let's assume you want to allow anyone to determine how many subscribers are subscribed to your list with the command ‘list-count@host’. Just create a program to do the work:

     #!/bin/sh
     DTLINE='Delivered-To: list-count@host processor'
     grep "$DTLINE" > /dev/null &&
     { echo "This message is looping"; exit 100; }
     {
       echo "$DTLINE"
       cat <<EOF
       From: list-help@host
       To: $SENDER
       Subject: list@host subscriber count
     
       Current number of subscribers:
       EOF
       ezmlm-list ~/DIR | wc -l
     } | /var/qmail/qmail-inject -f list-return- "$SENDER"
     exit 0

Then, create DIR/count containing ‘|/path/program’ and then do ‘ln -sf DIR/count ~/.qmail-list-count’. Now, the command will pass the message to ‘program’. The first thing ‘program’ looks for is its delivered-to line to detect looping. If not found, it goes on to print this header, followed by some minimal text and the subscriber number. This can of course be made prettier with ezmlm-list error checking, and maybe in perl, but shows how easy it is to extend ezmlm. All thanks to the DJB/qmail delivery mechanism.