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:
-
Pathnames aren't efficient for handling lots of messages.
UNIX has to traverse the same list of directories in the path to
get each message.
That can slow down your program and waste disk access time.
-
Some programs don't need the message pathnames; they just need the
individual message numbers.
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.
|