procmail
[Top] [All Lists]

Re: Is it possible to do something like this in Procmail

1999-12-09 03:42:04
"John Antypas" <jantypas(_at_)prosofteng(_dot_)com> writes:
I'd like to find a way to solve a little admin problem I have.  We're moving
away from NT (!!!) and NT's mail server options to something more reliable.
However, users all complain that NT allows them, through a web page, to:

- Change mail forwarding
- Change the autoresponder message

All of these users have never touched a shell account in their lives, so I
can create a general .procmailrc file for these users and they'll never
touch it.

Using postgres, I'd like to create a simple table:

create table usermailprefs (
     username char(32),
     autoresponder_on int,
     autoresponder_message varchar,
     forward_on int,
     forward_to_list varchar
);

Assuming I write a couple of programs below:

getautoresponder - Given a user name, return the autoresponder text
or --NONE--
getforwardlist -- Given a user name, return the address list or --NONE--

I'd like to tell procmail

For every message received, using getautoresponder, if you don't
get --NONE-- returned, send the text back to the sender.
Next, using getforwardlist, send the message to the list of addresses, or
if --NONE-- is returned, simply drop the message in the local mailbox.

These seem possible.  How sane am I (at least in this instance)?

Seems like a sane idea.  I would be tempted to use the return code of
the programs instead of a magic value like "--NONE--", but that's fine.
Here's one possible solution:

        # First, prevent loops
        :0
        * ! ^X-Loop: $LOGNAME(_at_)$HOST
        {
            GAR = `getautoresponder $LOGNAME`

            :0 hc
            * ! GAR ?? ^^--NONE--^^
            |(formail -r -A"X-Loop: $LOGNAME(_at_)$HOST"; \
              echo "$GAR")| $SENDMAIL $SENDMAILFLAGS -t

            GFL = `getforwardlist $LOGNAME`

            :0 w
            * ! GFL ?? ^^--NONE--^^
            |formail -b -A"X-Loop: $LOGNAME(_at_)$HOST" | \
             $SENDMAIL $SENDMAILFLAGS -- $GFL
        }
        # Delivery to the local mailbox will take place implicitly if the
        # message isn't delivered by the time procmail hits the end of the
        # .procmailrc file.


Note the use of the "variable ??" syntax to tell procmail to match the
regexp in the condition against the value of the variable instead of
against the header of the message.

Also, and this is important, note the "--" argument to the forwarding
sendmail.  If you're passing addresses from a possibly untrusted or
uncontrolled source to sendmail on its command line, you should preceed
them with a "--" argument to tell sendmail that there are no flags
after that.  This avoids problems with addresses that start with '-'.


Philip Guenther

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