procmail
[Top] [All Lists]

Re: intelligent autoresponder

1997-01-13 08:01:47
On Monday 13 January 97, at 6 h 59, the keyboard of Costa 
<100270(_dot_)3700(_at_)CompuServe(_dot_)COM> wrote:

Does anybody have a good idea - or even already programmed - an
"intelligent" autoresponder?

I use a real fileserver, see it hereunder.
 
Than procmail does a look in the filedir, and if it finds a
$FILENAME.txt matching with exactly with $FILENAME(_at_)domain(_dot_)com
it sends the corresponding file.

So, if I want to add a new autoresponder, I simply have to
copy a new file in $FILEDIR ;-)

No, you would have to add an entry in the aliases database as well (if 
you use sendmail, if you prefer qmail, things are different).

Otherwise, in procmail (warning, not tested):

:0
* ^TO_autoresponder\/[0-9]+
*!^FROM_DAEMON
*!^X-Loop: autoresponder(_at_)domain(_dot_)com
|(formail -rt -A "Precedence: junk"\
-I"From: Auto Reply from domain.com <autoresponder(_at_)domain(_dot_)com>" \
-I"Subject: Information Request" \
-A "X-Loop: autoresponder(_at_)domain(_dot_)com";\
cat $FILEDIR/$MATCH.txt )|$SENDMAIL -t


------- fileserver -----------------

(Sorry for the bad wrapping.)


ME="fileserver(_at_)globenet(_dot_)org"
URL="http://www.globenet.org/";
MAINTAINER="postmaster"
MAKE_REPLY="formail -rt -A'From: $ME' -A'X-URL: $URL' -iOld-Subject 
-A'MIME-Version: 1.0' -A'Content-type: text/plain; charset=iso-8859-1' 
-A'Content-Transfer-Encoding: 8bit' "
#MAKE_REPLY="formail -rt -A'From: $ME' -A'X-URL: $URL' -iOld-Subject "
SEND_HELP="cat messages/help"

# The file server. First, is it a request to it?
:0
* $ ^TO$ME
{

        MAILDIR=/public # chdir to the fileserver directory

        :0f
        | formail -I'From '

        # If request looks OK, do nothing
        # Check it doesn't come form a daemon, it is not a loop, etc.
        # We do not reply to these (may be we should reply to unknown
        # commands?)
        :0f
        * !^FROM_DAEMON
        * $ !^X-Loop: $ME               
        | formail -A"X-loop: $ME"

        # Former conditions are false (i.e., something is wrong in the
        # request.
        :0E
        {
                :0f
                | formail -i"X-Diagnostic: ERROR: Not safe to reply (No reply 
sent)" 

                :0
                ! $MAINTAINER

        }

        # Check it is a request we understand,
        # File name is mandatory for get requests, directory name is not
        # for ls requests.
        :0
        * !^Subject: *(send( *file|)|get|retrieve) *[-A-Za-z0-9_\./]+ *$
        * !^Subject: *(ls|index|dir(ectory|)) *[-A-Za-z0-9_\./]* *$
        * !^Subject: *help
        {
                :0c
                | ( sh -c "$MAKE_REPLY" ; \
                        echo "Unknown request: see the documentation:" ; \
                        echo -e "\n\n----\n\n" ; \
                        sh -c "$SEND_HELP" ) | $SENDMAIL -t
        
                :0
                {

                        :0
                        | formail -i"X-Diagnostic: ERROR: Unknown request 
(reply sent)"  | 
$SENDMAIL -oi $MAINTAINER


                }
        
        }
        
        # Canonicalize GET requests
        :0f
        * ^Subject: *(send( *file|)|get|retrieve) *\/[-A-Za-z0-9_\./]+ *$
        | formail -i"Subject: GET $MATCH"
        
        :0
        * ^Subject: GET
        {
                
                # Check it doesn't include .. (cheating attempt), etc.
                :0
                * ^Subject: GET .*\.\.
                {
                        :0f
                        | formail -i"X-Diagnostic: ERROR: SECURITY PROBLEM (no 
reply sent)" 
                        :0
                        ! $MAINTAINER
                }

                :0c
                * ? test -r $MATCH
                | ( sh -c "$MAKE_REPLY" ; \
                        echo "Your request of ${MATCH}: " ; \
                        echo -e "\n\n------------\n\n" ; \
                        cat ./$MATCH )  | $SENDMAIL -t

                :0E
                {

                        :0f
                        | formail -i"X-Diagnostic: ERROR: File does not exist 
(reply sent)"

                        :0c
                        | (sh -c "$MAKE_REPLY" ; \
                                echo "Sorry, file $MATCH does not exist." ; \
                                echo "May be you should check the spelling." ) \
                                        | $SENDMAIL -t
                }
        
                :0f
                * !^X-Diagnostic: ERROR
                | formail -i"X-Diagnostic: OK (File $MAILDIR/$MATCH sent)"

        }

        # No directory name indicated
        :0
        * ^Subject: *(index|ls|dir(ectory|)) *$
        {

                SUBJECT=`formail -xSubject:`

                :0f
                | formail -i"Subject: $SUBJECT /"

        }

        # Canonicalize INDEX requests
        :0f
        * ^Subject: *(index|ls|dir(ectory|)) *\/[-A-Za-z0-9_\./]+ *$
        | formail -i"Subject: INDEX $MATCH"

        :0
        * ^Subject: INDEX \/[-A-Za-z0-9_\./]+ *$
        {
                
                DIR=$MATCH
                                
                # Check it doesn't include .. (cheating attempt), etc.
                :0
                * ^Subject: INDEX .*\.\.
                {
                        :0f
                        | formail -i"X-Diagnostic: ERROR: SECURITY PROBLEM (no 
reply sent)" 
                        :0
                        ! $MAINTAINER
                }

                :0c
                * ? test -d ./$DIR
                | ( sh -c "$MAKE_REPLY" ; \
                        echo "Your request of the list of files in ${DIR}: " ; \
                        echo -e "\n\n------------\n\n" ; \
                        ls -ld ./$DIR ; echo "" ; ls -l ./$DIR )  \
                                | $SENDMAIL -t

                :0E
                {
                
                        :0f
                        | formail -i"X-Diagnostic: ERROR: Directory does not 
exist (reply 
sent)"

                        :0c
                        | (sh -c "$MAKE_REPLY" ; \
                                echo "Sorry, directory $DIR does not exist." ; \
                                echo "May be you should check the spelling." ) \
                                        | $SENDMAIL -t
                }

                :0f
                * !^X-Diagnostic: ERROR
                | formail -i"X-Diagnostic: OK (Index $MAILDIR/$DIR sent)"

        }

        :0
        * ^Subject: *help
        {
                :0c
                | (sh -c "$MAKE_REPLY" ; \
                        sh -c "$SEND_HELP" ) \
                                        | $SENDMAIL -t
                :0f
                * !^X-Diagnostic: ERROR
                | formail -i"X-Diagnostic: OK (Help sent)"

        }

}

:0
! $MAINTAINER


















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