procmail
[Top] [All Lists]

Re: Round Robin for email using Procmail

2000-06-26 21:52:32
Mark Thiessen asked,

| Has anyone ever heard of a round-robin for email.  I have been told that
| this should be possible to do with Procmail, but no one that I have talked
| to has known how.  In case you are not sure what I mean, I would like to
| set up a list of 10 names, every email coming in, gets forwarded to one of
| these names.

A round robin would be a setup where person #1 writes to person #2, person #2
sends it on to person #3, person #3 to person #4, until person N lets person
#1 know that it's made the whole trip; if person #5 has something to say to
everyone, then (s)he sends it to person #6, who sends it to person #7, and so
forth, until it comes back around to person #4, who then lets person #5 know
that it made the whole circuit.

| It would choose the first name for the first email, second
| for second, etc.  When it got to the end of the list, it would go to the
| first name on the list, and continue on.

You're asking for a rotating alias, which has been discussed on this list
several times, most recently about three days ago (but that was the special
case of alternating between two people).  Typically it's a way to distribute
mail for a department among the people who handle it.

In the past I've suggested keeping a pointer file (as well as a file of the
addresses to receive the messages) and using the built-in arithmetic of
procmail's scoring feature to select the line number from the address file,
but since I'm punchy from a long, trying day and trying to unwind to get some
sleep before another long, trying day tomorrow, I'm in the mood for something
nastier.  /path/to/victimfile is the list of addresses among whom these
messages are to be distributed:

  # `c' in case you want to save a copy with the userid running procmail
  :0c:/path/to/victimfile$LOCKEXT
  * conditions, if any
  ! `(echo 1p ; echo 1m$ ; echo w ; echo q) | ed -s /path/to/victimfile`
 
Dirty, yes, but it has only two forks (a shell and ex) and doesn't require a
separate pointer file.  If you need to preserve postmark information, then

  :0c:/path/to/victimfile$LOCKEXT
  * conditions, if any
  | formail -R 'From ' Old-Postmark: | "$SENDMAIL" $SENDMAILFLAGS \
    `(echo 1p ; echo 1m$ ; echo w ; echo q) | ed -s /path/to/victimfile`

in which case you'd be running the shell and formail anyway, so ed would be
the only additional fork (not that the subshell is free).  Be sure to use
led (part of the SmartList suite included with procmail) whenever you make
changes to the file containing the addresses.  led will use a compatible
lockfile while you're editing so that no incoming message will try to change
the file at the same time (nor read from it while you have it incompletely
edited).  Anyhow, the echoes and the pipe to ed will print the current top
line of the file where the backquotes will grab it and put it onto the com-
mand line and then move that address to the end and save the file.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail