procmail
[Top] [All Lists]

Re: Extracting username from return address?

1997-12-16 10:06:38
D R Hilton <drh-0(_at_)pineknot(_dot_)com> writes:
I'd like to set up a dummy address to which our users can send an e-mail
and receive a statement of their current month's usage in return.  I need
to trap the messages, extract the return address and execute:

ac -p Pusername | Mail username

The P in front of the username is necessary, since these are PPP users and
running ac with their mail username would return zero usage (BSD/OS).

I've got procmail installed.

Assuming that usernames are alphanumeric only, the following should work and
be secure:

        :0
        *   ^Subject: *get usage
        * ! ^X-Loop: getusage(_at_)pineknot\(_dot_)com
        * ! ^FROM_DAEMON
        {
            # Build the return header
            :0 fh
            | formail -rt -A"X-Loop: getusage(_at_)pineknot(_dot_)com" \
                -I"Subject: usage stats from $HOST"
            
            # Extract the username from the return header, and then
            # call ac with that, feeding the return header and the output
            # of ac into sendmail.  The second condition is there to remove
            # the trailing '@' from the value in the MATCH variable.
            :0 h
            * ^To:.*[^a-z0-9]\/[a-z0-9]+@
            * MATCH ?? ^\/[a-z0-9]+
            | { cat - ; ac -p P$MATCH ; } | $SENDMAIL $SENDMAILFLAGS -t
        }

Do you see how that works?


Philip Guenther

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