From:	ADVAX::"mcnc!VM1.NoDak.EDU!FISHER%EDWARDS-2060.AF.MIL" "Lawrence W. Fisher" 22-JUN-1990 16:14:34.38
To:	Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
CC:	
Subj:	MAILEDIT.1 - Part 1 of 2

Received: by ADVAX.DECnet (utk-mail11 v1.5) ; Fri, 22 Jun 90 16:16:56 EDT
Received:  from mcnc by ge-dab.GE.COM (5.61/GE-DAB 1.12) with UUCP
	id AA10373 for everhart; Fri, 22 Jun 90 16:16:31 -0400
Received: from VM1.NoDak.EDU by mcnc.mcnc.org (5.59/MCNC/5-16-88)
	id AA00201; Fri, 22 Jun 90 15:43:36 EDT
Message-Id: <9006221943.AA00201@mcnc.mcnc.org>
Received: from NDSUVM1.BITNET by VM1.NoDak.EDU (IBM VM SMTP R1.2.1MX) with BSMTP id 7786; Fri, 22 Jun 90 14:43:00 CDT
Received: from NDSUVM1.BITNET by NDSUVM1.BITNET (Mailer R2.07) with BSMTP id
 7780; Fri, 22 Jun 90 14:42:57 CDT
Date:         Fri, 22 Jun 90 14:42:43 CDT
Reply-To: "Lawrence W. Fisher" <mcnc!VM1.NoDak.EDU!FISHER%EDWARDS-2060.AF.MIL>
Sender: ANU-NEWS Discussion <ANU-NEWS@VM1.NoDak.EDU>
From: "Lawrence W. Fisher" <mcnc!VM1.NoDak.EDU!FISHER%EDWARDS-2060.AF.MIL>
Subject:      MAILEDIT.1 - Part 1 of 2
X-To:         anu-news@VM1.NODAK.EDU
To: Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
 
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.1-004  3-AUG-1989
$!   On 22-JUN-1990 11:42:28.53   By user FISHER
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 2 PARTS, TO KEEP EACH PART
$!  BELOW 30 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. [.NEWSSTUFF]AAAREADME.TXT;1
$!       2. [.NEWSSTUFF]BUILD.COM;1
$!       3. [.NEWSSTUFF]JUNKMAN.DAT;1
$!       4. [.NEWSSTUFF]MAILEDIT.TPU;1
$!       5. [.NEWSSTUFF]MAILUSERS.DAT;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ if f$getsyi("version") .ges. "V4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete/nolog 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete/nolog 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");
buff:=CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(buff))
;LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(buff));g:=0;LOOP EXITIF MARK(NONE)=END_OF(buff);x:=
ERASE_CHARACTER(1);IF g = 0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x=
"V" THEN APPEND_LINE;MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;
IF x="+" THEN g:=1;ERASE_LINE;ENDIF;ELSE IF x="-" THEN g:=0;ENDIF;ERASE_LINE;
ENDIF;ENDLOOP;p:="`";POSITION(BEGINNING_OF(buff));LOOP r:=SEARCH(p,FORWARD);
EXITIF r=0;POSITION(r);ERASE(r);COPY_TEXT(ASCII(INT(ERASE_CHARACTER(3))));
ENDLOOP;o:=GET_INFO(COMMAND_LINE,"output_file");WRITE_FILE(buff,o);
ENDPROCEDURE;Unpacker;EXIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create/nolog 'f'
X                             MAILEDIT.TPU
X
X       MAILEDIT is a tpu command procedure that is designed to work with
X       a data file, MAILUSERS.DAT, to affix newsgroup headers to
X       internet mail headers that require them.  It uses a rather
X       simplistic method of searching the mail header for some
X       information specific for that newsgroup/mailing list, such as
X       sender name, sender address, reply to address, etc.
X
X       To build the file, use the command @BUILD.
X
X       The format of the MAILUSERS.DAT file is straight forward, but
X       must be maintained to avoid problems.  The odd numbered lines
X       consist of the search critiera for a news group, and the even
X       numbered lines provide the newsgroup name.  The last line must be
X       odd numbered, and consist of the simple word "`091end`093"  Any extra
X       spaces may cause problems.
X
X       To execute the command, use the following:
X
X       $ MAIL
X       MAIL>extract/all/nohead newmail.preedit  ! Strip of VMS header, keep
X       `009`009`009`009`009   `009! the internet header
X       MAIL>exit
X
X       $ edit/tpu/section=sys$disk:mailedit/nodisplay newmail.preedit
X
X       This will produce a file called NEWMAIL.MAIL, which will contain
X       the batch file for use by NEWS. under news you can use`032
X       ADD BATCH/NONET/JUNK NEWMAIL.MAIL;*/DELETE to load the messages
X       into your NEWS system.
X
X
$ CALL UNPACK [.NEWSSTUFF]AAAREADME.TXT;1 1348100691
$ create/nolog 'f'
X$ ! Command procedure to build MAILEDIT tpu section.
X$ EDIT/NOSECTION/NODISPLAY/COMMAND=MAILEDIT
$ CALL UNPACK [.NEWSSTUFF]BUILD.COM;1 757006881
$ create/nolog 'f'
X#!rnews
X`012
XFrom: The garbage man <foobar.ad>
XNewsgroups: whocares
XMessage-Id: <Idontreallyknow>
XDate: 8-Mar-1990
XSubject: Bar
X
Xhumbug
X
$ CALL UNPACK [.NEWSSTUFF]JUNKMAN.DAT;1 907111657
$ create/nolog 'f'
X!`009MAILEDIT.TPU
X!
X!`009Written By:  Lawrence Fisher
X!`009Revised:     21-Jun-1990
X!
X!`009This file may be used and modified freely.
X!
X!`009Command procedure for the purpose of fixing Arpanet mail headers
X!`009to run with ANU news software.
X!
X!`009The program searches through the new mail batch, scans for new
X!`009message headers, and proceeds to place the "From:" string as the
X!`009first line of the header, and inserts a best guess "Newsgroup"
X!`009header if one does not exist.
X
X!       The best guess newsgroup determination is made by searching through
V a
X!       file in the current directory called:
X!
X!                       MAILUSERS.DAT
X!
X!       This file consists of a single line user name entry followed by a
X!       single line newsgroup name; for example:
X!
X!            `009        pcsa-l@miamiu            `032
X!                       INFO-PCSA       `032
X!
X!       there must be one newsgroup line for each user name line, and the`03
V2
X!       very last line of the file should read "`091end`093"
X!
X!       There can be no blank lines in this file.
X
X!`009Execution of the program takes the form:
X!
X!`009`009`009EDIT/SECTION=SYS$DISK:`091`093MAILEDIT input.file/NODISPLAY
X!
X!`009and generates an output file with the name NEWMAIL.MAIL
X
X
X!`009To build it enter the following command:     `032
X!                              `032
X! `009`009        $EDIT/NOSECTION/COMMAND=MAILEDIT/NODISPLAY`032
X
Xprocedure edt$init_variables`009`009! initialize global variables
X!
X! Initialize some variables
X!
X!
X! Create the null variable
X!
Xedt$x_empty := '';
Xedt$x_version : =0;
XTRUE:=1;
XFALSE:=0;
Xendprocedure
X`012
X!
X! INITIALIZATION PROCEDURE
X!
X! This procedure is invoked to initialize the editing session. The buffers
X! are created here.
X!
Xprocedure tpu$init_procedure  ! initialization procedure
XLOCAL`009 temp,
X        output_file_name ,
X`009parsed_output_file_name,
X`009input_file_name_only,
X`009screen_length ;
X
X!
X! Initialize our variables
Xedt$init_variables;
X!
X! Now for the main buffer. Create it from the input file
Xinput_file := get_info(command_line,'file_name');
X!+ if /nocreate is present and file does not exis,then exit
X
Xif (get_info(command_line,'create') = 0)
Xthen
X   ! /nocreate specified
X   temp:=file_parse(input_file);
X   if (file_search(temp)=edt$x_empty )
X       AND
X      (input_file <> edt$x_empty)
X `009then
X`009! exit immediately if file not there
X`009 message('Input file does not exist: '+temp);
X`009exit
X     else
X`009temp:=file_search(edt$x_empty) ! reset
X   endif;
Xendif;
X
Xmain_buffer := create_buffer("MAIN",input_file);
X
X
Xif (get_info(command_line,'read_only') = 1)
Xthen
X    set(no_write,main_buffer);
Xendif;
Xif (get_info(command_line,'output') <> 1)
Xthen
X    set(no_write,main_buffer);
Xelse
X    output_file_name := get_info(command_line,'output_file');
X    if (output_file_name <> edt$x_empty)
X    then
X
X! The output file should be written to the current directory by default
X! unless there is another directory specified in the output_file_name.
X! We need to use sys$disk:`091`093 as the default file specification so that
X! the output file won't be written to the same directory as the input
X! file if an input file directory is explicitly specified on the command lin
Ve.
X! We also DON'T want the node, device or directory of the input file, just
X! the name.
X
X`009input_file_name_only := file_parse
X`009`009`009`009(input_file, edt$x_empty, edt$x_empty, NAME)
X`009`009`009`009 + file_parse
X`009`009`009`009(input_file, edt$x_empty, edt$x_empty, TYPE);
X        parsed_output_file_name := file_parse (output_file_name, 'sys$disk:`
V091`093',
X                                    input_file_name_only);
X`009if parsed_output_file_name <> edt$x_empty then
X`009    set(output_file,main_buffer,parsed_output_file_name);
X
X! Want this buffer to be considered modified so it will be written on exit
X! for use especially with MAIL/EDIT
X
X`009    position (main_buffer);
X`009    split_line; append_line;`009! Marks it as modified
X        endif;
X    endif;
Xendif;
Xset(eob_text,main_buffer,"`091End of MAIN`093");
Xset(system,main_buffer);
X
X!  Go to the current position in the main buffer
X!
Xposition(main_buffer);
Xtpu$local_init;
Xendprocedure
X
X
X
XPROCEDURE EDIT_NEWMAIL
X   LOCAL found_range,
X         infile,
X         outfile,
X         scratch_line,
X         screen_display;
X
X          ON_ERROR
X
X          ENDON_ERROR;
Xscreen_display := create_window (1,24,ON);
Xread_file('junkman.dat');
Xnewsgroups_buffer := create_buffer("NEWSGROUPS_TRANS","MAILUSERS.DAT");
Xloop
X   exitif end_of(current_buffer)=mark(none); ! Exit if at bottom of buffer !
X   from_line := line_begin & 'from';         ! define bounded From: header !
X   a_start := mark(none); `009`009     ! mark where we start from    !
X
X   next_message := search_quietly(page_break,forward);
X`009`009`009`009`009     ! Find the start of next      !
X`009`009`009`009`009     ! Page/message`009`009   !
X   if next_message = 0`009`009`009     ! If we didn't find it then   !
X      then`009`009`009`009     ! Figure on the end of the    !
X         position(end_of(current_buffer));   ! end of the buffer, else     !
X         a_end := mark(none);
X      else
X         position(next_message);`009     ! Place ourselves at the next !
X         a_end := mark(none);`009`009     ! message.`009`009`009   !
X   endif;
X   position(a_start);
X   loop`009`009`009`009`009     ! Find the end of the header  !
X       exitif a_end=mark(none);                                         `032
X       exitif length(current_line)=0;
X       move_vertical(+1);
X   endloop;
X   a_header_end := mark(none);                       `032
X
X   a_range := create_range(a_start,a_header_end,bold); ! define a range for
V it !
X   position(a_start);
X
X   a_from_line := search_quietly(from_line,forward,no_exact,a_range);
X`009`009`009`009`009`009! find out if this is really !
X`009`009`009`009`009`009! a header or not            !
X   if a_from_line <> 0`009`009`009`009! If it is....`009`009     !
X      then
X         position(a_from_line);
X         the_from_line := erase_line;`009`009! Take the From: line`009     !
X         position(a_start);
X         copy_text(the_from_line);`009`009! And stick it at the top of !
X         split_line;`009`009`009`009! the header.`009`009     !
X
X         newsgroup:=search_quietly(line_begin & 'newsgroup',
X                                                   forward,no_exact,a_range)
V;
X`009`009`009`009`009`009! Find out if the newsgroup  !
X`009`009`009`009`009`009! is defined in the header   !
X         if newsgroup = 0`009`009`009! If not.....`009`009     !
X            then`009`009`009`009! try & guess what it is     !
X              position(beginning_of(newsgroups_buffer));
X`009      loop;`009`009`009        ! use loop to allow exits    !
X               position(newsgroups_buffer);     ! point to our translations
V  !
X               newsuser:=current_line;`009`009! get a new user name        !
X               exitif newsuser='`091end`093';`009`009! bail out if end of li
Vst    !
X               move_vertical(+1);`009`009! move down a line`009     !
X               newsgroup_text:=current_line; `009! and get a newsgroup name
V   !
X               move_vertical(+1);`009`009! move down another line     !
X               position(main_buffer);`009`009! get back into the main buff!
X
X               if search_quietly(newsuser,forward,no_exact,a_range) <> 0
X                  then`032
X`009`009`009copy_text('Newsgroups: '); ! Put in 1st half of header!
X`009`009`009copy_text(newsgroup_text); ! insert local nwsgrp name !
X`009`009`009split_line;            `032
X`009`009`009exitif 1;`009`009! bail out of 'loop'`009     !
X`009`009  endif;
X`009      endloop;`009`009`009`009! End of 'loop' structure  !
X              if newsuser='`091end`093'`009`009! If we didn't get a newsgrou
Vp !
X                 then
X`009`009`009position(main_buffer);`009! get back into main buff !
X`009`009`009copy_text('Newsgroups: junk'); ! make one up !
X`009`009`009split_line;
X`009`009  endif;
X         else
X              position(newsgroup); ! Special case !
X              if search_quietly('comp.os.vms',forward,no_exact,a_range) <> 0
X                 then                       ! If comp.os.vms we want INFO-VA
VX !
X                       position(newsgroup);       `032
X                       temp_range := search('comp.os.vms',forward,no_exact);
X                       position(temp_range);
X                       erase(temp_range);
X                       copy_text('info-vax');
X                 endif;
X         endif; ! Need a newsgroup !
X   endif; ! Valid header !
X   position(a_end); `009`009`009`009! end of current message !
X   if end_of(current_buffer) <> mark(none) `009! If we aren't already at end
V !
X      then
X        move_vertical(+1);`009`009`009! move past form feed !
X   endif;
Xendloop; ! end of paging loop !
X
XENDPROCEDURE;               `032
X                  `032
X! At the point of local_init, the main buffer already has the input file !
X! included.`009`009`009`009`009`009`009`009 !
X!`009`009`009`009`009`009`009`009`009 !
X! tpu$local_init is called immeadiately after the tpu$init procedure from!
X! the stripped down EVESECINI we are using.`009`009`009`009 !
X! `009`009`009`009`009`009`009`009`009 !
X! First we perform the editing, then we set the local init flag to one,  !
X! then we write the file NEWMAIL.MAIL and quit out.`009`009`009 !
X
Xprocedure tpu$local_init;
X  edit_newmail;
X  tpu$local_init:=1;
X  write_file(current_buffer,'NEWMAIL.MAIL');
X  quit;
Xendprocedure;
X
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
-------
