procmail
[Top] [All Lists]

Re: Procmail from the aliases file?

1997-01-07 14:41:18
Chuq Von Rospach desires ...

| ... to be able to set up some filters called from the aliases file, as in:
| 
| fred: "|/ /usr/local/bin/procmail /users/mailbot/procmail.fred"

I hope that that's a typo for
  fred: "|/usr/local/bin/procmail /users/mailbot/procmail.fred"

and if nothing else I'd stick a -m in there before the rcfile name so as not
to rely on any assumptions for the initial value of $MAILDIR, but let's get
back to Chuq's question:

| primarily to save me the hassle of setting up a "user" for every style
| of procmail filter I want to create. Unfortunately, this doens't seem
| to work cleanly when it comes to things like logging because sendmail
| is being paranoid (correctly) about ownership and permissions.
| 
| Is there a way to convince procmail to execute out of aliases as a user
| (in this case, user mailbot?) cleanly? Is there something I missed?

Philip Guenther and Alan Stebbens have posted solutions using the
/etc/procmailrcs directory.  With no experience of my own with procmail
as the MDA, I'll trust their answers implicitly.

There is, as well, another solution that has worked very well for me on
systems where procmail is not the MDA and /etc/procmailrcs would be ignored. 
If procmail is setuid root (or in one other case, which I won't get into),
you can get an alias to run procmail as a particular user with the -d switch:

  fred: "|/usr/local/bin/procmail -d mailbot" # don't use this; read on.

In conjunction with the -d option certain things CANNOT be done: you cannot
set variables on the command line, nor specify an rcfile there (even with -m),
nor use the -p option.  This becomes mailbot's mail now, and procmail insists
on the environment that mailbot wants (by forbidding command line variable
assignments and -p) and on the recipes that mailbot wants (by insisting on
~mailbot/.procmailrc as the rcfile).

The way to tell mailbot's .procmailrc that this is mail for fred, not regular
mail for mailbot, is with the -a option to define .procmailrc's $1:

  fred: "|/usr/local/bin/procmail -a fred -d mailbot"

If user mailbot has to handle other aliases, it can work the same way:

  ginger: "|/usr/local/bin/procmail -a ginger -d mailbot"

Note that everything after "-d" is treated as the logname of a user, so
the -d option must be last.  Also, it makes "# your_username" unnecessary
because the username is the argument to -d.

Now, in ~mailbot/.procmailrc, do this near the beginning:

   ALIAS # make sure it's unset to start
   :0 # If $1 is defined, this came through an alias.
   * ! ${1+!}
   { ALIAS=$1 }

And there you have the information saved.  You can use conditions like

 * ALIAS ?? regexp

later on in .procmailrc, or assign

 INCLUDERC=${ALIAS:+$HOME/procmail.$ALIAS}

[to use the naming style Chuq proposed] to get procmail out of there into
another rcfile altogther.  (Just make sure that the other rcfile completes
delivery even in cases of errors unless you WANT procmail to return to
~mailbot/.procmailrc afterward.)

<Prev in Thread] Current Thread [Next in Thread>