#! /bin/sh # Depends: chiark-utils-bin set -e DIR="$HOME/tmp/sa-learn-cache" LOCKED=false if [ "$1" = --locked ]; then LOCKED=: shift fi if [ "$1" = --spam ]; then CACHE="$DIR/spam" elif [ "$1" = --ham ]; then CACHE="$DIR/ham" else echo "don't know how to handle anything other than --spam or --ham" >&2 exit 1 fi LOCK="$CACHE.lock" mkdir -p "$DIR" if ! $LOCKED; then exec with-lock-ex -w "$LOCK" "$0" --locked "$@" else if [ -e "$CACHE" ]; then SIZE="$(stat -c %s "$CACHE")" else SIZE=0 fi cat >> "$CACHE" if [ "$SIZE" -gt 4194304 ]; then sa-learn --mbox --no-sync "$@" < "$CACHE" rm -f "$CACHE" fi fi exit 0