From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 31-OCT-1989 18:57
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: Help on NOTES

Message-Id:  <8910312134.AA28202@crdgw1.ge.com>
Received: From MITVMA.MIT.EDU by CRVAX.SRI.COM with TCP; Tue, 31 OCT 89 13:01:30 PDT
Received: from MITVMA.MIT.EDU by mitvma.mit.edu (IBM VM SMTP R1.2.1MX) with BSMTP id 3599; Tue, 31 Oct 89 16:01:36 EST
Received: from BCVMS.BITNET (LAURI) by MITVMA.MIT.EDU (Mailer R2.03B) with
 BSMTP id 3307; Tue, 31 Oct 89 16:01:35 EST
Date:     Tue, 31 Oct 89 16:00 EST
From: <LAURI%BCVMS.BITNET@mitvma.mit.edu>
Subject:  Re: Help on NOTES
To: info-vax@kl.sri.com
X-Original-To:  info-vax@kl.sri.com, LAURI


I wrote a DCL procedure which operates in conjunction with the DELIVER
feature in PMDF (we don't have all of PMDF installed) to automatically process
all incoming LISTSERV mail and submit it to corresponding VAXNOTES
conferences.  It's been running for a few months now with very little
problem.  Some things to note:

        1.  The account you choose to run this must subscribe to all
            desired LISTSERVs.
        2.  That account must have an entry in its MAIL.DELIVERY
            file to invoke the following procedure whenever new mail
            arrives.
        3.  Any non-LISTSERV mail for that account will generate an
            error in the error log.
        4.  A file with all LISTSERVs valid for your site must be created
            and maintained.

I've also developed a menu system for easier maintenance of all VAXnotes-
LISTSERV conferences.  It allows you to set up new conferences, delete
conferences, "archive" conferences, put up messages for VAXnotes users
to notify them of changes, browse log files, and process any messages
which have caused errors.  This part still has a few bugs but is
pretty useful as is so let me know if you're interested in that code
and I'll send it to you too.

                                                Lauri Doniger
                                                Boston College
                                                VAX Systems Programmer
                                                BITNET: lauri@bcvms

------------------------------------------------------------------------
$! AUTO-NOTES.COM
$
$! Author:  Lauri S. Doniger
$!
$! This procedure extracts header information from incoming mail
$! messages and inserts each message in its corresponding VAXNOTES
$! conference.
$
$ ON ERROR THEN GOTO UNKNOWN_ERROR
$
$ SENDER = "NONE"       ! No SENDER information yet
$ TOPIC = "NONE"        ! No SUBJECT information yet
$
$! This is the log file to keep track of all activity.
$ DATE_AND_TIME = F$TIME()
$ DATE = F$EXTRACT(0,11,"''DATE_AND_TIME'")
$ TIME = F$EXTRACT(12,8,"''DATE_AND_TIME'")
$ LOG_FILE = "STAFF_DISK:[BBOARDS.LOGS]AUTO-NOTES.LOG"
$! Create one if it doesn't exist already.
$ IF F$SEARCH("''LOG_FILE'") .EQS. ""
$   THEN
$       OPEN/WRITE/ERROR=LOG_FILE_ERROR L_FILE 'LOG_FILE'
$       CLOSE L_FILE
$   ENDIF
$
$! Create new one daily for easier maintenance.
$ FDATE = F$EXTRACT(0,11,F$FILE_ATTRIBUTES("''LOG_FILE'","CDT"))
$ IF FDATE .NES. DATE
$   THEN
$       OPEN/WRITE L_FILE 'LOG_FILE'
$       CLOSE L_FILE
$   ENDIF
$
$! This is the command file which actually submits the message to
$! the VAXNOTES conference.
$ BRACKET_POS = F$LOCATE("]","''MESSAGE_FILE'")
$ COM_FILE = F$EXTRACT('BRACKET_POS+1,F$LENGTH("''MESSAGE_FILE'")-'BRACKET_POS,"
''MESSAGE_FILE'")
$ COM_FILE = "STAFF_DISK:[BBOARDS.COMS]SUBMIT" + -
        F$EXTRACT(4,F$LOCATE(".","''COM_FILE'")-4,"''COM_FILE'")+".COM"
$
$! This is the file which contains the list of valid LISTSERVs.
$ LISTSERV_LIST = "STAFF_DISK:[BBOARDS.DATA]LISTSERV.LIST"
$
$! First, find out which bulletin board this message came from.
$! Then, find out what the subject: field is.  This field will be
$! used as the title for the VAXNOTES topic.
$ OPEN/READ/ERROR=MESSAGE_FILE_ERROR MAIL_FILE 'MESSAGE_FILE'
$READ_LOOP:
$ READ/END_OF_FILE=NOT_FOUND MAIL_FILE MESSAGE_LINE
$ IF F$LOCATE("Sender:",MESSAGE_LINE) .NE. F$LENGTH(MESSAGE_LINE)
$   THEN
$       OPEN/READ/ERROR=LISTSERV_FILE_ERROR L_FILE 'LISTSERV_LIST'
$READ_L_FILE:
$       READ/END_OF_FILE=NO_SENDER L_FILE L_LINE
$       LENG = F$LENGTH(L_LINE)
$       BLANK = F$LOCATE(" ",L_LINE)
$       L_NAME = F$EXTRACT(0,BLANK,L_LINE)
$       L_ADDR = F$EXTRACT(BLANK+1,LENG-BLANK,L_LINE)
$       IF F$LOCATE("''L_ADDR'",MESSAGE_LINE) .NE. F$LENGTH(MESSAGE_LINE)
$       THEN
$               BBOARD = "''L_NAME'"
$               SENDER = "FOUND"
$               CLOSE L_FILE
$       ELSE
$               GOTO READ_L_FILE
$       ENDIF
$   ENDIF
$
$ IF F$LOCATE("Subject:",MESSAGE_LINE) .NE. F$LENGTH(MESSAGE_LINE)
$   THEN
$       SUBJECT = F$EXTRACT(F$LOCATE(":",MESSAGE_LINE)+7,40,MESSAGE_LINE)
$       TOPIC = "FOUND"
$   ENDIF
$
$ IF SENDER .EQS. "FOUND"  .AND. TOPIC .EQS. "FOUND"
$   THEN
$       CLOSE MAIL_FILE
$       GOTO PROCESS_MESSAGE
$   ENDIF
$ GOTO READ_LOOP
$
$NOT_FOUND:
$NO_SENDER:
$ IF SENDER .NES. "FOUND"
$   THEN
$       CLOSE L_FILE
$       ERROR = "SENDER_NOT_FOUND"
$       GOTO ERROR_HANDLER
$   ENDIF
$
$NO_TOPIC:
$ IF TOPIC .NES. "FOUND"
$   THEN
$       CLOSE MAIL_FILE
$       CLOSE L_FILE
$       TOPIC = ""
$!      ERROR = "TOPIC_NOT_FOUND"
$!      GOTO ERROR_HANDLER
$   ENDIF
$
$PROCESS_MESSAGE:
$! Finally, insert the message in the conference.  To do this,
$! we must create a command procedure and then spawn it.  If successful,
$! we must delete the file containing the message before we exit, so
$! we don't process it again.
$ OPEN/WRITE/ERROR=COM_ERROR OUT_FILE 'COM_FILE'
$ WRITE OUT_FILE "notes "
$ WRITE OUT_FILE ""
$ WRITE OUT_FILE "open ''BBOARD'"
$ WRITE OUT_FILE "set moderator"
$ WRITE OUT_FILE "write ''MESSAGE_FILE' /noedit"
$ WRITE OUT_FILE "''SUBJECT'"
$ WRITE OUT_FILE "$ if $status"
$ WRITE OUT_FILE "$ then"
$ WRITE OUT_FILE "$     open/append/share l_file ''LOG_FILE'"
$ WRITE OUT_FILE "$     write l_file ""''TIME': ''MESSAGE_FILE'""
$ WRITE OUT_FILE "$     write l_file "" written to conference ''BBOARD'.""
$ WRITE OUT_FILE "$     close l_file"
$ WRITE OUT_FILE "$ else"
$ WRITE OUT_FILE "$     open/append/share l_file ''ERROR_LOG'"
$ WRITE OUT_FILE "$     write l_file ""''DATE_AND_TIME': error encountered inser
ting ''MESSAGE_FILE' in conference ''BBOARD'.""
$ WRITE OUT_FILE "$     close l_file"
$ WRITE OUT_FILE "$ endif"
$ WRITE OUT_FILE "$ exit"
$ CLOSE OUT_FILE
$ COM_FILE = F$SEARCH("''COM_FILE'")
$ @'COM_FILE'
$ DELETE 'COM_FILE'
$ EXIT
$
$LOG_FILE_ERROR:
$ ERROR = "LOG_FILE"
$ GOTO ERROR_HANDLER
$
$MESSAGE_FILE_ERROR:
$ ERROR = "MESSAGE_FILE"
$ GOTO ERROR_HANDLER
$
$LISTSERV_FILE_ERROR:
$ ERROR = "LISTSERV_FILE"
$ GOTO ERROR_HANDLER
$
$COM_ERROR:
$ ERROR = "NO_COMMAND_FILE"
$ GOTO ERROR_HANDLER
$
$UNKNOWN_ERROR:
$ ERROR_MESSAGE = F$MESSAGE(''$STATUS')
$ ERROR = "UNKNOWN"
$
$ERROR_HANDLER:
$! Create a separate log file for errors.
$ ERROR_LOG = "STAFF_DISK:[BBOARDS.LOGS]AUTO-NOTES.ERR"
$ IF F$SEARCH("''ERROR_LOG'") .EQS. ""
$   THEN
$       OPEN/WRITE L_FILE 'ERROR_LOG'
$       CLOSE L_FILE
$   ENDIF
$
$! Create new one daily for easier error checking.
$ FDATE = F$EXTRACT(0,11,F$FILE_ATTRIBUTES("''ERROR_LOG'","CDT"))
$ IF FDATE .NES. DATE
$   THEN
$       OPEN/WRITE L_FILE 'ERROR_LOG'
$       CLOSE L_FILE
$   ENDIF
$
$! We are going to rename every message file that causes a fatal problem.
$ ERROR_FILE = F$EXTRACT(0,F$LOCATE(".","''MESSAGE_FILE'"),"''MESSAGE_FILE'") +
".ERR"
$
$ OPEN/APPEND/SHARE L_FILE 'ERROR_LOG'
$ WRITE L_FILE "''DATE_AND_TIME':  ''MESSAGE_FILE'"
$ IF ERROR .EQS. "SENDER_NOT_FOUND" THEN WRITE L_FILE -
        "       Missing SENDER info ... exiting."
$ IF ERROR .EQS. "INVALID_CONFERENCE" THEN WRITE L_FILE -
        "       Invalid conference name (''BBOARD') ... exiting."
$ IF ERROR .EQS. "NO_COMMAND_FILE" THEN WRITE L_FILE -
        "       Could not open command file ... exiting."
$ IF ERROR .EQS. "LOG_FILE" THEN WRITE L_FILE -
        "       Could not open log file ... exiting."
$ IF ERROR .EQS. "MESSAGE_FILE" THEN WRITE L_FILE -
        "       Could not open message file ... exiting."
$ IF ERROR .EQS. "LISTSERV_FILE" THEN WRITE L_FILE -
        "       Could not open LISTSERV.LIST file ... exiting."
$! IF ERROR .EQS. "TOPIC_NOT_FOUND"
$!   THEN
$!      WRITE L_FILE "  Missing TOPIC info ... continuing."
$!      CLOSE L_FILE
$!      GOTO FOUND_INFO
$!   ENDIF
$ IF ERROR .EQS. "UNKNOWN"
$   THEN
$       WRITE L_FILE "  Unknown error encountered ... exiting."
$       WRITE L_FILE "''ERROR_MESSAGE'"
$   ENDIF
$ CLOSE L_FILE
$ RENAME 'MESSAGE_FILE' 'ERROR_FILE'
$ EXIT
------------------------------------------------------------------------

