The Section Batch-process New Mail: autoinc introduces autoinc, a script for running inc and processing each new message. It's designed to be run automatically from a cron or at job but you can also type its name at a shell prompt. Here is the autoinc script (you might want to open it in a separate browser window). To install it, see the Section Programs in This Book's Archive.
Before incorporating mail, it tries to be sure that there's enough disk space by checking your disk quota. If your system doesn't have disk quotas -- or even if it does -- you might also want to have autoinc run df to see if there's enough disk space left on your filesystem before it incorporates all your mail. (This test isn't completely accurate. Once the mail has been incorporated, each message will take at least one disk block -- but the test doesn't account for that extra disk usage. The margin shell variable can work around that problem.) If the user doesn't have enough room, autoinc sends mail to some address (probably not yours!) to complain. You can hack autoinc to notify the user in some other way.
Two places in the script use sed "tagged fields" to grab certain fields from the output of df and quota -v. Some people use awk to do this, but sed usually runs faster. For example, the second sed filter outputs a line like the following for the shell's eval command to read:
used=1345 total=2048That sets two variables, $used and $total, from the output of quota -v.
An ls -s command stores the mailbox size in $2. (Read about the set x trick in the Section Explanation of showpr.) If you're using inc with POP, that won't work, of course. But you can parse the output of msgchk -- use another sed expression to find the number nnn in the string (nnn bytes).
When autoinc incorporates new mail, it starts a loop to scan the messages one by one. The script uses the techniques in the Section Get Information with scan Format Strings to get information from the header of each message. To make autoinc do whatever it is you want it to do, you'll need to customize the body of the loop that scan drives. Right now, it's full of dummy case statements like this:
case "$from" in aaaa|bbbbb|ccccc|ddddd|eeeeeeee|fffffff|ggggggg|hhhhhh) $mh/refile $msg +$from continue ...Of course, your loop can use any tests it needs to. Or, you might not want to use a loop at all. Depending on what you need, a few commands like the one below could be more efficient:
pick --sender a -or --sender b ... -seq temp && refile temp +xWhile you're debugging autoinc, remember the inc -notruncate switch. It incorporates your new mail but doesn't remove the messages from your system mailbox. That way, you can incorporate and test the same messages over and over.
A set -e command makes the shell quit if any command returns a nonzero status. If there's a problem, just fix it and rerun autoinc by hand. When you rerun autoinc, it will look through all the leftover mail in inbox as well as any new mail it incorporates.
[Table of Contents] [Index] [Previous: Explanation of append] [Next: Explanation of automhn]
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 <email@example.com>