procmail
[Top] [All Lists]

Re: Getting files

1998-01-12 01:20:58
On Sun, 11 Jan 1998 04:41:51 -0800 (PST), John Gianni
<jjg(_at_)Cadence(_dot_)COM> wrote:
  QUESTION 1: How to make the request a variable yet preserving case 
           insensitivity (and adding space insensitivity)?

Jari's pm-tips contains a trick for canonicalizing case in variable
matches, originally due to David Tamkin. It's a nice trick, but it
requires you to have a list of all requestable files in the recipe. 
I think it's neater to just accept whatever they request and if a file
with that name isn't in my ftp directory, they get a "file not found".
IMHO, anybody who can't be bothered to preserve case for file names
deserve whatever they get ...

  QUESTION 2: How to add second request without duplicating the whole recipe?
           (currently I repeat the whole recipe for file "bar" if asked
           "send file bar")

There are canned library routines for this, but in general, you'd just
grab the file name into a variable. 

    :0
    * Subject:\<*send\<*file\<*\/[a-z][^/]+
    * ... other conditions more or less like in procmailex example ...
    {
        # Simplistic canonicalization: Convert everything to l/c
        FILE=`echo "$MATCH" | tr A-Z a-z`
        SUBJ="$FILE (automatic file request)"

        # If file doesn't exist, replace it with a "sorry, no can do"
        :0
        * ! ? test -r $HOME/ftp/$FILE
        { SUBJ="File not found ($FILE)" FILE="Sorry.txt" }

        # Send $HOME/ftp/$FILE with a subject of $SUBJ
        ...
    }

An added benefit of making all requestable files have lowercase file
names is that you can then have "hidden" files such as Sorry.txt above
which are in the same directory as the other files, but "invisible" to
requesters.

Hope this helps,

/* era */

-- 
 Paparazzi of the Net: No matter what you do to protect your privacy,
  they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>

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