#! /bin/csh -f # To fetch files saved in [IN] such as attachments and .html email bodies. # New attempt. Stay with old design. *.* is so fast that fancier # patterns aren't worthwhile except theoretically. # Can now take 2 params 'bbc' and 3 -- # -- which means get the 3rd last bbcnews email AND fetch it. ## These addresses are NOT urls BUT my unix file names. set pickup = ~/public_html/pickup # my name for my unix dir set pickup = ~/public_html/pickup # my name for my unix dir set IN = ~/mail/IN set ind = 1 if ("$1" == 'bbc' && "$2") set ind = "$2" ## Not sure if this is right or necessary bbcextract "$ind" # Extracts latest bbc daily .html file if ("$1" == 'bbc') exit set suffixes = (ics mp4 mp3 zip pdf doc{,x} ppt{,x} ps xls{,x} csv gif jp{,e}g png\ txt htm{,l} cw odp odt) ## Have done case-indiff matching differently below. ## But could do it like here. set tab = ' ' set unapproved = () set ignMax = 0; set msgignore = ({A,B,C,D,E,F,G,H,I,J}{A,B,C,D,E,F,G,H,I,J}); # Creates (only) 100 slots in array; with CAPS so if you see the # contents, you'll immed. know something is wrong with the script. cd $IN # Patterns with glob. Finds all files in current dir ## with extensions consisting of only 1 or 2 digits set toignore = (*.{[1234567890],[1234567890][1234567890]}) # MAC FILES e.g. .doc .ps etc. # webdir = pickup echo '' # Cannot handle a '[' in the file name. The glob fails and exits. foreach f (*.*) # excludes no-extension; starting with dot; being a dir if (! -e "$f") break # should abort silently if no matches at all #if ($f =~ .*) continue Excluded by *.* pattern above if (-x "$f") then echo "'$f' is executable '$f'." endif set ftail = "$f:e" # file extension if ("$ftail" == '') continue # This catches patterns above with no . if ("$ftail" == 'bak') continue # Expected, allowed; not to be moved if ("$ftail" == 'old') continue # allowed; not to be moved ## Main section: Only process files with extensions of 4 or less set l = (`echo -n $ftail | wc -m;`) # -n don't count LF as a char #if ("$ftail" =~ ??? || "$ftail" =~ ????) if ($l <= 4) then # Look at all extensions of 4 chars or less. set lcftail = (` echo $ftail | tr '[:upper:]' '[:lower:]' `) #edit ftail to lcftail set doit = 0 foreach s ($suffixes) # if approved suffix set bools to action it if ("$lcftail" == "$s") then set doit = 1 break endif end set ignore = 0 foreach fig ($toignore) if ("$fig" == "$f") then set ignore = 1 @ ignMax++; set msg = "${tab}Ignoring suffix '$f:e' (in '$f')"; set msgignore[$ignMax] = "$msg"; break endif end if (! $doit && ! $ignore) then set unapproved = ($unapproved .$ftail) continue endif if (! $doit) continue # On to next file, w/o action. # ACTION echo "Moving '$f' to [$pickup]" chmod 644 "$f" # so browser can see it mv "$f" $pickup else #echo " File '$f' remains." endif end echo ''; echo '===================='; echo "Tacitly allowed and not fetched suffixes: "; while ($ignMax) echo "$msgignore[1]"; shift msgignore; @ ignMax--; # echo appends LF to each slot, when it is printed out. end echo ''; # Separate the two list-prints echo "Unapproved and so not fetched suffixes:" echo -n ' '; echo "$unapproved" #unset nonomatch exit ls -ad .* rm .*.swp NEAT TECH FEATURES IN THIS SCRIPT 1) Auto expansion of suffix patterns e.g. htm{,l} --> htm html 2) Avoid such expansion to deal with upper/lower case variants of suffixes, by only testing lcase versions of what filenames turn up. 3) Collecting msgs of a given type into an array; and printing out together later on. Used indexed arrays for this. 4) Define var $tab with a tab in; to help formatting msgs; So each msg can be formattted with sps and tabs; and preserved as such. 5) Only need LF at end of each msg, so done on printout.