#! /bin/csh -f # $Header: /Users/kono/src/CVS/mh/miscellany/sortf/sorts,v 1.1.1.1 2005/04/18 14:46:05 kono Exp $ # # ...USE csh BECAUSE OF msgs[1] AND shift msgs FEATURES... # # # Revised Sept. 1989 Mark-Jason Dominus. # # New usage: sorts [-[no]verbose] [-[no]fold] [+folder] [msgs] # umask 77 # PROTECT TEMPORARY FILE WITH -rw------- MODE set mhdir = /usr/local/mh set temp = /tmp/MSORT$$ # #set theFolder = \ ## '+'`grep '^Current-Folder' $HOME/mail/context | sed -e 's/.*: //'` # # Following code installed 13-14 Sept. 1989 M-J. Dominus # #Default arguments: # Which folder to sort? Default = current folder. set theFolder = `folder -fast` # Get help? Default: No help. set helpflag = 0 # Verbose sort? Default: Shut up. set vflag = 0 # Case-sensitive sort? Default: Yep. set foldflag = '-f' # Which messages? Default: all set theMessages = 'all' # Add support for an arglist like: sorts 4-6 8 12-23. # The *FIRST* time you see a nonflag argument, _set_ theMessages = argument. # *AFTER* the first time, _append_ the argument to theMessages. set firstMsgArg = 1 # # .mh_profile lines override default options. # #echo "argv before profile is $argv" set profileLine = `grep -i '^sorts' $HOME/.mh_profile | sed -e 's/.*: //'` set argv = ($profileLine $argv) #echo "argv after profile is $argv" # # Command-line arguments override .mh_profile and ordinary defaults. # while ("$argv" != '') if ("$1" == '-verbose') then set vflag = 1 else if ("$1" == '-noverbose') then set vflag = 0 else if ("$1" == '-fold') then set foldflag = '-f' else if ("$1" == '-nofold') then set foldflag = '' else if ("$1" =~ +* ) then # Measure twice, cut once. -D. set theFolder = `echo $1 | cut -c2-` else if ("$1" == '-help') then set helpflag = 1 else if ("$firstMsgArg" == '1') then set theMessages = "$1" set firstMsgArg = 0 else set theMessages = ($theMessages $1) endif endif shift end if ($helpflag) then cat <& /dev/null ##if ($vflag) echo "folder '`$mhdir/folder -fast`' packed for sorting" #if ($vflag) echo "folder +$theFolder packed for sorting" # GET MESSAGE NUMBERS AND SUBJECTS # THIS OLD STUFF WAS TO OVERRIDE USER'S PROFILE SWITCHES.... # NOW NEED TO REVISE THIS TO USE scan FORMAT FILE!! # DELETE "Re:" AND STARTS OF BODIES (< $temp set msgs = "`colrm 5 < $temp`" # cd TO CURRENT MAIL FOLDER, AND MAKE TEMPORARY DIRECTORY: set foldir = `$mhdir/mhpath` chdir $foldir mkdir MaIlSoRt$$ # GET LIST OF MESSAGES, IN ORDER, BY DATE: if ($vflag) echo "sorting messages into temporary sub-folder:" foreach sortmsg (`sort $foldflag +1 $temp | colrm 5`) # REMOVE LEADING BLANK ON $msgs[1]: if ($vflag) echo -n "$sortmsg " mv $sortmsg MaIlSoRt$$/`echo -n $msgs[1]` shift msgs end if ($vflag) echo "" # MOVE SORTED MESSAGES INTO CURRENT FOLDER AND REMOVE TEMPORARY STUFF: if ($vflag) echo "moving messages back to original folder" cd MaIlSoRt$$ mv * $foldir if ($status == 0) then cd $foldir rmdir MaIlSoRt$$ rm $temp endif