#! /bin/sh -e

# Abstract: Bourne shell-script wrapper for running vsnag diags with procmail


Usage()
{
  thisfile=`basename $0`
  id=`sed 'N; $ !D; s/^[^"]*"//; s/".*//' < $0`
  ver=`sed "N; $ !D; s/^#//; s/\n#/;/; s/$id/$thisfile/g" < $0`


  ${PAGER:-more} 1>&2 << ENDHERE

     SYNOPSIS
        Usage: $thisfile [ OPTIONS [...] ] [ MESSAGE ]
               $thisfile [ -h|--help ]

        Where OPTIONS are:          And where the default is:
          --vsnag        rc-file      "vsnag.rc" in the CURRENT directory
          --myvars       rc-file      "vsnag.myvars.rc" in the VSNAG directory
          --diags        rc-file      "vsnag.self-test.rc" in the VSNAG directory
          --rcfile       rc-file      [none]

          -p|--procmail  path/binary   the first procmail binary in your path
          -v|--verbose   on|off        on

        And where (an optional) MESSAGE is any single email message you
        wish to test against a Virus Snaggers(tm) setup using the self-test
        diagnostics rc-file;

        Or where:
          -h|--help                    gives this help screen.


     DESCRIPTION
        $thisfile is a Bourne-shell script that pipes MESSAGE
        (or, if no MESSAGE argument was given, /dev/null) through the
        default procmail binary in a protected environment with various
        options preset, for the purpose of testing functionality, settings,
        and output of Virus Snaggers(tm) and procmail.  The output is a
        procmail log (sent to /dev/stdout, usually your terminal screen)
        that includes results from the vsnag.self-test.rc file.

        To run as a vsnag diagnostic tool, $thisfile
        needs to be able to find, at a minimum, (a) a procmail binary
        (in the user's path, unless the "--procmail" option is used);
        (b) a vsnag.self-test.rc file of at least version 1.25 (or,
        if none, the self-test output will be skipped with a warning
        message); and (c) Virus Snaggers files comprising at least
        version 2.10 of that program.  Command-line OPTIONS, described
        above, allow the user to specify paths and names of relevant
        files that $thisfile would not find on its
        own (e.g., in the current directory).

        As an alternative to running Virus Snaggers files, the script
        can run any rc-file you specify with the --rcfile option.  That
        is, $thisfile can become your instant test
        harness or sandbox for any procmail rc-file!  (In that case
        the self-test.rc won't be run automatically.)

        It is possible to pipe $thisfile's output to other
        programs or redirect it to a file.

     EXAMPLES
        The following works if typed from a directory one level beneath
        that in which all the vsnag files have been placed:

          $thisfile --vsnag ../vsnag.rc  a.message


        The following would work if typed at a shell prompt from the
        directory where the Virus Snaggers files are located, assuming
        the vsnag.self-test.rc is, however, in the directory "../testing/"
        and a.message is a mail message sitting in the user's \$HOME:
        
          $thisfile --diags ../testing/vsnag.self-test.rcfile \$HOME/a.message


        To view $thisfile output and concurrently save it to
        a file (e.g., for later review or emailing):

          $thisfile a.message | tee vsdiags.out


        To grep the output for the string "DOMAIN":

          $thisfile a.message | grep DOMAIN

     BUGS/NOTES
        The "genvars" file's path and name is taken from the "myvars" file
        directly and cannot be preset from this script.  Change the value
        from within myvars if you want to alter the filepath or name for
        genvars.

        Use the "--procmail" option to invoke a procmail binary that is not
        the default procmail binary in your path.

     FILES
        The Virus Snaggers(tm) files for procmail, as well as the optional
        vsnag.self-test.rc module, can be found at http://vsnag.spamless.us.
        Full documentation for Virus Snaggers(tm) is available at the site.

     COPYRIGHT
        $thisfile is protected under copyright by its author,
        who reserves all rights.  It incorporates by reference the
        copyright notice printed in the Virus Snaggers(tm) program
        files and documentation.

     $ver

ENDHERE

  # printf " <\"Dammit, Jim, I'm a lawyer, not a programmer!\">\n"
  exit $1
}


  MESSAGE=/dev/null
  RCFILE="${VSNAG:-vsnag.rc}"

  while [ $# -ne 0 ]
  do  case "$1" in
   --vsnag|--rcfile|--rc)     RCFILE="$2"; shift ;;
                --myvars)  VS_MYVARS="$2"; shift ;;
                 --diags)   VS_DIAGS="$2"; shift ;;
           --procmail|-p)   PROCMAIL="$2"; shift ;;
            --verbose|-v)    VERBOSE="$2"; shift ;;
               --help|-h)                Usage 1 ;;
                      -*)                Usage 2 ;;
                       *)           MESSAGE="$1" ;;
      esac
  shift
  done

  PROCMAIL="${PROCMAIL:-procmail}"
  VS_DIAGS="${VS_DIAGS:-`dirname $RCFILE`/vsnag.self-test.rc}"

  $PROCMAIL -m      DEFAULT=/dev/null          \
                    LOGFILE=/dev/stderr        \
                    MAILDIR=.                  \
                    VERBOSE="${VERBOSE:-yes}"  \
                    VS_DIAGS="$VS_DIAGS"       \
                    VS_MYVARS="$VS_MYVARS"     \
                    PROCMAIL="$PROCMAIL"       \
             "$RCFILE"  <  "$MESSAGE"  2>&1



# "vsnag.point-n-shoot.sh" (c) by Dallman Ross <dman@spamless.us>
# ver. 1.21a; 29-Nov-04

