comparison miscellany/sortf/sorts @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children 441a2190cfae
comparison
equal deleted inserted replaced
-1:000000000000 0:bce86c4163a3
1 #! /bin/csh -f
2
3 # $Header$
4 #
5 # ...USE csh BECAUSE OF msgs[1] AND shift msgs FEATURES...
6 #
7 #
8 # Revised Sept. 1989 Mark-Jason Dominus.
9 #
10 # New usage: sorts [-[no]verbose] [-[no]fold] [+folder] [msgs]
11 #
12
13 umask 77 # PROTECT TEMPORARY FILE WITH -rw------- MODE
14 set mhdir = /usr/local/mh
15 set temp = /tmp/MSORT$$
16
17 #
18 #set theFolder = \
19 ## '+'`grep '^Current-Folder' $HOME/mail/context | sed -e 's/.*: //'`
20 #
21 # Following code installed 13-14 Sept. 1989 M-J. Dominus
22 #
23 #Default arguments:
24 # Which folder to sort? Default = current folder.
25 set theFolder = `folder -fast`
26 # Get help? Default: No help.
27 set helpflag = 0
28 # Verbose sort? Default: Shut up.
29 set vflag = 0
30 # Case-sensitive sort? Default: Yep.
31 set foldflag = '-f'
32 # Which messages? Default: all
33 set theMessages = 'all'
34
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.
38 set firstMsgArg = 1
39
40 #
41 # .mh_profile lines override default options.
42 #
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"
47
48 #
49 # Command-line arguments override .mh_profile and ordinary defaults.
50 #
51 while ("$argv" != '')
52 if ("$1" == '-verbose') then
53 set vflag = 1
54 else if ("$1" == '-noverbose') then
55 set vflag = 0
56 else if ("$1" == '-fold') then
57 set foldflag = '-f'
58 else if ("$1" == '-nofold') then
59 set foldflag = ''
60 else if ("$1" =~ +* ) then
61 # Measure twice, cut once. -D.
62 set theFolder = `echo $1 | cut -c2-`
63 else if ("$1" == '-help') then
64 set helpflag = 1
65 else
66 if ("$firstMsgArg" == '1') then
67 set theMessages = "$1"
68 set firstMsgArg = 0
69 else
70 set theMessages = ($theMessages $1)
71 endif
72 endif
73 shift
74 end
75
76 if ($helpflag) then
77 cat <<END_OF_HELP
78 syntax: sorts [+folder] [msgs] [switches]
79 switches are:
80 -[no]verbose
81 -[no]fold
82 -(help)
83 END_OF_HELP
84 exit
85 endif
86 # End of 14 Sept. 1989 argument-parsing additions. M-J.D.
87
88 # REMOVE GAPS BEFORE SORTING (IGNORE folder'S OUTPUT):
89 #
90 # Commented out 14 Sept. 1989 M-J.D.
91 #
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"
95
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:
100
101 if ($vflag) echo "scanning folder for message numbers and subjects"
102
103 #$mhdir/scan -noheader -nonumdate -nosize -notime $argv | cut -c1-4,30- | \
104
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`"
108
109 # cd TO CURRENT MAIL FOLDER, AND MAKE TEMPORARY DIRECTORY:
110 set foldir = `$mhdir/mhpath`
111 chdir $foldir
112 mkdir MaIlSoRt$$
113
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]`
120 shift msgs
121 end
122 if ($vflag) echo ""
123
124 # MOVE SORTED MESSAGES INTO CURRENT FOLDER AND REMOVE TEMPORARY STUFF:
125 if ($vflag) echo "moving messages back to original folder"
126 cd MaIlSoRt$$
127 mv * $foldir
128 if ($status == 0) then
129 cd $foldir
130 rmdir MaIlSoRt$$
131 rm $temp
132 endif