#!/bin/bash # # $Id: trimmbox,v 1.1 2002/12/21 17:06:56 adicvs Exp $ # # This script will trim mbox files to the number of messages specified. # It assumes that messages are deliverd into the mbox via procmail. # Lock files are maintained appropriately, # maxmsg="100" mboxmatch="$HOME/mail/Junkmail" lockext=".lock" tempext=".temp" date=`date` if [ "$1" = "-v" ]; then verbose="1" fi # Test mbox properties test_mbox () { # Omit anything but files if [ ! -f "$mbox" ]; then [ "$verbose" ] && echo "$mbox is directory, skipping" return 1 fi # Omit lock files and temp files case "$mbox" in *$lockext) [ "$verbose" ] && echo "$mbox is lockfile, skipping" return 1 ;; *$tempext) [ "$verbose" ] && echo "$mbox is temporary file, skipping" return 1 ;; esac return 0 } # Append trim message to mbox msg_mbox () { cat< "$temp" formail +"$skip" -s < "$mbox" >> "$temp" cat "$temp" > "$mbox" rm -f "$temp" fi # Remove lockfile rm -f "$lock" done