Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!bbn!bbn.com!mesard
From: mesard@bbn.com (Wayne Mesard)
Newsgroups: comp.mail.mh
Subject: MHALL - do something to a lot of folders
Message-ID: <33245@bbn.COM>
Date: 8 Dec 88 17:27:14 GMT
Sender: news@bbn.COM
Reply-To: mesard@BBN.COM (Wayne Mesard)
Organization: Bolt Beranek and Newman Inc., Cambridge MA
Lines: 104

Here's a little script I whipped up this morning.  It repeatedly applies
a command (with optional arguments) to a bunch of folders.  I wrote it
because I'm forever forgetting where I refile'd a message to the night
before, and wanted a quick n dirty way to look for it.

The default command and argument are "scan" and "last".  The default
folders are all your top-level folders.

When folders are explicitly named subfolders will also be processed.
The -n switch prevents this recursion.  Conversly, when no folders are
given, the top-level ones are used.  The -r switch will cause subfolders
to be processed as well.  To apply a command other than "scan" use the
-c switch.

Examples:
---------
mhall first:2 5 +unix +inbox
   Will "scan" the first two messages and message number 5 in +unix,
   +inbox and any subfolders.

mhall -c show
   Show the current message of each top-level folder.

mhall -c folder -pack -r
   Invoke "folder" with the -pack option on every folder and subfolder.

Disclaimer: This is not elegant.


------------------SNIP------------------
#!/bin/csh -fb

#      mhall - apply a command to some or all of your MH folders.
#      Copyright (c) 1988 Wayne Mesard
#
#      This is free software.  It may be reproduced, retransmitted,
#      redistributed and otherwise propogated at will, provided that
#      this notice remains intact and in place.
#
#      Please direct bug reports, code enhancements and comments
#      to mesard@BBN.COM.

set tfolders
set args
set cmd
set recurse
set curfolder = `folder -fast`

while ( X$1 != X )
  switch ($1)
    case -help:
      echo "syntax: `basename $0` [-r] [-n] [-c command] [command-arg...] [+folder...]"
      exit 0
    case -c:
      set cmd = "$2"
      shift
      breaksw
    case -r:
      set recurse = "-recurse"
      breaksw
    case -n:
      set recurse = "-norecurse"
      breaksw
    case +*:
      set tfolders = "$tfolders $1"
      breaksw
    default:
      set args = "$args $1"
      breaksw
  endsw
  shift
end

if ("$tfolders" == "") then
  set folders = `folders $recurse -fast`
else
  set folders
  foreach folder ($tfolders)
    set folders = "$folders `folder $folder -recurse $recurse -fast`"
  end
endif

if ("$cmd" == "") then
  set cmd = "scan"
  if ("$args" == "") set args = "last"
endif

onintr CLEANUP

foreach folder ($folders)
  echo :${folder}:
  $cmd +$folder $args
end

CLEANUP:
folder +$curfolder >/dev/null
exit 0

-------------------------SNOOP-------------------

-- 
unsigned *Wayne_Mesard();    Vique's Law:
MESARD@BBN.COM                 A man without religion is like a fish
BBN, Cambridge, MA             without a bicycle.