Does your program handle command-line arguments like last:10 or 6 25-cur? If your script is running only MH commands, that's no problem because MH commands can understand those message lists. If you're using a standard UNIX command like grep or awk, you'll need the message filenames. Also, if your program uses sequences, it may need to know whether a particular sequence is defined or empty. Here are ways to handle those problems.
The mhpath command will give you full pathnames of individual messages or the messages named in a sequence. That's usually okay for short lists of messages. But pathnames aren't always what you want:
args="6 25-cur" msgs="`pick -list $args`"Using pick that way can cause trouble if you have certain pick switches in your MH profile. For example, using -sequence picked in the MH profile means that your script will overwrite a folder's picked sequence every time you run pick to get a message number list. (There's no pick -nosequence switch to solve this problem.) A better (but slightly ugly) answer is to use scan. Give scan the MH format string %(msg) that prints just the message numbers. Here's the previous example with scan instead of pick:
args="6 25-cur" msgs="`scan -format '%(msg)' $args`"Whether you get the list from pick or scan, though, here's how to access the individual messages in a folder. Grab any folder name from the command line (as shown in the Example for loop parsing a command line) and cd to the folder like this:
cd `mhpath $folder` || exit 1If mhpath fails or the folder name isn't valid, the || exit 1 will abort the script. Otherwise, you can use the message numbers from pick or scan as filenames because the messages will be files in the current directory.
Finding an empty or missing sequence isn't quite as clean a process. The best way I know is to run mark -list -seq sequence-name, where sequence-name is the sequence you want to test. The output for an empty or missing sequence looks like this:
sequence-name: (null)In a Bourne shell script, for example, where the sequence name is stored in the seqname variable, you could test for an empty sequence with:
seq_out=`mark -list -seq $seqname` case "$seq_out" in ""|"$seqname: (null)") # "mark" made no output and/or $seqname is empty ...
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. It 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 COPYING.
Copyright © 1991, 1992, 1995 O'Reilly Media, Inc.
Copyright © 1996, 1997, 1999, 2000, 2002, 2004 Jerry Peek
Last modified: 2006-05-31 15:13:43 -0700