Getting Message Numbers

[previous] [next] [table of contents] [index]

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.

The mhpath command will give you full pathnames. That's usually okay for short lists of messages. But pathnames aren't always what you want:

Two MH commands, pick and scan, can convert a message range like 25-cur into a list of messages. For example, if the current message is 34, the next command might store the list 6 25 26 29 31 33 34 in the variable msgs:
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 1
If 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.

[Table of Contents] [Index] [Previous: The mhpath Command] [Next: Settings from the MH Profile]


Last change $Date: 1996/06/06 15:10:33 $

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 <jpeek@jpeek.com>