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: Nope.
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 '^sortf' $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: sortf [+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 senders"
103 #$mhdir/scan -noheader -nonumdate -nosize -notime $argv | cut -c1-4,30- | \
105 # The cut -c1-19 is because otherwise we would strip the
106 # 'To:' off of 'To:rissa@gargoyle' and then we would be left
107 # with 'rissa@gargoyle' which compares less than
108 # 'rissa@gargoyle.uc' which is what we see when rissa wrote
109 # to us instead of the other way around. So we lop off the
110 # last three characters to even things out. 16 Sept 1989 M-J. Dominus
112 $mhdir/scan -noheader '+'$theFolder $theMessages | cut -c1-4,12-29 | \
113 sed -e 's/^\(.....\)[Tt][Oo]:[ ]*/\1/' -e 's/<<.*//' | \
117 set msgs = "`colrm 5 < $temp`"
119 # cd TO CURRENT MAIL FOLDER, AND MAKE TEMPORARY DIRECTORY:
120 set foldir = `$mhdir/mhpath`
121 set tmpfoldir = 'MaIlSoRt$$'
125 # GET LIST OF MESSAGES, IN ORDER, BY DATE:
126 if ($vflag) echo "sorting messages into temporary sub-folder:"
127 foreach sortmsg (`sort $foldflag +1 $temp | colrm 5`)
128 # REMOVE LEADING BLANK ON $msgs[1]:
129 if ($vflag) echo -n "$sortmsg "
130 mv $sortmsg $tmpfoldir/`echo -n $msgs[1]`
135 # MOVE SORTED MESSAGES INTO CURRENT FOLDER AND REMOVE TEMPORARY STUFF:
136 if ($vflag) echo "moving messages back to original folder"
139 if ($status == 0) then