############################## -*- Mode: sh -*- #############################
## wwwoffle-outgoing-regexp-rm -- remove WWWOFFLE outgoing requests via regular expression
## Copyright       : http://www.fsf.org/copyleft/gpl.html
## Author          : Dan Jacobson -- http://jidanni.org/
## Created On      : Sat Oct 13 04:16:34 2001
## Last Modified By: root
## Last Modified On: Thu Jun 13 09:26:52 2002
## Update Count    : 35
## Status          : Use with caution!
###############################################################################
# The newest copy of this program is on my website
# must be root to use
: ${wwwoffle_cache=/var/spool/wwwoffle} #if not otherwise set by the user
test -d $wwwoffle_cache||{
    echo $0: $wwwoffle_cache: invalid wwwoffle_cache directory 1>&2
    exit 24;}
negate=
case $1 in
    -v) negate=!; shift;; #so we can also act like grep -v
#now eliminate all those crap requests that seem to accrue before your next connection:
    -i) shift;set ${WWWorm_junkstufs-'\\.(css|js|ico|jpg|gif|png|swf)$'};; #images etc.
esac
test $# -gt 1 && { echo $0: args too many 1>&2; exit 33;}
set -e
wwwoffle-ls outgoing|
   gawk -v IGNORECASE=1 '$6 '$negate'~ "'$1'" {print $6|"more";flag=1}
       END{if (!flag){print "no matches";exit 1}}' &&
#should add a -l to just list and not proceed further
{
    #sure hope no one else is causing the list to change before we got here.
    #should really not call this twice...
    echo -n 'Delete these from outgoing request list? [n]|y  '
    read answer
    test x$answer == xy &&
    cd $wwwoffle_cache/outgoing &&
    wwwoffle-ls outgoing|gawk -v IGNORECASE=1 '$6 ~ "'$1'" {print $1}'|xargs rm
}
#should get the list only once, in case of other users adding requests concurrently
