procmail
[Top] [All Lists]

Re: fileserver works, ls command does not :(

1996-04-01 13:40:40
"D. Emilio Grimaldo T." <grimaldo(_at_)sce(_dot_)philips(_dot_)nl> writes:
...
 Now, I wanted to do one more thing: to have a `send list' or 
 `send list *' or `send list *txt' command on the subject line
 that would use the provided pattern (if given, if not assume *)
 to do an `ls' command on the  fileserver directory and return that
 listing of available files to the requester. I have tried everything
 in my mind as well as variations of the procmailex examples and
 none of them works, at best the request message is kept in the
 incoming mailbox. Does anybody has a working solution? Here is
 my last trial :~(

:0
* ^Subject: send list [*0-9a-zA-Z]*
* !^X-Loop: account(_at_)the(_dot_)address
* !^From +account(_at_)the(_dot_)address
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^Subject: send list .*[/.]\.
{
 MAILDIR=$HOME/systems/fileserver # chdir to the fileserver directory

 :0 fhw                   # reverse mailheader and extract name
 * ^Subject: send list
 | formail -rA "X-Loop: account(_at_)the(_dot_)address"

 FILE="$MATCH"         # the requested filename

 LS=`ls ./$FILE`

 :0 ah
 | echo $LS  | $SENDMAIL -oi -t
}


You forgot the \/ part of the regexp, and you need to get the
header data past the echo.  I've gussied it up below, to show
how you can group it all into one recipe.  I've also changed
a few other things: regexps are already case insensitive, match
"From: " as well as "From ", avoid temporary variables, and
remove redundant conditions.



# Be careful with the "Subject:" conditions.  Requests for files or
# listings outside of the fileserver directory should not be allowed.
# The negated condition below is actually unnecessary here, given that
# the nested recipes extract only [0-9a-z] (plus '*' for listings) when
# deciding what to send.  They should not allow whitespace in the names,
# and if they allow '/', then make sure you have the "! ^Subject:.*[/.]\."
# condition in place, or else *all* your files will be accessible.
# The "From:?" condition is probably unnecessary for preventing looping,
# and may hinder testing, so I would toast it.
:0
*   ^Subject: send (list|file) [*0-9a-z]+
* ! ^X-Loop: account(_at_)the(_dot_)address
* ! ^From:? +account(_at_)the(_dot_)address
* ! ^FROM_DAEMON
* ! ^Subject: send list .*[/.]\.
{
    MAILDIR=$HOME/systems/fileserver # chdir to the fileserver directory

    :0 fhw                      # reverse mailheader
    | formail -rA "X-Loop: account(_at_)the(_dot_)address

    :0 h                        # is this a send file command?  Extract name
    * ^Subject: send file \/[0-9a-z]+
    | cat - ./$MATCH 2>&1 | $SENDMAIL -oi -t

    :0 h                        # is this a send list command?  Extract name
    * ^Subject: send list \/[*0-9a-z]+
    | (cat -; ls ./$MATCH) | $SENDMAIL -oi -t

    # If we got here, than something bogus happened, like a request to
    # "send file *"  (If wildcards are okay on the send file side, then
    # add them to the set in the proper line.)  Otherwise, this is a
    # "cannot happen" situation.
    :0 fb
    | (echo "MAIL FILESERVER FATAL ERROR!"; echo ""; cat -)

    :0:
    $DEFAULT
}


I'm not familiar with the "getnames" command, but you could probably
add it in here by changing the first condition to:

*   ^Subject: (getnames|send (list|file) [*0-9a-z]+)

(or whatever the subject of the "getnames" command is supposed to look
like.)  Then add another recipe inside the block that matches on the
getnames subject, and off you go.  Remember that the formail has
already been done for you at that point.  By grouping the all you cut
down on the number of times procmail has to try matching on "X-Loop:"
and "^FROM_DAEMON", etc.



Philip Guenther

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