From:	CSBVAX::MRGATE!info-vax-RELAY@KL.SRI.COM@SMTP  4-JAN-1978 10:35
To:	ARISIA::EVERHART
Subj:	Pre-sorting NEWMAIL entries


Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Tue, 21 Jun 88 16:31:06 PDT
Received: from IRUCCIBM by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 2425; Tue, 21 Jun 88 19:30:37 EDT
Received: by IRUCCIBM (Mailer X1.25) id 6797; Mon, 20 Jun 88 16:36:27 IST
Date:         Mon, 20 Jun 88 14:14:48 IST
From:         "J.F.Murphy" <CBSY8001%IRUCCIBM.BITNET@CUNYVM.CUNY.EDU>
Subject:      Pre-sorting NEWMAIL entries
To:           info-vax@kl.sri.com

Hi,
From a recent info-vax entry -

> ... I have examined the
> manuals, and I see no description of any routines for manipulating
> mail files, or even a description of the format of said files. Where
> do I have to go to get one? The microfiche of the system source. I
> don't know about you, but *I'm* not likely to put a lot of work into
> something that someone else in an office somewhere can radically
> change on a whim.
>> ... you don't particularly _need_ to do it in mail ... a simple
>>TPU program which worked on an extracted mail file would be enough).

I'm glad to see other folks find at least SOME aspects of VMS MAIL less
than a total joy.   My main gripe used to be the inability to sort entries
in anything OTHER than date sequence. Normally this isn't a problem
BUT if I've been away a few days and come back to 100+ NEWMAIL items
then, not posessing a photographic memory, I find it a nuisance
having to flit around the mail menu looking thru related-subject entries.

We've VAX and IBM BitNet/EARN nodes here and I used to subscribe
to "busy" lists via the IBM 'cos RiceMAIL, although slow, is VERY
versatile when it comes to re-sequencing mail entries.
(Also, one has the option of replying directly to From: (the individual)
 or Sender: (the list)  ).

Anyway, I eventually cobbled together  MAILSORTER.COM  to help
re-sequence unread VAX Mail entries. Its painfully slow, the method
used is cumbersome -but I've come to find it quite useful and now
look on it as a stopgap until DEC see fit to give the world a
DIR/SEQ=xxx add-on  to the STANDARD mail command..
                           ********

Herewith is a de-commented version - mail me direct if
you feel you must have the full gory detailed, commented one !.
All improvements to this routine gratefully accepted.

Enjoy.
jfm

J.F.Murphy (Project Manager -Systems)
Cork University, Ireland
BITNET/EARN   CBSY8001@IRUCCIBM.BITNET,  CBSY8001@IRUCCVAX.BITNET
HEANET        CBSY8001@IBM1.UCC.IE,      CBSY8001@VAX1.UCC.IE




........................ Cut between dotted lines and save .....................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by CBSY8001
$! on Monday 20-JUN-1988 16:00:50.85
$!
$! It contains the following 1 file:
$! MAILSORTER.COM
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="MAILSORTER.COM"
$ Check_Sum_is=1697399019
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$! MAILSORTER.COM - decommented on 20-JUN-1988 15:34:18.31
X$ v = 'f$VERIFY(0)'
X$ SET NoON
X$ IF P1.EQS."?" THEN GOTO HELP
X$ set = "SET"
X$ SET SYMBOL/SCOPE=(NoLOCAL,NoGLOBAL)
X$ say = "WRITE SYS$OUTPUT"
X$ subj_seq = "SUBJECT:"
X$ subject_key = "/KEY=(POS:41,SIZ:38)"
X$ from_seq = "FROM:"
X$ from_key = "/KEY=(POS:07,SIZ:20) /KEY=(POS:41,SIZ:38)"
X$ IF P1.EQS."" THEN P1 = "FROM:"
X$ par = f$EDIT(P1,"TRIM,UPCASE")
X$ parl = f$LENGTH(par)
X$ sequence = ""
X$ flag = par.EQS.f$EXTRACT(0,parl,subj_seq)
X$ IF flag THEN sortkey = subject_key
X$ IF flag THEN sequence = subj_seq
X$ flag = par.EQS.f$EXTRACT(0,parl,from_seq)
X$ IF flag THEN sortkey = from_key
X$ IF flag THEN sequence = from_seq
X$ IF sequence.EQS."" THEN GOTO BAD_PAR
X$ scratchfile = "SYS$SCRATCH:MAILSORTER.SCRATCH"
X$ rdir = f$ENVIRONMENT("DEFAULT")
X$ SET DEFAULT SYS$LOGIN
X$ mailfile = f$SEARCH("MAIL.MAI;")
X$ IF mailfile.EQS."" THEN mailfile = f$SEARCH("[.MAIL]MAIL.MAI;")
X$ IF mailfile.EQS."" THEN mailfile = f$SEARCH("[...]MAIL.MAI;")
X$ IF mailfile.EQS."" THEN GOTO NO_MAIL_FILE
X$ SET DEFAULT 'rdir'
X$ IF f$SEARCH(scratchfile).NES."" THEN DELETE 'scratchfile';* /NoLOG
X$ say "... Generating a list of folder NEWMAIL contents"
X$ DEFINE/USER_MODE SYS$OUTPUT 'scratchfile';1
X$ MAIL
XSELECT NEWMAIL
XDIR
XEXIT
X$ say "...'Pruning' the list of folder NEWMAIL contents"
X$ DEFINE/USER_MODE SYS$OUTPUT NL:
V$ EDIT /TPU /NoSECTION /NoDISPLAY /COMMAND=SYS$INPUT /OUTPUT='scratchfile';2 's
Xcratchfile';1
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
Xfil:=GET_INFO(COMMAND_LINE,"FILE_NAME");buf:=CREATE_BUFFER("",fil);
Xout:=GET_INFO(COMMAND_LINE,"OUTPUT_FILE");SET(OUTPUT_FILE,buf,out);
XPOSITION(BEGINNING_OF(buf));x:="%MAIL-I-SELECTED, 0 messages selected";
Xn:=SEARCH(x,FORWARD,EXACT);IF (n<>0) THEN QUIT; ENDIF;
XPOSITION(BEGINNING_OF(buf));
Vx:="%MAIL-E-NOTEXIST, folder NEWMAIL does not exist";n:=SEARCH(x,FORWARD,EXACT)
X;
XIF (n<>0) THEN QUIT;ENDIF;POSITION(BEGINNING_OF(buf));
XLOOP IF`009(LENGTH(CURRENT_LINE)<35) OR (SUBSTR(CURRENT_LINE,30,1)<>"-") OR
X(SUBSTR(CURRENT_LINE,34,3)<>"-19") THEN`009ERASE_LINE;ELSE MOVE_VERTICAL(1);
XENDIF;EXITIF MARK(NONE)=END_OF(buf);ENDLOOP;POSITION(BEGINNING_OF(buf));
XCHANGE_CASE(buf,UPPER);EXIT;
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
X$ IF f$SEARCH("''scratchfile';-1").EQS."" THEN GOTO NO_NEW_MAIL
X$ PURGE/NoLOG 'scratchfile'
V$ say "... Sorting  the list of folder NEWMAIL contents in ", sequence, " Seque
Xnce"
X$ SORT 'scratchfile';2 'scratchfile';3 'sortkey'
X$ PURGE 'scratchfile' /NoLOG
V$ say "... Generating a command file to extract NEWMAIL contents in ", sequence
X, " Sequence"
X$ DEFINE/USER_MODE SYS$OUTPUT NL:
V$ EDIT /TPU /NoSECTION /NoDISPLAY /COMMAND=SYS$INPUT /OUTPUT='scratchfile';4 's
Xcratchfile';3
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
Xfil:=GET_INFO(COMMAND_LINE,"FILE_NAME");buf:=CREATE_BUFFER("",fil);
Xout:=GET_INFO(COMMAND_LINE,"OUTPUT_FILE");SET(OUTPUT_FILE,buf,out);
XPOSITION(BEGINNING_OF(buf));COPY_TEXT("$MAIL");SPLIT_LINE;
XCOPY_TEXT("SELECT NEWMAIL");SPLIT_LINE;LOOP nnn:=SUBSTR(CURRENT_LINE,1,5);
XCOPY_TEXT("READ"+nnn);SPLIT_LINE;COPY_TEXT("EXTRACT/APPEND extract_file");
XSPLIT_LINE;COPY_TEXT("DELETE"+nnn);SPLIT_LINE;ERASE_LINE;
XEXITIF MARK(NONE)=END_OF(buf);ENDLOOP;EXIT;
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
X$ IF f$SEARCH("''scratchfile';-1").EQS."" THEN GOTO NO_NEW_MAIL
V$ say "... Running  the command file to extract NEWMAIL contents in ", sequence
X, " Sequence"
X$ DEFINE/USER extract_file 'scratchfile';5
X$ @'scratchfile' /OUT=NLA0:
X$ PURGE 'scratchfile' /NoLOG
X$ say "... 'Re-DateStamping' the extract file entries with current date+time"
X$ DEFINE/USER_MODE SYS$OUTPUT NL:
V$ EDIT /TPU /NoSECTION /NoDISPLAY /COMMAND=SYS$INPUT /OUTPUT='scratchfile';6 's
Xcratchfile';5
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
Xfil:=GET_INFO(COMMAND_LINE,"FILE_NAME");buf:=CREATE_BUFFER("",fil);
Xout:=GET_INFO(COMMAND_LINE,"OUTPUT_FILE");SET(OUTPUT_FILE,buf,out);
Xff:=ASCII(12);count:=0;POSITION(BEGINNING_OF(buf));
XLOOP EXITIF MARK(NONE)=END_OF(buf);x:=SEARCH(ff,FORWARD,EXACT);EXITIF (x=0);
XPOSITION(x);cl:=CURRENT_LINE;IF (LENGTH(cl)=1) THEN MOVE_VERTICAL(1);
XEXITIF MARK(NONE)=END_OF(buf);cl:=CURRENT_LINE;x:=SUBSTR(cl,1,5);
XIF (x="From:") THEN eol:=LINE_END;y:=SEARCH(eol,FORWARD);POSITION(y);
XERASE_CHARACTER(-17);COPY_TEXT(" ");COPY_TEXT(FAO("!%D",0));count:=count+1;
XENDIF;ENDIF;MOVE_VERTICAL(1);EXITIF MARK(NONE)=END_OF(buf);ENDLOOP;
XIF (count=0) THEN QUIT;ELSE EXIT;ENDIF;
V!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
X!
X$ IF f$SEARCH("''scratchfile';-1").EQS."" THEN GOTO SOMETHING_AMISS
X$ PURGE 'scratchfile' /NoLOG
X$ say "... Moving the modified extract file to folder NEWMAIL_SORTED"
X$ DEFINE/USER_MODE SYS$OUTPUT NL:
X$ DEFINE/USER_MODE new_extract_file 'scratchfile'
X$ DEFINE/USER_MODE mailfile 'mailfile'
X$ MAIL
XSET FILE  new_extract_file
XCOPY/ALL/NOCONFIRM NEWMAIL_SORTED mailfile
XEXIT
X$ DELETE 'scratchfile';* /NoLOG
X$ say ">>> Job Completed -"
V$ say "    Contents of folder NEWMAIL moved to NEWMAIL_SORTED in", sequence, "
XSequence."
X$ say " "
X$FIN:
X$ EXIT 1.OR.'f$VERIFY(v)'
X$NO_NEW_MAIL:
X$ say " "
X$ say "MAILSORTER-I-NONEW% - No entries in NEWMAIL folder."
X$ say " "
X$ IF f$SEARCH(scratchfile).NES."" THEN DELETE/NoLOG 'scratchfile';*
X$ GOTO FIN
X$NO_MAIL_FILE:
X$ say " "
X$ say "MAILSORTER-I-NOMAILFILE% - You don't seem to own a MAIL.MAI file."
X$ say " "
X$ GOTO FIN
X$BAD_PAR:
X$ say " "
X$ say "??? Param ''P1' invalid."
X$ say "    Specify FROM: or SUBJECT:"
X$ say " "
X$ GOTO FIN
X$SOMETHING_FISHY:
X$ say " "
V$ say "??? Modified new version of mail extract file ", scratchfile, " not crea
Xted -"
V$ say "    check file current version ", scratchfile, " for possible problems.
X  "
X$ say " "
X$ GOTO FIN
X$HELP: TYPE /PAGE SYS$INPUT
X
XMAILSORTER
X**********
X
XRoutine to sort the entries in the NEWMAIL folder into either
X   Subject: sequence (regardless of origin)
Xor Subject-within-From: sequence.
X
X
XHave you ever had  lots of NEWMAIL entries  and been a bit cheesed off
Xhaving to skip around and about the MAIL Menu  to entries with related
XSubject: headers ???    Yeah, its a pain AND a distraction, isn't it !.
X
XWell, this routine should make things easier -
X albeit in a   S L O W   and rather sledgehammer fashion.
X  (C'mon DEC, when can we have DIR/SEQ=xxx as a MAIL sub-command ???).
X
XThis routine moves entries in the NEWMAIL folder to folder NEWMAIL_SORTED.
XBecause of  the  snails-pace "speed"  of the current version, it probably
Xisn't worth bothering with  unless you have 30+ or so  mail items waiting
Xfor you.  It is VERY useful when dealing with items received from Mailing
XLists on BITNET etc.
X
X
X
XTo use
X`009@LIB:MAILSORTER seq
X`009`009`009`009where  seq is either SUBJECT: or FROM:
X`009`009`009`009(default = FROM: - ie subject-within-From:)
X`009`009`009`009Abbreviation is permitted - ie S or SU etc.
X then
X`009MAIL
X`009 SELECT NEWMAIL_SORTED
X`009 etc.
X
XDon't forget that NEWMAIL_SORTED entries are NOT automatically moved
Xto the MAIL folder when you read them...
XALSO - the original date&time at the top of each mail item is changed
Xto the current date&time so as to force MAIL to display things in the
Xrequired sequence (kludgy, huh !).
X
XShould you change your mind and decide you want to have mail items in
Xthe alternative sequence the you can RE-sort everything as follows:
X
X`009MAIL
X`009 SELECT NEWMAIL_SORTED
X`009 MOVE/ALL NEWMAIL
X`009 EXIT
X`009@LIB:MAILSORTER othersequencecode
X`009 etc
X
X
XTo make life easier, put the following line in your LOGIN.COM -
X`009DEFINE  mail$init SYS$LOGIN:MAILKEYS.INI
X
XThen create file SYS$LOGIN:MAILKEYS.INI containing the following
X(unless you habitually use PF2, 3, 4 for something specific).
X`009DEFINE/KEY /ECHO/NOLOG             PF2 "DELETE "
X`009DEFINE/KEY /ECHO/NOLOG             PF3 "FILE "
X`009DEFINE/KEY /TERMINATE/ECHO/NOLOG   PF4 "FILE MAIL"
X
XThus, to move an item in folder NEWMAIL_SORTED to folder MAIL,
Xyou merely press PF4.
X
X$ GOTO FIN
$ GoSub Convert_File
$ Exit
