I placed the following script in /etc/crontab.daily/tagspam (every script in this directory is run automatically every night by cron).
# Tag spam in the spam maildir, and notspam in the notspam maildir
# Delete the tagged mail
#
# The virtual domain where the spam and notspam mailboxes live
MAILHOME=/home/vpopmail/domains/moorsbroadband.net
# The spam and notspam mailboxes
SPAMDIR=spam
HAMDIR=notspam
# Run sa-learn on all the mail, whether it has been seen by a mail reader or not
sa-learn --spam $MAILHOME/$SPAMDIR/Maildir/new
sa-learn --spam $MAILHOME/$SPAMDIR/Maildir/cur
sa-learn --ham $MAILHOME/$HAMDIR/Maildir/new
sa-learn --ham $MAILHOME/$HAMDIR/Maildir/cur
# Delete the tagged mail, so it isn't used again
rm $MAILHOME/$SPAMDIR/Maildir/new/*
rm $MAILHOME/$SPAMDIR/Maildir/cur/*
rm $MAILHOME/$HAMDIR/Maildir/new/*
rm $MAILHOME/$HAMDIR/Maildir/cur/*