3 # $Header: mail.sort,v 2.5 87/09/19 05:55:23 jerryp Exp $
5 # ...USE csh BECAUSE OF msgs[1] AND shift msgs FEATURES...
8 # Revised Sept. 1989 Mark-Jason Dominus.
10 # New usage: sorts [-[no]verbose] [-[no]fold] [+folder] [msgs]
13 umask 77 # PROTECT TEMPORARY FILE WITH -rw------- MODE
14 set mhdir = /usr/local/mh
15 set temp = /tmp/MSORT$$
19 ## '+'`grep '^Current-Folder' $HOME/mail/context | sed -e 's/.*: //'`
21 # Following code installed 13-14 Sept. 1989 M-J. Dominus
24 # Which folder to sort? Default = current folder.
25 set theFolder = `folder -fast`
26 # Get help? Default: No help.
28 # Verbose sort? Default: Shut up.
30 # Case-sensitive sort? Default: Yep.
32 # Which messages? Default: all
33 set theMessages = 'all'
35 # Add support for an arglist like: sorts 4-6 8 12-23.
36 # The *FIRST* time you see a nonflag argument, _set_ theMessages = argument.
37 # *AFTER* the first time, _append_ the argument to theMessages.
41 # .mh_profile lines override default options.
43 #echo "argv before profile is $argv"
44 set profileLine = `grep -i '^sorts' $HOME/.mh_profile | sed -e 's/.*: //'`
45 set argv = ($profileLine $argv)
46 #echo "argv after profile is $argv"
49 # Command-line arguments override .mh_profile and ordinary defaults.
52 if ("$1" == '-verbose') then
54 else if ("$1" == '-noverbose') then
56 else if ("$1" == '-fold') then
58 else if ("$1" == '-nofold') then
60 else if ("$1" =~ +* ) then
61 # Measure twice, cut once. -D.
62 set theFolder = `echo $1 | cut -c2-`
63 else if ("$1" == '-help') then
66 if ("$firstMsgArg" == '1') then
67 set theMessages = "$1"
70 set theMessages = ($theMessages $1)
78 syntax: sorts [+folder] [msgs] [switches]
86 # End of 14 Sept. 1989 argument-parsing additions. M-J.D.
88 # REMOVE GAPS BEFORE SORTING (IGNORE folder'S OUTPUT):
90 # Commented out 14 Sept. 1989 M-J.D.
92 #$mhdir/folder -pack '+'$theFolder >& /dev/null
93 ##if ($vflag) echo "folder '`$mhdir/folder -fast`' packed for sorting"
94 #if ($vflag) echo "folder +$theFolder packed for sorting"
96 # GET MESSAGE NUMBERS AND SUBJECTS
97 # THIS OLD STUFF WAS TO OVERRIDE USER'S PROFILE SWITCHES....
98 # NOW NEED TO REVISE THIS TO USE scan FORMAT FILE!!
99 # DELETE "Re:" AND STARTS OF BODIES (<<etc. etc.) FROM SUBJECT FIELDS:
101 if ($vflag) echo "scanning folder for message numbers and subjects"
103 #$mhdir/scan -noheader -nonumdate -nosize -notime $argv | cut -c1-4,30- | \
105 $mhdir/scan -noheader '+'$theFolder $theMessages | cut -c1-4,30- | \
106 sed -e 's/^\(......\)[Rr][Ee]:[ ]*/\1/' -e 's/<<.*//' > $temp
107 set msgs = "`colrm 5 < $temp`"
109 # cd TO CURRENT MAIL FOLDER, AND MAKE TEMPORARY DIRECTORY:
110 set foldir = `$mhdir/mhpath`
114 # GET LIST OF MESSAGES, IN ORDER, BY DATE:
115 if ($vflag) echo "sorting messages into temporary sub-folder:"
116 foreach sortmsg (`sort $foldflag +1 $temp | colrm 5`)
117 # REMOVE LEADING BLANK ON $msgs[1]:
118 if ($vflag) echo -n "$sortmsg "
119 mv $sortmsg MaIlSoRt$$/`echo -n $msgs[1]`
124 # MOVE SORTED MESSAGES INTO CURRENT FOLDER AND REMOVE TEMPORARY STUFF:
125 if ($vflag) echo "moving messages back to original folder"
128 if ($status == 0) then