#! /bin/sh # $Id: autoinc,v 1.4 1992/10/19 21:00:48 jerry book3 $ ### autoinc - Incorporate new mail; refile from inbox automatically ### Usage: autoinc ## TABSTOPS ARE SET AT 4 IN THIS SCRIPT df=/bin/df expr=/bin/expr grep=/bin/grep mailer=/usr/ucb/mail quota=/usr/ucb/quota sed=/bin/sed tr=/bin/tr error=xxx@yyy,aaa@bbb # WHERE TO MAIL ERRORS margin=300 # HOW MANY EXTRA KBYTES WE NEED mh=/usr/local/mh # WHERE MH PROGRAMS LIVE # GET NAME OF FILESYSTEM WITH HOME DIRECTORY FROM LINES LIKE # THIS. TAKE LAST WORD STARTING WITH A SLASH ON SECOND LINE: # Filesystem kbytes used avail capacity Mounted on # hostname:/u1 842171 442588 315365 58% /u1 homedir="`$df ${HOME?} | $sed -n '2s@.*\(/[^/]*\)$@\1@p'`" # GET QUOTA VALUES. USE sed TO GRAB LINE THAT STARTS WITH ${homedir}: # Disk quotas for yourname (uid 1234): # Filesystem usage quota limit timeleft files quota limit # /u1 18451 20000 20000 1474 0 0 # AND PUT THE FIRST TWO NUMBERS ON THE LINE INTO SHELL VARIABLES: eval `$quota -v | $sed -n "s@^${homedir} *\([0-9][0-9]*\) *\([0-9][0-9]*\).*@used=\1 total=\2@p"` # PUT x IN $1, NUMBER OF KBYTES IN $2, MAILBOX FILENAME IN $3. # (NOTE: SOME ls -s OUTPUT IS IN 512-BYTE BLOCKS; NEED TO DOUBLE THOSE.) set x `/bin/ls -s /usr/spool/mail/$USER` wouldbe="`$expr $used + $2 + $margin`" if [ $wouldbe -ge $total ] then echo "used $used kytes, incoming mail $2 kbytes, quota is $total." | $mailer -s "ERROR -- no room to 'inc' mail! Clean up now!" $error exit fi # FILTER inc OUTPUT THROUGH grep, PUT LEFTOVERS BACK ONTO STDERR. # IF inc RETURNS NON-ZERO, EXIT. $mh/inc 2>&1 | $grep -v '^inc: no mail to incorporate' 1>&2 || exit set -e # IF ANY ERRORS FROM NOW ON, EXIT # SCAN inbox MESSAGES. GET MSG. NUMBER, From: AND Sender: ADDRESS. # TURN UPPER TO LOWER CASE. THEN FEED TO STANDARD INPUT OF LOOP. # INSIDE LOOP, refile MESSAGES WE KNOW HOW TO HANDLE; LEAVE OTHERS: $mh/scan +inbox -format '%(msg) %(mbox{from}) %(mbox{sender})' | $tr '[A-Z]' '[a-z]' | while read msg from sender do # FOR MOST, MATCH From: COMPONENT AND PUT INTO THAT FOLDER: case "$from" in aaaa|bbbbb|ccccc|ddddd|eeeeeeee|fffffff|ggggggg|hhhhhh) $mh/refile $msg +$from continue ;; iiiiii|jjjjj|kkkkkkkk|llllllll|mmmmmmm|nnnnnn|ooooooo) $mh/refile $msg +$from continue ;; # ... AND SO ON ... esac # THIS ONE IS BETTER TO MATCH ON Sender: COMPONENT: case "$sender" in ppppppp) $mh/refile $msg +ppppppp continue ;; esac done
[Table of Contents] [Index] [Return to Explanation of autoinc]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <jerry@ora.com>
HIVE: All information for read only. Please respect copyright! |