Mercurial > hg > Applications > mh
diff miscellany/sortf/sorts @ 0:bce86c4163a3
Initial revision
author | kono |
---|---|
date | Mon, 18 Apr 2005 23:46:02 +0900 |
parents | |
children | 441a2190cfae |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/miscellany/sortf/sorts Mon Apr 18 23:46:02 2005 +0900 @@ -0,0 +1,132 @@ +#! /bin/csh -f + +# $Header$ +# +# ...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 <<END_OF_HELP +syntax: sorts [+folder] [msgs] [switches] + switches are: + -[no]verbose + -[no]fold + -(help) +END_OF_HELP + exit +endif +# End of 14 Sept. 1989 argument-parsing additions. M-J.D. + +# REMOVE GAPS BEFORE SORTING (IGNORE folder'S OUTPUT): +# +# Commented out 14 Sept. 1989 M-J.D. +# +#$mhdir/folder -pack '+'$theFolder >& /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 (<<etc. etc.) FROM SUBJECT FIELDS: + +if ($vflag) echo "scanning folder for message numbers and subjects" + +#$mhdir/scan -noheader -nonumdate -nosize -notime $argv | cut -c1-4,30- | \ + +$mhdir/scan -noheader '+'$theFolder $theMessages | cut -c1-4,30- | \ + sed -e 's/^\(......\)[Rr][Ee]:[ ]*/\1/' -e 's/<<.*//' > $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