home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / mail / mh / 1545 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  20.0 KB

  1. Path: sparky!uunet!usc!news.service.uci.edu!ucivax!gateway
  2. From: wohler@sap-ag.de (Bill Wohler)
  3. Subject: mailarch-1.4: archive MH mail
  4. Message-ID: <9301231852.AA22117@sap-ag.de>
  5. Newsgroups: comp.mail.mh
  6. Organization: SAP AG  Walldorf, Germany
  7. Lines: 769
  8. Date: 23 Jan 93 19:03:08 GMT
  9. Phone: +49 6227-341658  Home: +49 6221-163255
  10.  
  11.   this is mailarch 1.4, a program to archive MH mail.
  12.  
  13.   it tars and compresses mh directories for substantial disk savings
  14.   (inodes too).  for example:
  15.  
  16.     [wohler@is0001:510]% du -s 1992/mar 1992/mar.tar.Z
  17.     6528    1992/mar
  18.     1360    1992/mar.tar.Z
  19.  
  20.   the idea of mailarch is to move certain folders into an archive area
  21.   monthly.  older archives are tarred and compressed.
  22.  
  23.   the programs seek and extract (enclosed) are used to extract
  24.   messages from the archive.
  25.  
  26.   please read the headers of the scripts for more information.  if you
  27.   use these, let me know and i'll place you on my mailing list.  if
  28.   you find the documentation in the headers non-illuminating, i want
  29.   to know about it.
  30.  
  31.   note: mailarch is a csh script and seek and extract are ksh scripts.
  32.   the PATH in these scripts may have to be updated for your environment.
  33.   known to work on aix and hpux.
  34.  
  35.   changes in mailarch since 1.3:
  36.   * Updated documentation for MH 6.8.
  37.   * Works on hpux.
  38.   * Extract's default output folder now +hold (instead on +hold$$).
  39.   * Bug fixes.
  40.  
  41.   changes in mailarch since 1.2:
  42.   * Create replacement folders with desired permissions.  (Major new
  43.     feature in the user interface.)
  44.   * Use mhparam to get .mh_profile components.
  45.   * Updated documentation.
  46.   * Check to ensure that a folder exists before processing.  On some errors,
  47.     either mailarch would hang, or bogus folders would get created.
  48.  
  49.                         --bw
  50.  
  51. #! /bin/sh
  52. # This is a shell archive.  Remove anything before this line, then unpack
  53. # it by saving it into a file and typing "sh file".  To overwrite existing
  54. # files, type "sh file -c".  You can also feed this as standard input via
  55. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  56. # will see the following message at the end:
  57. #        "End of archive 1 (of 1)."
  58. # Contents:  extract mailarch seek
  59. # Wrapped by wohler@is0001 on Sat Jan 23 19:45:29 1993
  60. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  61. if test -f 'extract' -a "${1}" != "-c" ; then
  62.   echo shar: Will not clobber existing file \"'extract'\"
  63. else
  64. echo shar: Extracting \"'extract'\" \(3687 characters\)
  65. sed "s/^X//" >'extract' <<'END_OF_FILE'
  66. X#! /bin/ksh
  67. X#
  68. X# $Id: extract,v 1.6 1993/01/23 18:22:53 wohler Exp $
  69. X#
  70. X# NAME
  71. X#   extract - extract mail messages from archives
  72. X#
  73. X# SYNOPSIS
  74. X#   extract [-c new-folder] year folder [msg ...]
  75. X#
  76. X# DESCRIPTION
  77. X#   In the case that no specific messages are designated, extract will extract
  78. X#   all messages in the year in the specified folder.  The folder in this case
  79. X#   is relative to the mail directory (ie +a/others).
  80. X#
  81. X#   If specific messages are specified, then only those messages are
  82. X#   extracted.    In this case, the folder specified must also include the year
  83. X#   and month (ie. +1991/jan/a/others).     The message list "all" is also
  84. X#   supported and extracts all messages from the folder.
  85. X#
  86. X#   The year argument is essentially an archive directory in the Mail
  87. X#   directory.  This program assumes that this archive contains the
  88. X#   subdirectories "jan," "feb," etc. as created by the mailarch program.
  89. X#
  90. X# OPTIONS
  91. X#   -c new-folder  specify the folder to hold the extracted messages
  92. X#           (default: +hold).
  93. X#
  94. X# RETURNS
  95. X#   0 normally; 1 upon error.
  96. X#
  97. X# BUGS
  98. X#   In pre-MH-6.8 versions that lack the mhparam command, use the
  99. X#   commented out setting of the "mail" variable below.
  100. X#
  101. X# AUTHOR
  102. X#   Bill Wohler <wohler@sap-ag.de>    SAP AG        22 July 1992
  103. X
  104. X# Constants (variables that do not change during runtime).
  105. X
  106. X# Defaults (variables that may be affected by arguments).
  107. Xnewfolder=hold
  108. X
  109. X# Initializations (internal variables that need to be set to something).
  110. XPATH=/usr/local/bin/mh:/bin:/usr/bin    # set minimum search path
  111. Xcmd=${0##*/}                # name by which command called
  112. Xexitstatus=0                # upon error, set to non-zero
  113. Xinterrupt=0                # upon interrupt, set to 1
  114. X#mail=$HOME/$(awk '/^Path/{print $2}' $HOME/.mh_profile)
  115. Xmail=$HOME/$(mhparam Path)
  116. Xmonths="jan feb mar apr may jun jul aug sep oct nov dec"
  117. X
  118. X# Functions
  119. X
  120. Xusage ()
  121. X{
  122. X    echo "Usage: $cmd [-c new-folder] year folder [msg ...]"
  123. X    bye 1
  124. X}
  125. X
  126. Xintr ()
  127. X{
  128. X    echo ""
  129. X    interrupt=1
  130. X    bye 1
  131. X}
  132. X
  133. X# Usage: bye [exit status] [exit message]
  134. Xbye ()
  135. X{
  136. X    if [ $# -gt 0 ]; then
  137. X        exitstatus=$1
  138. X        shift
  139. X    fi
  140. X    if [ $# -gt 0 ]; then
  141. X        echo "$*"
  142. X    elif [ $interrupt -eq 1 ]; then
  143. X        echo ""
  144. X    elif [ $exitstatus -eq 0 ]; then
  145. X        echo "Done."
  146. X    fi
  147. X    exit $exitstatus
  148. X}
  149. X
  150. X# Parse arguments
  151. Xwhile [ $# != 0 ]; do
  152. X    case "$1" in
  153. X    -c)    shift; newfolder=$1;;
  154. X    -v)    print=1;;
  155. X    -*)    usage;;
  156. X    *)    break;;
  157. X    esac
  158. X    shift
  159. Xdone
  160. X
  161. Xif [ $# -lt 2 ]; then
  162. X    usage
  163. Xfi
  164. X
  165. Xtrap intr 2
  166. X
  167. Xyear=$1
  168. Xfolder=${2#+}
  169. Xshift; shift
  170. Xmsgs=$*
  171. X
  172. X[ ! -d $mail/$year ] && bye 1 "$mail/$year does not exist."
  173. X[ -z "$newfolder" ]  && usage
  174. X
  175. Xfolder +$mail/$newfolder </dev/null > /dev/null  || bye 1
  176. Xcd $mail/$year || bye 1
  177. X
  178. Xecho "Extracting mail from archives."
  179. Xif [ -z "$msgs" ]; then
  180. X    # No messages given; extract all messages in folder for all months.
  181. X    for mon in $months; do
  182. X        if [ -f $mon.tar.Z ]; then
  183. X            zcat $mon.tar.Z | tar xvf - $year/$mon/$folder
  184. X            if [ -d $(mhpath +./$year/$mon/$folder) ]; then
  185. X                folder +./$year/$mon/$folder > /dev/null
  186. X                refile all +$newfolder
  187. X            fi
  188. X        fi
  189. X    done
  190. Xelse
  191. X    # Extract the named messages.
  192. X    if [ "$msgs" = all ]; then
  193. X        msglist=$folder
  194. X    else
  195. X        for i in $msgs; do
  196. X            msglist="$msglist $folder/$i"
  197. X        done
  198. X    fi
  199. X    mon=${folder#*/}            # strip junk to left of month
  200. X    mon=${mon%%/*}                # strip junk to right of month
  201. X    if [ -f $mon.tar.Z ]; then
  202. X        zcat $mon.tar.Z | tar xvf - $msglist
  203. X        if [ -d $(mhpath +./$folder) ]; then
  204. X            folder +./$folder > /dev/null
  205. X            refile all +$newfolder
  206. X        fi
  207. X    else
  208. X        bye 1 "$mon.tar.Z does not exist."
  209. X    fi
  210. Xfi
  211. X
  212. Xif [ ! -d $year ]; then
  213. X    bye 0 "No files extracted."
  214. Xelse
  215. X    # We can remove the now empty folders.
  216. X    rm -rf $mail/$year/$year
  217. Xfi
  218. X
  219. Xecho "Sorting mail."
  220. Xsortm +$newfolder
  221. X
  222. Xecho "Messages in +$newfolder."
  223. X
  224. Xbye
  225. X
  226. X# Local Variables:
  227. X# mode: sh
  228. X# End:
  229. END_OF_FILE
  230. if test 3687 -ne `wc -c <'extract'`; then
  231.     echo shar: \"'extract'\" unpacked with wrong size!
  232. fi
  233. chmod +x 'extract'
  234. # end of 'extract'
  235. fi
  236. if test -f 'mailarch' -a "${1}" != "-c" ; then
  237.   echo shar: Will not clobber existing file \"'mailarch'\"
  238. else
  239. echo shar: Extracting \"'mailarch'\" \(9675 characters\)
  240. sed "s/^X//" >'mailarch' <<'END_OF_FILE'
  241. X#! /bin/csh -f
  242. X#
  243. X# $Id: mailarch,v 1.6 1993/01/23 18:26:04 wohler Exp $
  244. X#
  245. X# NAME
  246. X#   mailarch - archive MH mail folders
  247. X#
  248. X# SYNOPSIS
  249. X#   mailarch [-a folders] [-f folders] [-m mail] [options] [-s] [-v]
  250. X#         thismonth [lastmonth]
  251. X#
  252. X# DESCRIPTION
  253. X#   After a period of time one's mail folders get quite full with
  254. X#   material that is rarely looked at.  This program is an attempt to
  255. X#   organize old mail.  The idea is that selected folders are moved
  256. X#   into a different place, usually at monthly intervals.  The first
  257. X#   time, the folder hierarchy is preserved.  The second time this
  258. X#   program is called, a month later, the old hierarchy is packed
  259. X#   (currently with tar) and compressed.  The mail itself can then be
  260. X#   easily stored on tape and the index saved on disk for searching
  261. X#   for old mail.
  262. X#
  263. X#   Usage is straightforward.  First create the MH profile components
  264. X#   "Archive" and "Parent-Folders" described below.  If one is
  265. X#   archiving mail from March, 1991, then the usage would be:
  266. X#
  267. X#    mailarch 1991/mar 1991/feb
  268. X#
  269. X#   This will move selected folders in your mail directory to the
  270. X#   folder 1991/mar.  This name is arbitrary and any intermediary
  271. X#   directories will be automatically created.  But, since it is a
  272. X#   folder, it will be created relative to your mail directory.
  273. X#
  274. X#   This archived folder is then rid of .mh_sequences files and
  275. X#   folders are sorted.  An index of all the messages is also created.
  276. X#   An opportunity to edit or remove large, unwanted files is also
  277. X#   given. The older folder is packed (currently with tar) into a single
  278. X#   file and removed.  The packed folder and its index are then
  279. X#   compressed.
  280. X#
  281. X#   Only parts of this process can be run by using the -o flags.
  282. X#
  283. X#   The names of the folders to be archived are found in the MH profile
  284. X#   "Archive"; names are separated by whitespace.
  285. X#
  286. X#   Pre-MH 6.7.1 versions could not create arbitrarily nested folders, so if
  287. X#   folders that contain subfolders are archived, then it is necessary to
  288. X#   recreate folder trees for them.  This MH profile is called
  289. X#   "Parent-Folders".  Folders listed may be suffixed by ":mode" in order to
  290. X#   override the default folder creation mode.  This "mode" is as in the
  291. X#   chmod(1) command (ie. can be either absolute or symbolic).  For example:
  292. X#
  293. X#    Archive: maillists friends out
  294. X#    Parent-Folders: maillists friends:700 out:700
  295. X#
  296. X#   This archives and recreates the "maillists", "friends", and "out" folders.
  297. X#   The friends and out folders are not accessible by members of the group or
  298. X#   others since they may contain sensitive mails.
  299. X#
  300. X# OPTIONS
  301. X#   -a folders
  302. X#    Override the MH profile value of "Archive" with "folders."
  303. X#    Surround multiple folders with double quotes.
  304. X#
  305. X#   -f folders
  306. X#    Override the MH profile value of "Parent-Folders" with "folders."
  307. X#    Surround multiple folders with double quotes.
  308. X#
  309. X#   -m mail
  310. X#    Set the name of the mail directory.  The default is the value
  311. X#    of the MH profile entry "Path."
  312. X#
  313. X#   -s size
  314. X#    Specify the size of file (in K) that should be edited or
  315. X#    removed (default is 25K).
  316. X#
  317. X#   -v
  318. X#    Display each of the steps.
  319. X#
  320. X#   By default, all of the following actions are performed in the
  321. X#   order listed.  If any of these options are specified, then no
  322. X#   other actions will be performed that are not also listed.
  323. X#
  324. X#   -om
  325. X#    Move the current folders into the new archive.
  326. X#   -os
  327. X#    Sort messages of the new archive.
  328. X#   -oi
  329. X#    Make an index of the new archive.
  330. X#   -op
  331. X#    Pack and compress the old archive.
  332. X#
  333. X# ENVIRONMENT
  334. X#   MH            If set, used instead of ~/.mh_profile.
  335. X#
  336. X# PROFILE COMPONENTS
  337. X#   Path        mail directory (must be relative to home directory).
  338. X#   Archive        folders to archive
  339. X#   Parent-Folders    folders to recreate
  340. X#
  341. X# BUGS
  342. X#   If your MH is pre-MH-6.8, uncomment the non-"mhparam" versions of setting
  343. X#   variables below.
  344. X#
  345. X#   I have to investigate whether or not files might be accidently
  346. X#   removed if you run out of disk space while packing files.
  347. X#
  348. X#   Various scan and sortm messages are displayed (ie. "no messages in folder")
  349. X#   These should be suppressed.
  350. X#
  351. X#   The archive folder name should be able to created automatically so that
  352. X#   this script can be cronned!  An idea would be to say that if it is after
  353. X#   the 15th of month B and before the 15th of month C, then the current month
  354. X#   is month B and last month is month A.
  355. X#
  356. X# AUTHOR
  357. X#   Bill Wohler <wohler@sap-ag.de>    SAP AG        1 March 1988
  358. X#
  359. X
  360. X# Defaults
  361. Xset all        = 1            # perform all operations
  362. Xset movefolders = 0            # move folders into old directory
  363. Xset sort    = 0            # sort messages
  364. Xset mkindex    = 0            # make an index
  365. Xset pack    = 0            # pack and compress folder
  366. Xset mail    = ~/`mhparam Path`    # mail directory
  367. Xset folders    = `mhparam Archive`    # folders to archive
  368. Xset mkfolders    = `mhparam Parent-Folders` # folders to recreate
  369. Xset size    = 25            # file size (kbytes) to edit or remove
  370. X
  371. X# In pre-MH.6.8 installations, uncomment these, and comment out like
  372. X# variables above.  mhprofile not needed in MH.6.8 or later.
  373. X#if ($?MH) then                # file containing archive config
  374. X#    set mhprofile = $MH
  375. X#else
  376. X#    set mhprofile = ~/.mh_profile
  377. X#endif
  378. X#set mail    = ~/`awk '/^Path/{print $2}' $mhprofile`
  379. X#set folders    = `awk '/^Archive/{for(i=2;i<=NF;i++)print $i}' $mhprofile`
  380. X#set mkfolders    = `awk '/^Parent-Folders/{for(i=2;i<=NF;i++)print $i}' $mhprofile`
  381. X
  382. X# Initializations
  383. Xset cmd        = $0            # name by which command called
  384. Xset exitstatus    = 0            # upon error, set to non-zero and exit
  385. Xset lastmonth oldarchive
  386. X
  387. X# If either no args, or just the directory, parsing args will get
  388. X# "Subscript out of range."
  389. Xif ($#argv == 0) \
  390. X    goto usage
  391. X
  392. X# Parse arguments
  393. Xwhile ("$argv[1]" =~ -*)
  394. X    switch ("$argv[1]")
  395. X    case "-a":
  396. X        shift
  397. X        set folders = ($argv[1])
  398. X        breaksw
  399. X
  400. X    case "-f":
  401. X        shift
  402. X        set mkfolders = ($argv[1])
  403. X        breaksw
  404. X
  405. X    case "-m":
  406. X        shift
  407. X        set mail = $argv[1]
  408. X        breaksw
  409. X
  410. X    case "-oi":
  411. X        set mkindex = 1
  412. X        set all = 0
  413. X        breaksw
  414. X
  415. X    case "-op":
  416. X        set pack = 1
  417. X        set all = 0
  418. X        breaksw
  419. X
  420. X    case "-om":
  421. X        set movefolders = 1
  422. X        set all = 0
  423. X        breaksw
  424. X
  425. X    case "-os":
  426. X        set sort = 1
  427. X        set all = 0
  428. X        breaksw;
  429. X
  430. X    case "-s":
  431. X        shift
  432. X        set size = $argv[1]
  433. X        breaksw
  434. X
  435. X    case "-v":
  436. X        set print = 1
  437. X        breaksw
  438. X
  439. X    default:
  440. X        goto usage
  441. X    endsw
  442. X    shift
  443. X    if ($#argv == 0) \
  444. X        break
  445. Xend
  446. X
  447. Xif ($#argv < 1) \
  448. X    goto usage
  449. X
  450. Xset archive = $argv[1]
  451. X
  452. Xif ($#argv > 1) then
  453. X    set lastmonth = $argv[2]
  454. Xendif
  455. X
  456. X# Now check that each needed variable is non-nil.
  457. X
  458. Xif (! -e $mail) then
  459. X    echo "${mail}: No such directory."
  460. X    set exitstatus = 1
  461. X    goto bye
  462. Xendif
  463. Xif ($lastmonth != "" && ! -e $mail/$lastmonth) then
  464. X    echo "${lastmonth}: No such directory."
  465. X    set exitstatus = 1
  466. X    goto bye
  467. Xendif
  468. Xif ("$folders" == "") then
  469. X    echo "No folders to archive."
  470. X    set exitstatus = 1
  471. X    goto bye
  472. Xendif
  473. X
  474. Xskipargs:
  475. Xonintr intr
  476. X
  477. X
  478. X# Move folders to archive and then create folders that must always exist.
  479. Xif ($movefolders || $all) then
  480. X    if ($?print) \
  481. X        echo "Moving ($folders) to $archive"
  482. X    cd $mail || exit 1
  483. X    mkdir `echo $mail/$archive|awk -F/ '{for(i=2;i<=NF;i++){for(j=2;j<=i;j++)printf"/%s",$j;printf"\n"}}'` >& /dev/null
  484. X    mv $folders $archive
  485. X
  486. X    # Recreate folders with non-default permissions if desired.
  487. X    if ("$mkfolders" != "") then
  488. X        if ($?print) \
  489. X            echo "Recreating $mkfolders"
  490. X        foreach i ($mkfolders)
  491. X            set folder = `echo $i | sed 's/:.*$//'`
  492. X            set mode = `echo $i | sed 's/^.*://'`
  493. X            # The redirection here is to keep the folder command
  494. X            # from being interactive.
  495. X            folder +$folder            </dev/null>/dev/null
  496. X            if ($folder != $mode) then
  497. X                if ($?print) \
  498. X                    echo chmod $mode `mhpath +$folder`
  499. X                chmod $mode `mhpath +$folder`
  500. X            endif
  501. X        end
  502. X    endif
  503. Xendif
  504. X
  505. X# Sort messages in archive.
  506. Xif ($sort || $all) then
  507. X    # Make sure we don't archive postings of sources...
  508. X    cd $mail/$archive || exit 1
  509. X    set large = `find . -size +$size -print`
  510. X    if ("$large" != "") then
  511. X        echo "Edit large files, or remove later."
  512. X        sleep 2
  513. X        vi $large
  514. X        echo "Interactively remove large files."
  515. X        foreach i ($large)
  516. X            grep ^Subject $i
  517. X            rm -i $i
  518. X        end
  519. X    endif
  520. X
  521. X    foreach i (`folders -recurse -fast +$archive`)
  522. X        if (! -d $mail/$i) \
  523. X            continue
  524. X        if ($?print) \
  525. X            echo "Sorting $i..."
  526. X        sortm +$i
  527. X        folder -pack +$i            >/dev/null</dev/null
  528. X    end
  529. Xendif
  530. X
  531. X# Make index of archive.
  532. Xif ($mkindex || $all) then
  533. X    set index = $mail/$archive.idx
  534. X    rm -f $index
  535. X    # try to rewrite to use +$archive rather than +. to reduce characters.
  536. X    foreach i (`folders -recurse -fast +$archive`)
  537. X        if (! -d $mail/$i) \
  538. X            continue
  539. X        if ($?print) \
  540. X            echo "Scanning $i..."
  541. X        echo "" >>! $index
  542. X        scan -header +$i >>! $index
  543. X        # if no messages, should just have a small mesg
  544. X        # on same line as the echo $i.
  545. X    end
  546. Xendif
  547. X
  548. X# Now, tar and compress last month's archive if given.
  549. Xif (($pack || $all) && "$lastmonth" != "") then
  550. X    if ("$oldarchive" == "") \
  551. X        set oldarchive = $lastmonth.tar
  552. X    set oldindex = $lastmonth.idx
  553. X    cd $mail/$lastmonth || exit 1
  554. X    if ($?print) \
  555. X        echo "Cleaning $lastmonth..."
  556. X    find . -name .mh_sequences -exec rm {} \;
  557. X    if ($?print) \
  558. X        echo "Creating $oldarchive..."
  559. X    cd $mail
  560. X    rm -f $oldarchive
  561. X    tar -cf $oldarchive $lastmonth
  562. X    if ($status == 0) \
  563. X        rm -rf $lastmonth
  564. X    if ($?print) \
  565. X        echo "Compressing $oldarchive and $oldindex..."
  566. X    chmod 444 $oldarchive $oldindex
  567. X    compress $oldarchive $oldindex
  568. Xendif
  569. X
  570. Xgoto bye
  571. X
  572. Xusage:
  573. X    echo "Usage: $cmd:t [-a folders ] [-f folders] [-m mail] [options] [-s size] [-v] thismonth [lastmonth]"
  574. X    echo "Options:"
  575. X    echo "    -om  move the current folders into the current month"
  576. X    echo "    -os  sort messages of the current month"
  577. X    echo "    -oi  make an index of the current month"
  578. X    echo "    -op  pack and compress the last month"
  579. X    exit(1)
  580. X
  581. Xintr:
  582. X    echo ""
  583. X    set interrupt exitstatus = 1
  584. X    # Fall through!
  585. X
  586. Xbye:
  587. X    if ($?print) \
  588. X        echo "Done."
  589. X    exit($exitstatus)
  590. END_OF_FILE
  591. if test 9675 -ne `wc -c <'mailarch'`; then
  592.     echo shar: \"'mailarch'\" unpacked with wrong size!
  593. fi
  594. chmod +x 'mailarch'
  595. # end of 'mailarch'
  596. fi
  597. if test -f 'seek' -a "${1}" != "-c" ; then
  598.   echo shar: Will not clobber existing file \"'seek'\"
  599. else
  600. echo shar: Extracting \"'seek'\" \(2796 characters\)
  601. sed "s/^X//" >'seek' <<'END_OF_FILE'
  602. X#! /bin/ksh
  603. X#
  604. X# $Id: seek,v 1.6 1993/01/23 18:25:18 wohler Exp $
  605. X#
  606. X# NAME
  607. X#   seek -- find names or subjects from archives
  608. X#
  609. X# SYNOPSIS
  610. X#   seek search-string [year ...]
  611. X#
  612. X# DESCRIPTION
  613. X#   Seek searches the indexes for the desired string.  If there is white space
  614. X#   within the string, enclose the string in quotes.
  615. X#
  616. X#   Multiple years can be specified; if the year is omitted, the current year
  617. X#   is used.
  618. X#
  619. X#   The year argument is essentially an archive directory in the Mail
  620. X#   directory.  This program assumes that this archive contains the
  621. X#   indices "jan.idx.Z," "feb.idx.Z," etc. as created by the mailarch
  622. X#   program.
  623. X#
  624. X# OPTIONS
  625. X#
  626. X# RETURNS
  627. X#   0 normally; 1 upon error.
  628. X#
  629. X# BUGS
  630. X#   In pre-MH-6.8 versions that lack the mhparam command, use the
  631. X#   commented out setting of the "mail" variable below.
  632. X#
  633. X# AUTHOR
  634. X#   Bill Wohler <wohler@sap-ag.de>    SAP AG        18 May 92
  635. X
  636. X# Constants (variables that do not change during runtime).
  637. X
  638. X# Defaults (variables that may be affected by arguments).
  639. X
  640. X# Initializations (internal variables that need to be set to something).
  641. XPATH=/usr/local/bin/mh:/bin:/usr/bin:/usr/ucb    # set minimum search path
  642. Xcmd=${0##*/}                # name by which command called
  643. Xmail=$HOME/$(mhparam Path)        # mail folder
  644. X#mail=$HOME/$(awk '/^Path/{print $2}' $HOME/.mh_profile)
  645. Xmonths="jan feb mar apr may jun jul aug sep oct nov dec"
  646. Xexitstatus=0                # upon error, set to non-zero and exit
  647. Xinterrupt=0                # upon interrupt, set to 1
  648. X
  649. X# Functions
  650. X
  651. Xusage () {
  652. X    echo "Usage: $cmd search-string [year ...]"
  653. X    bye 1
  654. X}
  655. X
  656. Xintr ()
  657. X{
  658. X    echo ""
  659. X    interrupt=1
  660. X    bye 1
  661. X}
  662. X
  663. Xbye ()
  664. X{
  665. X    if [ $# -gt 0 ]; then
  666. X        exitstatus=$1
  667. X        shift
  668. X    fi
  669. X    if [ $# -gt 0 ]; then
  670. X        echo "$*"
  671. X    elif [ $interrupt -eq 1 ]; then
  672. X        echo ""
  673. X    elif [ $exitstatus -eq 0 ]; then
  674. X        echo "Done."
  675. X    fi
  676. X    exit $exitstatus
  677. X}
  678. X
  679. X# Usage: find pattern
  680. Xsearch ()
  681. X{
  682. X    if [ $# -ne 1 ]; then
  683. X        echo "Internal error: search() usage incorrect."
  684. X        return;
  685. X    fi
  686. X
  687. X    pattern=$1
  688. X
  689. X    awk '
  690. X        /^Folder/ {
  691. X            header = $0
  692. X            header_printed = 0
  693. X            next
  694. X        }
  695. X
  696. X        /'$pattern'/ {
  697. X            if (! header_printed) {
  698. X                print header
  699. X                header_printed = 1
  700. X            }
  701. X            print $0
  702. X        }
  703. X
  704. X        {
  705. X            next
  706. X        }
  707. X    '
  708. X}
  709. X
  710. X# Parse arguments
  711. Xwhile [ $# != 0 ]; do
  712. X    case "$1" in
  713. X    -v)    print=1;;
  714. X    -*)    usage;;
  715. X    *)    break;;
  716. X    esac
  717. X    shift
  718. Xdone
  719. Xif [ $# -lt 1 ]; then
  720. X    usage
  721. Xfi
  722. Xsearch=$1
  723. Xshift
  724. Xyear=$*
  725. X
  726. Xif [ -z "$year" ]; then
  727. X    if whence uname > /dev/null; then
  728. X        [ "$(uname -s)" = HP-UX ] && machine=hp
  729. X    fi
  730. X    case "$machine" in
  731. X    hp)    year=$(date | awk '{print $6}');;
  732. X    *)    year=$(date | awk '{print $5}');;
  733. X    esac
  734. Xfi
  735. X
  736. Xtrap intr 2
  737. X
  738. Xfor i in $year; do
  739. X    cd $mail/$i || continue
  740. X    for j in $months; do
  741. X        if [ -f $j.idx.Z ]; then
  742. X            zcat $j.idx.Z | search "$search"
  743. X        elif [ -f $j.idx ]; then
  744. X            cat $j.idx | search "$search"
  745. X        else
  746. X            echo "No index for $j."
  747. X        fi
  748. X    done
  749. Xdone
  750. X
  751. Xbye
  752. X
  753. X# Local Variables:
  754. X# mode: sh
  755. X# End:
  756. END_OF_FILE
  757. if test 2796 -ne `wc -c <'seek'`; then
  758.     echo shar: \"'seek'\" unpacked with wrong size!
  759. fi
  760. chmod +x 'seek'
  761. # end of 'seek'
  762. fi
  763. echo shar: End of archive 1 \(of 1\).
  764. cp /dev/null ark1isdone
  765. MISSING=""
  766. for I in 1 ; do
  767.     if test ! -f ark${I}isdone ; then
  768.     MISSING="${MISSING} ${I}"
  769.     fi
  770. done
  771. if test "${MISSING}" = "" ; then
  772.     echo You have the archive.
  773.     rm -f ark[1-9]isdone
  774. else
  775.     echo You still need to unpack the following archives:
  776.     echo "        " ${MISSING}
  777. fi
  778. ##  End of shell archive.
  779. exit 0
  780.