From:	SMTP%"MX-List%WKUVX1.BITNET@uu7.psi.com" 24-SEP-1993 20:19:08.25
To:	EVERHART
CC:	
Subj:	RE: Extract mail???How!!???!?!?!

X-Listname: Message Exchange Discussion List <MX-List@WKUVX1.BITNET>
Warnings-To: <>
Errors-To: list-mgr%WKUVX1.BITNET@uu7.psi.com
Sender: list-mgr%WKUVX1.BITNET@uu7.psi.com
Date: Fri, 24 Sep 1993 16:39:31 MDT
From: Dan Wing <dwing@uh01.colorado.edu>
Reply-To: MX-List%WKUVX1.BITNET@uu7.psi.com
To: MX-List@WKUVX1.BITNET
Cc: hathaway@physc1.byu.edu
Message-Id: <00973081.D7CF23A0.8090@uh01.Colorado.EDU>
Subject: RE: Extract mail???How!!???!?!?!

>I am currently using a VAX/VMS mail utility version 5.0.  I would like to be
>able to extract mail files based on their subject line and put them in separate
>files.  I know that I could extract many messages and put them in one file, but
>I would like to keep them separate.

Use this at your own risk; this was written by a friend of mine back in school
and was used when we had 5-6 files we mailed to another account; this .COM file
would automatically retrieve the 5-6 files and retain their filenames and the
username that mailed them (saved lots of work for TAs!).

I also write a simple .COM file that mailed a bunch of files to a username
(like the TA) which included the filename in the subject line.

I use this program now to automatically get files that have been VMS_SHAREd
into 100s of parts and then mailed to me -- this .COM file extracts them
(using the subject line as the filename) and then I use APPEND to stick 'em
all together.  A few months ago a better solution to this was made available
and Hunter announced it on INFO-VAX/comp.os.vms and FSUPDATE, but I haven't
looked at it yet.....

-dan

-----

$ IF P1 .EQS. "?" THEN GOTO _HELP
$ !-------------------------------------------------
$ !     This command procedure will extract files
$ !     from a folder in the MAIL utility and give
$ !     them the name that is in the subject field.
$ !
$ !     Written by Dale Moore, CS Student, Central Washington University,
$ !       February 1990
$ !
$ !
$ !     EDIT 001, 17-APR-1991, Dan Wing,
$ !       added capability to get name from inside of "()"
$ !     EDIT 002, 27-AUG-1991, Dan Wing,
$ !       Added "^f" function, to get filename (without directory or device)
$ !       and use that in the extract operation.
$ !     EDIT 003,  3-AUG-1992, Dan Wing,
$ !       Don't do SET TERM/PAGE, because it messes up DECterms and isn't
$ !       necessary.
$ !
$ !!!!!!
$
$ !
$
$ set nover
$ set on
$ on warning then goto del
$ write sys$output ""
$ !
$ !-------------------------------------------------
$ !
$ !     ENTER FOLDER UNTIL IT IS NOT NULL
$ !
$ file_spec:
$       if p1 .eqs. ""
$       then
$               write sys$output "Please enter the file specification where  ^?
 inserts the
 following into the
$               write sys$output "resulting filename. "
$               write sys$output ""
$               WRITE SYS$OUTPUT "   ^(        uses filename inside of
 parenthesis."      ! edit 001
$               write sys$output "   ^n        inserts the username of the sende
r."
$               write sys$output "   ^s        inserts the subject field."
$               write sys$output "   ^f        inserts the filename of the subje
ct (no
 directory or device)"
$               write sys$output "   ^x        inserts the first x words of the
object field,
 where x = 0-9."
$               write sys$output "   ^d,^m,^y  inserts the day, month, or year t
he message
 was received."
$               write sys$output "   ^#        inserts the message number."
$               write sys$output "   ^u        inserts user defined text based o
n the
 username of the sender."
$               write sys$output "                where there exists a file:
 EXTRACT_USER.DAT"
$               write sys$output "                and each record contains:   us
ername \
 associated text
$               write sys$output ""
$               write sys$output "Examples:    [4mFrom[m           [4mDate[m
 [4mSubject[m"
$               write sys$output "             CS298_12       12-FEB-1990  LAB1
Lisa Jerold
 sorry it is late."
$               write sys$output ""
$               write sys$output "             [4mSpecification[m  [4mResultant
 filename[m"
$               write sys$output "             ^s
 LAB1_LISA_JEROLD_SORRY_IT_IS_LATE."
$               write sys$output "             [.^n]^1.c      [.CS298_12]LAB1.C"
$               write sys$output "             ^u.mod         JEROLD.MOD   where
:  CS298_12 \
 JEROLD"
$               write sys$output ""
$               inquire/nopunc p1 "Please enter file specs:  [^S] "
$               if p1 .eqs. "" then p1 = "^S"
$               write sys$output ""
$               write sys$output ""
$               write sys$output ""
$               write sys$output ""
$               write sys$output ""
$               write sys$output ""
$               write sys$output ""
$               write sys$output "Please enter DIR parameters/qualifiers.  Do no
t use /FULL
 or /EDIT:"
$               write sys$output ""
$               write sys$output "    /BEFORE    /CC_SUBSTRING   /FROM_SUBSTRING
     /FOLDER"
$               write sys$output "    /FULL      /MARKED         /NEW
 /REPLIED"
$               write sys$output "    /SINCE     /START          /SUBJECT_SUBSTR
ING
 /TO_SUBSTRING"
$               write sys$output ""
$               write sys$output "Examples:       NEWMAIL                 ! sele
cts the
        newmail folder."
$               write sys$output "                /SUBJECT_SUBSTRING=LAB  ! sele
cts messages
 that contain LAB."
$               write sys$output ""
$               write sys$output "See MAIL help for more information on DIR para
meters and
 qualifiers."
$               write sys$output ""
$               inquire/nopunct p2 "Please enter DIR parameters/qualifiers (Retu
rn for none):
  "
$               endif
$ !
$       p1 = f$edit (p1, "TRIM, COLLAPSE, UPCASE")
$       if (f$locate ("^U", p1) .ne. f$length (p1))
$       then
$               if (p3 .eqs. "")
$               then
$                       inquire/nopunct p3 "Please enter user data filename  (re
turn =
 EXTRACT_USER.DAT) :  "
$                       if p3 .eqs. "" then p3 = "EXTRACT_USER.DAT"
$                       endif
$               gosub lookup_table
$               endif
$       write sys$output ""
$       write sys$output "Please wait."
$       write sys$output ""
$ !
$ !-------------------------------------------------
$ !
$ !             CREATE 'DIR' listing FOR NEXT COMMAND
$ !
$ !
$       open/write folder tmp_command.tmpztmp
$       write folder "dir ''p2'"
$       close folder
$ !
$ !-------------------------------------------------
$ !
$ !             MAIL> DIR folder /OUTPUT = FILE
$ !
$ !
$!!! removed  3-AUG-1992 by DGW set term/page=255
$ !
$       assign/user tmp_command.tmpztmp sys$input
$       assign/user tmp_directory.tmpztmp sys$output
$ !
$       mail
$ !
$       deassign sys$input
$       deassign sys$output
$ !
$!!! removed  3-AUG-1992 by DGW set term/page=24
$ !
$ !-------------------------------------------------
$ !
$ !             WE KNOW WHAT'S IN THE FOLDER, NOW
$ !             CREATE A FILE THAT CONTAINS ONLY
$ !             THE SUBJECT FIELD.
$ !
$ !
$       open/read input tmp_directory.tmpztmp
$       open/write output tmp_command.tmpztmp
$ !
$ read_again:
$       read/end_of_file=none_selected input line
$       if f$locate("#", line) .eq. f$length(line) then goto read_again
$       read/end_of_file=none_selected input line
$ !
$ !-------------------------------------------------
$ !
$ !             EXTRACT AND WRITE SUBJECT FIELD
$ !
$ !
$ message_number = 1
$ next_input:
$       read/error=done input line
$       file_spec = p1
$ again:
$       carrot = f$locate ("^", file_spec)
$       len  = f$length (file_spec)
$       if carrot .eq. len then goto openmail
$ !
$       tc = f$extract (carrot+1, 1, file_spec)
$       before = f$extract (0, carrot, file_spec)
$       after  = f$extract (carrot+2, len, file_spec)
$       if tc .eqs. "N"
$       then
$               name = f$extract (f$locate ("::", line) + 2, f$length (line), li
ne)
$               name = f$extract (0, f$locate (" ",name), name)
$               file_spec = before + "''name'" + after
$               goto again
$               endif
$       if tc .eqs. "S"
$       then
$               subject = f$edit (f$extract(40,f$length(line)-40,line), "TRIM, C
OMPRESS,
 UPCASE")
$               file_spec = before + "''subject'" + after
$               goto again
$               endif
$! begin edit 002
$       if tc .eqs. "F"
$       then
$               subject = f$edit (f$extract(40,f$length(line)-40,line), "TRIM, C
OMPRESS,
 UPCASE")
$               subject = f$parse(subject,,,"name") + f$parse(subject,,,"type")
$               file_spec = before + "''subject'" + after
$               goto again
$               endif
$! end edit 002
$       if tc .ges. "0" .and. tc .les. "9"
$       then
$               count = f$integer (tc)
$               max = 0
$               subject = ""
$               temp_subject = f$edit (f$extract(40,f$length(line)-40,line), "TR
IM, COMPRESS,
 UPCASE")
$               x_top:
$                       if count .eq. max .or. max .gt. 9 then goto x_done
$                       space = f$locate (" ", temp_subject)
$                       if space .eq. f$length (space) then goto x_done
$                       subject = subject + f$extract (0, space, temp_subject) +
 " "
$                       temp_subject = f$extract (space + 1, f$length (temp_subj
ect), temp_subject)
$                       max = max + 1
$                       goto x_top
$               x_done:
$                       subject = f$edit (subject, "TRIM")
$                       file_spec = before + "''subject'" + after
$                       goto again
$                       endif
$       if tc .eqs. "D"
$       then
$               day = f$extract(27,2,line)
$               file_spec = before + "''day'" + after
$               goto again
$               endif
$       if tc .eqs. "M"
$       then
$               month = f$extract(30,3,line)
$               file_spec = before + "''month'" + after
$               goto again
$               endif
$       if tc .eqs. "Y"
$       then
$               year = f$extract(34,4,line)
$               file_spec = before + "''year'" + after
$               goto again
$               endif
$       if tc .eqs. "U"
$       then
$               name = f$extract (f$locate ("::", line) + 2, f$length (line), li
ne)
$               name = f$extract (0, f$locate (" ",name), name)
$               name = 'name'
$               if $status .eq. %x00038140
$               then
$                       write sys$output "Check user definition file ""''p3'""."
$                       goto del
$                       endif
$               file_spec = "''before'''name'''after'"
$               goto again
$               endif
$       if tc .eqs. "#"
$       then
$               file_spec = "''before'''message_number'''after'"
$               goto again
$               endif
$!+-+ begin edit 001
$       IF TC .EQS. "("
$       THEN
$               DW_TEMPSPEC = F$ELEMENT(1,"(",LINE) - ")"
$               FILE_SPEC = "''BEFORE'" + DW_TEMPSPEC + "''AFTER'"
$               GOTO AGAIN
$               ENDIF
$!+-+ end edit 001
$
$ write sys$output "Error in file specification."
$ goto del
$
$ openmail:
$       file_spec = f$edit (file_spec, "TRIM")
$       gosub make_filename_legal
$       write output file_spec
$       message_number = message_number + 1
$       goto next_input
$ done:
$       close input
$       close output
$ !
$ !-------------------------------------------------
$ !
$ !             NOW CREATE A NEW FILE AND SELECT
$ !             THE RIGHT FOLDER.
$ !
$ !
$       open/write output tmp_read_extract.tmpztmp
$       open/read input tmp_command.tmpztmp
$       write output "dir ''p2'"
$       x = 1
$ !
$ !-------------------------------------------------
$ !
$ !             WRITE A SERIES OF 'READ AND EXTRACT'
$ !
$ !
$ next:
$       read/error=quit input file_spec
$       write output "read ''x'"
$       write output "extract/noheader ''file_spec'"
$       write sys$output "''x'  ''file_spec'"
$       x = x + 1
$       goto next
$ !
$ quit:
$       close output
$       close input
$ !
$ !-------------------------------------------------
$ !
$ !             EXTRACT THEM.
$ !
$ !
$       write sys$output ""
$       inquire/nopunc in "ok? (yes/no): "
$       if f$extract(0,1,in) .eqs. "N"
$       then
$               write sys$output ""
$               write sys$output "Aborting at your request."
$               write sys$output ""
$               goto del
$               endif
$ !
$       write sys$output "Please wait."
$       assign/user tmp_mail.tmpztmp sys$output
$       assign/user tmp_read_extract.tmpztmp sys$input
$       mail
$ !
$ !-------------------------------------------------
$ !
$ !             DELETE TEMPORARY FILES.
$ !
$ !
$ del:
$       set noon
$
$! ++ IF statements added 11-SEP-1990 by DGW.  SET MESSAGE statements
$!    removed
$       if f$trnlnm("input") .nes. "" then close input
$       if f$trnlnm("output") .nes. "" then close output
$       if f$search("tmp_*.tmpztmp") .nes. "" then delete tmp_*.tmpztmp;*
$! ++
$
$       exit
$ !
$ none_selected:
$       write sys$output "No files selected."
$       goto del
$ !------------------------------------------------------
$ make_filename_legal:
$ file_spec_temp = ""
$ check = 1
$ period = 0
$ len = f$length (file_spec) - 1
$ x = 0
$ loop:
$       if x .gt. len then goto make_done
$       c = f$extract (x,1,file_spec)
$       if (c .ges. "A" .and. c .les. "Z")      .or. -
           (c .ges. "0" .and. c .les. "9")      .or. -
           (c .eqs. ":")                        .or. -
           (c .eqs. "$")                        .or. -
           (c .eqs. "-")                        .or. -
           (c .eqs. "_")
$       then
$               file_spec_temp = file_spec_temp + c
$               x = x + 1
$               goto loop
$       else
$               if (c .eqs. "." .and. check .eq. 0)     .or. -
                   (c .eqs. "." .and. period .eq. 0)    .or. -
                   (c .eqs. "[")                        .or. -
                   (c .eqs. "]")
$               then
$                       if c .eqs. "[" then check = 0
$                       if c .eqs. "." then period = 1
$                       if c .eqs. "]"
$                       then
$                               period = 0
$                               check = 1
$                               endif
$                       file_spec_temp = file_spec_temp + c
$               else
$                       file_spec_temp = file_spec_temp + "_"
$                       endif
$               endif
$ x = x + 1
$ goto loop
$ !
$ make_done:
$       file_spec = file_spec_temp
$       return
$ !--------------------------------------------------
$ lookup_table:
$       open/read/error=lookup_error lookup 'p3'
$       lookup_top:
$               read/end=lookup_done lookup lookup_line
$               temp = f$locate ("\", lookup_line)
$               before = f$extract (0, temp, lookup_line)
$               after = f$extract (temp+1, f$length (lookup_line), lookup_line)
$               'before' := 'after
$               show sym 'before'
$               goto lookup_top
$       lookup_done:
$               close lookup
$               return
$       lookup_error:
$               write sys$output "Error, user definition file ""''p3'"" not foun
d."
$       EXIT
$
$_HELP:
$  TYPE SYS$INPUT:

This command procedure will extract files from a folder in the MAIL
utility and give them the name that is in the subject field.

Written by Dale Moore, February 1990

$  EXIT
