;+----------------------------------------------------------------------------+
;|  CH1QMAIL.ASP created August 12, 1989                                      |
;|  Copyright 1989,1990 (C) Marty Acuff                                       |
;|                                                                            |
;|  For automated Qmail retrieval, and batch Zmodem downloads. This script    |
;|  file is intended for use with Procomm Plus.                               |
;|                                                                            |
;+----------------------------------------------------------------------------+
;
;        ------------------=[ Revision History ]=--------------------
;
;	June 11, 1989   the hack begins...
;	December 2, 1989 fixed user abort exit after Mdialing. Now goes to Main
;		Menu.
;	December 17, 1989 fixed WAITFOR during Auto Log Off to accommodate some
;		nodes that skip the ending "Thank you"...
;	December 30, 1989 fixed user abort exit from Mdialing to initialize all
;		variables before return to Main Menu. Corrects problem of current time
;		being dropped into download directory varible in edit config menu.
;	January 13, 1990 Added an alarm if CH1QMAIL stays online after it has
;		completed (Auto Logoff is set to N). This is to alert the user that
;		their attendance is required.
;	March 1, 1990 Changed LF.TXT filename to CH1QMAIL.LF to avoid accidental
;		file deletion. Converted CH1QMAIL.ASP to operate with Door 13, 
;		Qmail 3.0 door, marking the imminent demise of the old Qmail door.
;		Modifyed screen colors to display properly for monochrome users.
;
;        ------------=[ Directory & Files Organization ]=------------
;
;	All user system information is stored in CH1QMAIL.CFG. If config file
;	is not found, defaults will be used and config file will be created.
; 
;
GOTO OPENCFG	; initialize variables from CH1QMAIL.CFG

;        -----------------=[ LEVEL 3 SUBROUTINES ]=-------------------

;        -------------------------------------------------------------
STRIPLF:				; subroutine strips LF (ASCII #10, aka ^J)
						; S9 = holds the string to be stripped
						; S8 = is used as a temporary search variable, used in
						;      this subroutine. On exit from subroutine, S8 is
						;      set to " ".
						; N9 = is a place counter, and will be used in this
						;      subroutine. On exit from subroutine, N9 is
						;      set to 0.
   STRCAT S9 "*"
   INIT N9 0
   STLOOP:
      SUBSTR S8 S9 N9 1
      FIND S8 "*"
      IF FOUND
         DEC N9
         SUBSTR S9 S9 0 N9
         INIT N9 0
         ASSIGN S8 " "
         RETURN
      ENDIF
      INC N9
      GOTO STLOOP
RETURN

;        -------------------------------------------------------------
ADDLF:							; concatenates a Line Feed (^J) to S9
	FOPENI "CH1QMAIL.LF" TEXT	; CH1QMAIL.LF contains a CR/LF pair - that's all!
	FGETC S9					; read a LF from input file
	FPUTC S9					; and put it in the output file.
	FCLOSEI						; close the input file
RETURN

;        -------------------------------------------------------------
DLMVSUB:						; extract file name substring from record
	SUBSTR S9 S7 N9 1			; take one character from word
	FIND S9 "#"					; look for occurrence of "#"
	IF NOT FOUND
		INC N9					; increment counter and check next character
		GOTO DLMVSUB
	ENDIF
	DEC N9						; back up word "slice" counter one space
	SUBSTR S9 S7 0 N9			; take file name substring from record
RETURN

;        -------------------------------------------------------------
QWKFILE:						; find a unique qwk file name, given:
								; S1 = QWK path name
								; S8 = file name prefix
								; S9 = the complete file name created
								; N7 = year  (for building prefix)
								; N8 = month (for building prefix)
								; N9 = day   (for building prefix)
DATE S9						; put today's date into S9
SUBSTR S8 S9 6 2			; extract year
ATOI S8 N7					; store in numeric variable
SUBSTR S8 S9 0 2			; extract month
ATOI S8 N8					; store in numeric variable
SUBSTR S8 S9 3 2			; extract day
ATOI S8 N9					; store in numeric variable
STRFMT S8 "%2.2u%2.2u%2.2u" N7 N8 N9			; format the file name prefix
							; N9 = file counter
INIT N9 1					; initialize counter
QWKFILE1:
	STRFMT S9 "%s\%s%2.2u.QWK" S1 S8 N9
	ISFILE S9					; test for existing file
	IF SUCCESS					; if the file already exists, then
		INC N9					; increment the counter
		IF GT N9 99				; cancel qwk if N9 > 99
			ASSIGN S9 "*"		; can't create the file. Erase S9
			BOX 10 08 14 72 078	; make a window for message
			FATSAY 12 10 079 "Too many qwk files with %s prefix. File not renamed!" S8
			SOUND 1000 30		; get user's attention
			PAUSE 5				; allow user a moment to read message
			GOTO QWKFILE2		; skip past and get out.
		ENDIF
		GOTO QWKFILE1			; try again
	ENDIF
QWKFILE2:
FIND S9 "*"
IF NOT FOUND
	STRFMT S8 "COPY %s\CHANNEL1.QWK %s" S1 S9	; create DOS command line
	DOS S8						; execute the command
	ISFILE S9					; if file copied okay, delete CHANNEL1.QWK
	IF SUCCESS
		STRFMT S8 "DEL %s\CHANNEL1.QWK" S1
		DOS S8
		STRFMT S8 "## CHANNEL1.QWK renamed to %s   " S9
		MESSAGE " "
		MESSAGE S8
	ELSE
		MESSAGE " "
		MESSAGE "## Couldn't rename CHANNEL1.QWK. DANGER OF OVERWRITE!" S9
		ALARM 3
	ENDIF
ENDIF
RETURN

;        -------------------------------------------------------------
REPFILE:						; find a unique rep file name, given:
								; S2 = REP path name
								; S8 = file name prefix
								; S9 = the complete file name created
								; N7 = year  (for building prefix)
								; N8 = month (for building prefix)
								; N9 = day   (for building prefix)
DATE S9						; put today's date into S9
SUBSTR S8 S9 6 2			; extract year
ATOI S8 N7					; store in numeric variable
SUBSTR S8 S9 0 2			; extract month
ATOI S8 N8					; store in numeric variable
SUBSTR S8 S9 3 2			; extract day
ATOI S8 N9					; store in numeric variable
STRFMT S8 "%2.2u%2.2u%2.2u" N7 N8 N9			; format the file name prefix
							; N9 = file counter
INIT N9 1					; initialize counter
REPFILE1:
	STRFMT S9 "%s\%s%2.2u.REP" S2 S8 N9
	ISFILE S9					; test for existing file
	IF SUCCESS					; if the file already exists, then
		INC N9					; increment the counter
		IF GT N9 99				; cancel rep if N9 > 99
			ASSIGN S9 "*"		; can't create the file. Erase S9
			BOX 10 08 14 72 078	; make a window for message
			FATSAY 12 10 079 "Too many rep files with %s prefix. File not renamed!" S8
			SOUND 1000 30		; get user's attention
			PAUSE 5				; allow user a moment to read message
			BOX 10 08 14 72 119	; erase message window
			GOTO REPFILE2		; skip past and get out.
		ENDIF
		GOTO REPFILE1			; try again
	ENDIF
REPFILE2:
FIND S9 "*"
IF NOT FOUND
	STRFMT S8 "COPY %s\CHANNEL1.REP %s" S2 S9	; create DOS command line
	DOS S8						; execute the command
	ISFILE S9					; if file copied okay, delete CHANNEL1.REP
	IF SUCCESS
		STRFMT S8 "DEL %s\CHANNEL1.REP" S2
		DOS S8
		STRFMT S8 "## CHANNEL1.REP renamed to %s   " S9
		MESSAGE " "
		MESSAGE S8
	ELSE
		MESSAGE " "
		MESSAGE "## Couldn't rename CHANNEL1.REP. DANGER OF OVERWRITE!" S9
		ALARM 3
	ENDIF
ENDIF
RETURN

;        -------------------------------------------------------------
DLWRITE:						; write file name to CH1DLOAD.LST with contents
								;  of S9.
	INC N5						; increment the file counter
	FPUTS S9					; write file name to CH1DLOAD.LST
	FPUTC S6					; write a Line Feed to CH1DLOAD.LST
RETURN

;        -----------------=[ LEVEL 2 SUBROUTINES ]=-------------------

;        -------------------------------------------------------------
NULLCHK:		; if string is null, set S9 = "#null#"
	SWITCH S9
		CASE _NULL
			ASSIGN S9 "#null#"
		ENDCASE
		DEFAULT
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
NULLGET:			; gets (temporary) run-time value from user
;	BOX 00 00 23 79 119			; erase the screen
	BOX 09 10 14 70 062			; draw a message window
	ATSAY 10 12 062 "Before you can proceed, you must complete the value for:"
	ATSAY 11 20 063 S9
	NULLGET1:
	ATGET 12 20 031 40 S9
	ATSAY 13 32 062 "Okay? (Y/N) [ ]"
	NULLGET2:
	LOCATE 13 45
	KEYGET S8
	SWITCH S8
		CASE "Y"
			BOX 09 10 14 70 119	; erase prompt box
		ENDCASE
		CASE "N"
			ATSAY 13 11 062 "                                                          "
			GOTO NULLGET1
		ENDCASE
		DEFAULT
			SOUND 440 10
			GOTO NULLGET2
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
NULLNAME: 	; checks for blank in First- Last- Name and Password, substitutes
			; "(blank)"
	FIND S9 "#null#"
	IF FOUND
		ASSIGN S9 "blank"
	ENDIF
RETURN

;        -------------------------------------------------------------
HOLD:		; Puts screen on "hold". User presses any key.
	ATSAY 22 32 206 "[ Press a Key ]"
	HOLDLOOP:
	IF NOT HITKEY
		GOTO HOLDLOOP
	ENDIF
	KFLUSH
	ATSAY 22 32 119 "               "
RETURN

;        -------------------------------------------------------------
SHOWI2YN:		; set S9 to display integer y/n: 1="Y" 0="N"
	SWITCH S9
		CASE "0"
			ASSIGN S9 "N"
		ENDCASE
		CASE "1"
			ASSIGN S9 "Y"
		ENDCASE
		DEFAULT					; if unexpected value is given, show error
			ASSIGN S9 "Error!"
			INIT N5 1			; and set Config change flag
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
SHOWBPS:	; set S9 to display currently configured baudrate
	SWITCH S9
		CASE "3"
			ASSIGN S9 "300"
		ENDCASE
		CASE "12"
			ASSIGN S9 "1200"
		ENDCASE
		CASE "24"
			ASSIGN S9 "2400"
		ENDCASE
		CASE "48"
			ASSIGN S9 "4800"
		ENDCASE
		CASE "96"
			ASSIGN S9 "9600"
		ENDCASE
		CASE "192"
			ASSIGN S9 "19200"
		ENDCASE
		CASE "384"
			ASSIGN S9 "38400"
		ENDCASE
		CASE "576"
			ASSIGN S9 "57600"
		ENDCASE
		CASE "1152"
			ASSIGN S9 "115200"
		ENDCASE
		DEFAULT					; just in case the value got screwed up...
			ASSIGN S9 "1200"
			INIT N0 12
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
FILECFG:	; subroutine to store configuration info to CH1QMAIL.CFG
	FCLOSEO						; close any currently open file
	BOX 00 00 23 79 112			; draw a box on the screen (erase screen)
	ISFILE "CH1QMAIL.CFG"		; does a config file already exist?
	IF SUCCESS					; if so, create a backup file
		BOX 05 17 07 63 042
		ATSAY 06 19 046 "Renaming old CH1QMAIL.CFG to CH1QMAIL.CFB"
		PAUSE 2
		DOS "COPY CH1QMAIL.CFG CH1QMAIL.CFB"
		ISFILE "CH1QMAIL.CFB"	; was backup file actually created?
			IF NOT SUCCESS		; if not, display warning and abort
				BOX 05 17 07 63 119
				BOX 09 04 15 76 078
				ATSAY 11 05 079 "Couldn't Create CH1QMAIL.CFB. You may be out of disk space. Please"
				ATSAY 12 05 079 "check available disk space, and re-start this program. This will"
				ATSAY 13 05 079 "NOT save your current changes. Returning to menu."
				GOSUB HOLD
				RETURN
			ENDIF
	ENDIF
	FOPENO "CH1QMAIL.CFG" TEXT
	IF NOT SUCCESS				; couldn't open new CH1QMAIL.CFG
		BOX 09 05 14 75 078
		ATSAY 11 07 079 "Couldn't open CH1QMAIL.CFG. The file may be marked 'read only'."
		ATSAY 12 07 079 "This will NOT save your current changes. Returning to menu."
		GOSUB HOLD
		RETURN
	ENDIF
	BOX 05 17 07 63 119
	CUROFF
	BOX 10 12 14 68 024
	ATSAY 12 14 031 "Creating a new configuration file. Please stand by."
		FPUTS "Configuration file for CH1QMAIL.ASP version 3.00"
		GOSUB ADDLF
	ITOA N0 S9
		FPUTS S9
		GOSUB ADDLF
	ITOA N1 S9
		FPUTS S9
		GOSUB ADDLF
	ITOA N2 S9
		FPUTS S9
		GOSUB ADDLF
	ITOA N3 S9
		FPUTS S9
		GOSUB ADDLF
	ITOA N4 S9
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S0
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S1
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S2
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S3
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S4
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S5
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S6
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S7
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 S8
		FPUTS S9
		GOSUB ADDLF
	ASSIGN S9 "EOF"
		FPUTS S9
		GOSUB ADDLF
	FCLOSEO
	CURON
	BOX 01 01 22 78 119			; erase screen
RETURN

;        -------------------------------------------------------------
NONULL:		; display a message on screen that #null# is not allowed
	ATSAY 18 01 119 "                                                                            "
	BOX 17 10 20 70 079			; draw a box on screen white on red
	ATSAY 18 11 079 "  Use of '#null#' character sequence is not permitted.  "
	ATSAY 19 32 078 "Press any key."
	KEYGET S9
	BOX 17 10 20 70 119			; erase box from screen
RETURN

;        -------------------------------------------------------------
BAUDSET:		; sets the baudrate from CH1QMAIL.CFG
				; value stored in variable N0 (stored as rate/100)
	ITOA N0 S9
	SWITCH S9
		CASE "3"
			SET BAUDRATE 300
		ENDCASE
		CASE "12"
			SET BAUDRATE 1200
		ENDCASE
		CASE "24"
			SET BAUDRATE 2400
		ENDCASE
		CASE "48"
			SET BAUDRATE 4800
		ENDCASE
		CASE "96"
			SET BAUDRATE 9600
		ENDCASE
		CASE "192"
			SET BAUDRATE 19200
		ENDCASE
		CASE "384"
			SET BAUDRATE 38400
		ENDCASE
		CASE "576"
			SET BAUDRATE 57600
		ENDCASE
		CASE "1152"
			SET BAUDRATE 115200
		ENDCASE
		DEFAULT					; just in case the variable got screwed up!
			SET BAUDRATE 1200
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
LOGFILE:						; find a unique log file name, given:
								; S7 = path name
								; S8 = file name prefix
								; S9 = the complete file name created
								; N7 = year  (for building prefix)
								; N8 = month (for building prefix)
								; N9 = day   (for building prefix)
DATE S9						; put today's date into S9
SUBSTR S8 S9 6 2			; extract year
ATOI S8 N7					; store in numeric variable
SUBSTR S8 S9 0 2			; extract month
ATOI S8 N8					; store in numeric variable
SUBSTR S8 S9 3 2			; extract day
ATOI S8 N9					; store in numeric variable
STRFMT S8 "%2.2u%2.2u%2.2u" N7 N8 N9			; format the file name prefix
							; N9 = file counter
INIT N9 1					; initialize counter
LOGFILE1:
	STRFMT S9 "%s\%s%2.2u.LOG" S7 S8 N9
	ISFILE S9					; test for existing file
	IF SUCCESS					; if the file already exists, then
		INC N9					; increment the counter
		IF GT N9 20				; cancel log if N9 > 20
			ASSIGN S9 "*"		; can't create the file. Erase S9
			BOX 10 08 14 72 078	; make a window for message
			FATSAY 12 10 079 "Too many log files with %s prefix. New file not opened!" S8
			SOUND 1000 30		; get user's attention
			PAUSE 5				; allow user a moment to read message
			CLEAR				; erase message window
			GOTO LOGFILE2		; skip past and get out.
		ENDIF
		GOTO LOGFILE1			; try again
	ENDIF
LOGFILE2:
FIND S9 "*"
IF NOT FOUND
	LOG CLOSE
	LOG OPEN S9
	DATE S8
	STRFMT S9 "## Log file open on %s at " S8
	TIME S8 1
	STRCAT S9 S8
	LOCATE 00 00
	MESSAGE S9
ENDIF
RETURN

;        -------------------------------------------------------------
CFGPATH:	; Read the current configuration for paths only
	ASSIGN S0 S4
	ASSIGN S1 S5
	ASSIGN S2 S6
	ASSIGN S3 " "
	ASSIGN S4 " "
	ASSIGN S5 " "
	ASSIGN S6 " "
	ASSIGN S7 " "
	ASSIGN S8 " "
	FOPENI "CH1QMAIL.CFG" TEXT
;	ATSAY 00 12 059 "          Checking CH1QMAIL.CFG version number           "
		FGETS S9				; config file header with version number
		FIND S9 "Configuration file for CH1QMAIL.ASP"
		IF FOUND
			FGETS S9			; baudrate
			FGETS S9			; Qmail transfer flag
			FGETS S9			; Download flag
			FGETS S9			; Auto Log off flag
			FGETS S9			; Log file flag
			FGETS S9			; CHANNEL1 phone number
			FGETS S9			; First Name
			FGETS S9			; Last  Name
			FGETS S9			; Password
			FGETS S9			; PcPlus directory
			FGETS S9			; QWK directory
			FGETS S9			; REP directory
			FGETS S9			; LOG directory info not needed
			FGETS S9			; Download directory
;			ATSAY 00 12 059 "              Checking download directory                "
			GOSUB STRIPLF
			ASSIGN S3 S9
			FGETS S9
			FIND S9 "EOF"
			IF NOT FOUND
				ASSIGN S9 "FAIL"
			ENDIF
			IF EOF
				ASSIGN S9 "FAIL"
			ENDIF
		ELSE
			ASSIGN S9 "FAIL"
		ENDIF
	FCLOSEI
RETURN

;        -------------------------------------------------------------
LOGON:
	WAITFOR " or Enter = No? " 05
	WHEN "Press (Enter) to continue?" "^M"
	TRANSMIT "n q ns^M"
	WAITFOR "our first name? "
	IF NOT WAITFOR
		ASSIGN S9 "FAIL"
		RETURN
	ENDIF
	STRFMT S9 "%s %s^M" S1 S2
	TRANSMIT S9
	WAITFOR "ots will echo)? "
	TRANSMIT S3
	TRANSMIT "^M"
	WAITFOR "Enter = Yes?"
	TRANSMIT "^M"
	WAITFOR "Channel 1 Command?"
	IF NOT WAITFOR
		ASSIGN S9 "FAIL"
	ENDIF
RETURN

;        -------------------------------------------------------------
QMAIL:
	TRANSMIT "DOOR 13^M"
	WAITFOR "Command? " 60
	QMAIL-D:					; download part of Qmail transfer
	STRFMT S7 "%s\CHANNEL1.QWK" S1	; create full pathname for QWK file
	ISFILE S7
	IF SUCCESS
		GOSUB QWKFILE			; rename CHANNEL1.QWK
		FIND S9 "*"
		IF NOT FOUND
			TIME S8 1
			STRFMT S9 "## Renamed old QWK packet at %s" S8
			MESSAGE S9
		ENDIF
	ENDIF
	TRANSMIT "D^M"
	WAITFOR "cket (Y or N)? " 90
	STRFMT S9 "DSZ CON handshake both rz %s " S7	; DOS download command
	TRANSMIT "Y^M"									; accept packet
	WAITFOR "CHANNEL1.QWK now." 60					; transmit prompt
	DOS S9											; execute command
	WAITFOR "Command? " 60		; postpone further processing until prompt
	ISFILE S7					; test successful transfer
	IF SUCCESS					; rename QWK packet if transfer okay
		GOSUB QWKFILE			; rename CHANNEL1.QWK
		FIND S9 "*"
		IF NOT FOUND
			TIME S8 1
			STRFMT S9 "## Renamed QWK mail packet at %s" S8
			MESSAGE S9
		ENDIF
	ENDIF
	QMAIL-U:					; upload CHANNEL1.REP (if available), and
								; rename upon successful transfer
	STRFMT S7 "%s\CHANNEL1.REP" S2	; create full pathname for REP file
	ISFILE S7
	IF SUCCESS
		STRFMT S9 "DSZ CON handshake both sz %s " S7	; DOS upload command
		TRANSMIT "U^M"
		WAITFOR "Ready to receive"
		DOS S9
		WAITFOR "successful" 90
		IF WAITFOR
			WAITFOR "Command? " 20
			GOSUB REPFILE			; rename CHANNEL1.REP
			TIME S8 1
			STRFMT S9 "## Renamed REP mail packet at %s" S8
			MESSAGE S9
		ELSE
			WAITFOR "Command? " 20
			TIME S8 1
			STRFMT S9 "## Problem with upload at %s." S8
			MESSAGE " "
			MESSAGE S9
		ENDIF
	ENDIF
	QMAIL-Q:					; quit the Qmail door
	TRANSMIT "Q^M"				; quit Qmail Door, and return to Main
	WAITFOR "Channel 1 Command?" 60
RETURN

;        -------------------------------------------------------------
ZDOOR:
STRFMT S4 "%s\CH1DLOAD.LST" S3	; create full pathname of download list
ISFILE S4						; look for CH1DLOAD.LST list of files to d/l
IF FAILURE						; if CH1DLOAD.LST exists, start Zdoor session
	GOTO ZDOOR-X
ENDIF
	TRANSMIT "Door 1^M"
	WAITFOR "Command? " 60
	FOPENI S4 TEXT				; read from download list
	IF NOT SUCCESS
		TIME S8 1
		STRFMT S9 "## Couldn't open CH1DLOAD.LST at %s" S8
		MESSAGE " "
		MESSAGE S9
		GOTO ZDOOR-Q
	ENDIF
	STRFMT S7 "DSZ handshake both rz -r %s" S3	; create Zmodem command
	INIT N5 0
ZDOOR-1:						; beginning of Zdoor download loop
	IF GT N5 19
		GOTO ZDOOR-D
	ENDIF
	FGETS S9				; get a file name from list
	IF EOF					; if end of file is encountered, proceed
		GOTO ZDOOR-D
	ENDIF
	FIND S9 "#RECEIVED#"	; if file is marked received, don't d/l again!
	IF FOUND
		GOTO ZDOOR-1		; don't download from this entry
	ENDIF
	FIND S9 "*"				; search for disallowed character "*"
	IF FOUND
		GOTO ZDOOR-1		; don't download from this entry
	ENDIF
	FIND S9 "?"				; search for disallowed character "?"
	IF FOUND
		GOTO ZDOOR-1		; don't download from this entry
	ENDIF
	GOSUB STRIPLF			; strip the Line Feed character from string
	STRFMT S8 "MARK %s ^M" S9 ; create xmit line
	TRANSMIT S8				; send download request to ZDoor
	WAITFOR "Marked for download" 10
	IF WAITFOR
		INC N5
		WAITFOR "ZDoor Command?" 10
	ENDIF
	STRFMT S9 "## Download count [%1.1u] " N5	; make file count string
	MESSAGE " "
	MESSAGE S9
	GOTO ZDOOR-1
ZDOOR-D:						; beginning of Zmodem Batch download
	FCLOSEI						; close CH1DLOAD.LST
	IF GT N5 0						; if N5>0, or if file names were provided
		TRANSMIT "MARK D ^M"
		IF LT N5 20				; if N5<20
			WAITFOR "More filename(s) to download" 40
			IF NOT WAITFOR
				GOTO ZDOOR-Q
			ENDIF
			TRANSMIT "^M"
		ENDIF
		WAITFOR "(Enter = Continue)?" 60
		TRANSMIT "^M"
		WAITFOR "Start your ZModem" 10
		IF WAITFOR
			DOS S7						; shell to DOS and start Zmodem transfer
			WAITFOR "Command? " 480		; allow 8 min. for network delays
		ELSE
			TRANSMIT "^X^X^X^X^X^X^X^X^X^X"		; send an abort sequence, just in case
			ALARM 5	
		ENDIF
	ENDIF
ZDOOR-Q:
	TRANSMIT "Q^M"				; quit ZDoor, and return to Main
	WAITFOR "Channel 1 Command?" 60
ZDOOR-X:						; exit label for ZDoor routine
RETURN

;        -------------------------------------------------------------
DLCHECK:						; checks CH1DLOAD.LST against downloaded files
								; and marks successful downloads "#RECEIVED#"
STRFMT S4 "%s\CH1DLOAD.LST" S3	; create full pathname of download list
STRFMT S5 "%s\CH1DLOAD.BAK" S3	; create full pathname of backup download list
ISFILE S4						; look for CH1DLOAD.LST list of files to d/l
IF FAILURE						; if CH1DLOAD.LST doesn't exist, exit routine
	GOTO DLCHK-X
ENDIF
	STRFMT S9 "COPY %s %s" S4 S5		; command string creates backup
	DOS S9								; execute the command
	FOPENI "CH1QMAIL.LF" TEXT	; CH1QMAIL.LF contains a CR/LF pair - that's all!
	IF SUCCESS					; if file was found,
		FGETC S6				; store a Line Feed in variable from input file
	ELSE						; if file was not found
		MESSAGE " "				; display an error message.
		MESSAGE "## Couldn't open CH1QMAIL.LF. Aborting Download Verification!"
		GOTO DLCHK-Q			; and quit the routine
	ENDIF
	FCLOSEI						; close the input file
	FOPENI S5 TEXT				; open backup file as source for new file
	IF FAILURE
		MESSAGE "## Couldn't open CH1DLOAD.BAK. Aborting Download Verification"
		GOTO DLCHK-Q
	ENDIF
	FOPENO S4 TEXT				; create an updated CH1DLOAD.LST
	IF FAILURE
		MESSAGE "## Couldn't open CH1DLOAD.LST. Aborting Download Verification"
		MESSAGE "## File may be marked READ ONLY."
		GOTO DLCHK-Q
	ENDIF
	INIT N5 0					; N5 counts valid records updated to CH1DLOAD.LST
DLCHK-1:						; beginning of update loop
	FGETS S7
	IF EOF
		FCLOSEI					; close input  file
		FCLOSEO					; close output file
		IF EQ N5 0				; if record count = 0
			STRFMT S9 "DEL %s" S4	; create DOS command to delete CH1DLOAD.LST
			MESSAGE " "
			MESSAGE "## No files to update to CH1DLOAD.LST-- DELETED. "
			DOS S9				; execute the DOS command
		ENDIF
		GOTO DLCHK-X			; end of file -- close both files
	ENDIF
	FIND S7 "#RECEIVED#"		; if entry was previously marked "#RECEIVED#"
	IF FOUND					; do not write to new file -- self-purging
		GOTO DLCHK-1			; skip this entry -- do not write to new file
	ENDIF
	FIND S7 "*"					; do not allow wildcards in file name specs
	IF FOUND
		GOTO DLCHK-1			; skip this entry -- do not write to new file
	ENDIF
	FIND S7 "?"					; do not allow wildcards in file name specs
	IF FOUND
		GOTO DLCHK-1			; skip this entry -- do not write to new file
	ENDIF
	ASSIGN S9 S7				; store filename in S9, prep for STRIPLF
	GOSUB STRIPLF				; strip the Line Feed from file name.
	ASSIGN S8 S9				; store the file name in S8
	STRFMT S9 "%s\%s" S3 S8
	ISFILE S9					; look for file in download directory
	IF SUCCESS
		GOTO DLCHK-3
	ENDIF
	ISFILE S8					; look for file in current directory
	IF SUCCESS
		GOTO DLCHK-4
	ENDIF
DLCHK-2:						; specified file was not found
	ASSIGN S9 S8
	GOSUB DLWRITE
	GOTO DLCHK-1
DLCHK-3:						; file found in the download directory
	STRFMT S9 "%s #RECEIVED#" S8
	GOSUB DLWRITE
	STRFMT S9 "## Marking %s received." S8
	MESSAGE " "
	MESSAGE S9
	GOTO DLCHK-1
DLCHK-4:						; file found in the current directory
	STRFMT S9 "%s #RECEIVED# (Default)" S8
	GOSUB DLWRITE
	STRFMT S9 "## %s located in default directory." S8
	MESSAGE " "
	MESSAGE S9
	GOTO DLCHK-1
DLCHK-Q:						; end of the routine--quit here
	FCLOSEI						; close input  file
	FCLOSEO						; close output file
DLCHK-X:						; skip the routine if CH1DLOAD.LST not found
RETURN

;        -------------------------------------------------------------
LOGOFF:				; say goodbye to CHANNEL1, and close log if open
	TIME S8 1
	STRFMT S9 "## Logging off at %s." S8
	MESSAGE " "
	MESSAGE S9
	TRANSMIT "G^M"
	WAITFOR "NO CARRIER"
	PAUSE 5
	HANGUP
RETURN

;        -------------------------------------------------------------
DLMOVE:							; For unregistered DSZ users, this moves
								; downloads to the specified directory.
	INIT N7 0					; N7=last file from CH1DLOAD.LST moved
	INIT N8 0					; N8=current file being read
	STRFMT S4 "%s\CH1DLOAD.LST" S3
	ISFILE S4
	IF FAILURE
		GOTO DLMV-X
	ENDIF
	FOPENI S4 TEXT				; open CH1DLOAD.LST for input (read the file)
DLMV-1:
	FGETS S7					; get a record from CH1DLOAD.LST
	IF EOF						; if End Of File is encountered, exit
		FCLOSEI					; (close file first)
		GOTO DLMV-X
	ENDIF
	INC N8						; increment the record counter
	FIND S7 "(Default)" 		; look for files downloaded to default directory
	IF NOT FOUND
		GOTO DLMV-1
	ENDIF
	INIT N9 0					; reset word "slice" counter 
DLMV-2:
	GOSUB DLMVSUB				; extract file name substring from record
	INIT N7 N8					; set file pointer to current record
	ISFILE S9					; look for file in current directory
	IF NOT SUCCESS
		GOTO DLMV-1
	ENDIF
	STRFMT S8 "COPY %s %s\%s" S9 S3 S9
	DOS S8						; copy the file to download directory
	STRFMT S8 "%s\%s" S3 S9
	ISFILE S8					; verify copy success to download directory
	IF FAILURE
		GOTO DLMV-1
	ENDIF
	STRFMT S8 "## <%s> moved to %s (Unregistered DSZ). " S9 S3
	MESSAGE S8
	STRFMT S8 "DEL %s" S9		; if copy was successful, then delete file
	DOS S8						; from current directory
	GOTO DLMV-1
DLMV-X:
RETURN

;        -----------------=[ LEVEL 1 SUBROUTINES ]=-------------------

;        -------------------------------------------------------------
READCFG:	; Read the current configuration file into variables
	FOPENI "CH1QMAIL.CFG" TEXT
	ATSAY 12 12 056 "          Checking CH1QMAIL.CFG version number           "
		FGETS S9				; config file header with version number
		FIND S9 "Configuration file for CH1QMAIL.ASP"
		IF FOUND
			FGETS S9
			ATSAY 12 12 056 "              Checking Baud Rate setting                 "
			GOSUB STRIPLF
			ATOI S9 N0
			FGETS S9
			ATSAY 12 12 056 "              Checking Qmail tranfer flag                "
			GOSUB STRIPLF
			ATOI S9 N1
			FGETS S9
			ATSAY 12 12 056 "                Checking Download flag                   "
			GOSUB STRIPLF
			ATOI S9 N2
			FGETS S9
			ATSAY 12 12 056 "               Checking Auto Logoff flag                 "
			GOSUB STRIPLF
			ATOI S9 N3
			FGETS S9
			ATSAY 12 12 056 "                Checking Log file flag                   "
			GOSUB STRIPLF
			ATOI S9 N4
			FGETS S9
			ATSAY 12 12 056 "            Checking CHANNEL1 phone number               "
			GOSUB STRIPLF
			ASSIGN S0 S9
			FGETS S9
			ATSAY 12 12 056 "                  Checking First Name                    "
			GOSUB STRIPLF
			ASSIGN S1 S9
			FGETS S9
			ATSAY 12 12 056 "                  Checking Last Name                     "
			GOSUB STRIPLF
			ASSIGN S2 S9
			FGETS S9
			ATSAY 12 12 056 "                   Checking Password                     "
			GOSUB STRIPLF
			ASSIGN S3 S9
			FGETS S9
			ATSAY 12 12 056 "            Checking Procomm Plus directory              "
			GOSUB STRIPLF
			ASSIGN S4 S9
			FGETS S9
			ATSAY 12 12 056 "                Checking QWK directory                   "
			GOSUB STRIPLF
			ASSIGN S5 S9
			FGETS S9
			ATSAY 12 12 056 "                Checking REP directory                   "
			GOSUB STRIPLF
			ASSIGN S6 S9
			FGETS S9
			ATSAY 12 12 056 "                Checking LOG directory                   "
			GOSUB STRIPLF
			ASSIGN S7 S9
			FGETS S9
			ATSAY 12 12 056 "              Checking download directory                "
			GOSUB STRIPLF
			ASSIGN S8 S9
			FGETS S9
			FIND S9 "EOF"
			IF NOT FOUND
				ASSIGN S9 "FAIL"
			ENDIF
			IF EOF
				ATSAY 12 12 059 " Premature End of File. Configuration File is incorrect. "
				GOSUB HOLD
				ASSIGN S9 "FAIL"
			ENDIF
		ELSE
			ASSIGN S9 "FAIL"
		ENDIF
	FCLOSEI
RETURN

;        -------------------------------------------------------------
EDITCFG:	; allows user editing of configuration
			; S0 = CHANNEL1 phone number
			; S1 = User's First Name
			; S2 = User's Last  Name
			; S3 = User's Password
			; S4 = PcPlus (& ASP files) directory
			; S5 = QWK files directory
			; S6 = REP files directory
			; S7 = LOG files directory
			; S8 = Download  directory
			; S9 = General user responses
			; N0 = Baudrate (3|12|24|48|96|192|384|576|1152)
			; N1 = Qmail transfer       (1=transfer     0=don't)
			; N2 = Download             (1=transfer     0=don't)
			; N3 = Auto log off         (1=Auto Log Off 0=stay connected)
			; N4 = Log file of session  (1=Open a log   0=don't)
			; N5 = Configuration status (1=changes made 0=no change)
	FIND S9 "FAIL"
	IF NOT FOUND
		INIT N5 0					; reset configuration status flag
	ELSE
		INIT N5 1					; set   configuration status flag
	ENDIF
CFGLOOP1:
	BOX 00 00 23 79 121
	ASSIGN S9 S0
	GOSUB NULLNAME
	FATSAY 01 05 112 "A] CHANNEL 1 Phone number.........<%s>" S9
	ASSIGN S9 S1
	GOSUB NULLNAME
	FATSAY 02 05 112 "B] First Name (for log on)........<%s>" S9
	ASSIGN S9 S2
	GOSUB NULLNAME
	FATSAY 03 05 112 "C] Last  Name (for log on)........<%s>" S9
	ASSIGN S9 S3
	GOSUB NULLNAME
	FATSAY 04 05 112 "D] Password   (for log on)........<%s>" S9
	FATSAY 05 05 112 "E] PCPLUS directory (& ASP).......<%s>" S4
	FATSAY 06 05 112 "F] QWK directory..................<%s>" S5
	FATSAY 07 05 112 "G] REP directory..................<%s>" S6
	FATSAY 08 05 112 "H] LOG directory..................<%s>" S7
	FATSAY 09 05 112 "I] Zmodem Download directory......<%s>" S8
	ITOA N0 S9
	GOSUB SHOWBPS
	FATSAY 10 05 112 "J] Baud Rate...................... %s" S9
	ITOA N1 S9
	GOSUB SHOWI2YN
	FATSAY 11 05 112 "K] Qmail Transfer (Y/N)?.......... %s" S9
	ITOA N2 S9
	GOSUB SHOWI2YN
	FATSAY 12 05 112 "L] Download using CH1DLOAD.LST?... %s" S9
	ITOA N3 S9
	GOSUB SHOWI2YN
	FATSAY 13 05 112 "M] Auto Log off?.................. %s" S9
	ITOA N4 S9
	GOSUB SHOWI2YN
	FATSAY 14 05 112 "N] Log of each session?........... %s" S9
	ATSAY  15 05 124 "Q] Quit configuration."
	
	CFGGET:
	ATSAY  18 08 126 "Please make a selection to change, or Q to quit [   ]    "
	LOCATE 18 58
	KEYGET S9
	SWITCH S9
		CASE "Q"
			ATSAY 18 58 126 S9
			IF EQ N5 1			; if N5=1 (if changes flag is set)
				BOX 11 15 13 65 079
				ATSAY 12 18 079 "Changes have been made. Save them? (Y/N):      "
				BOX 16 04 20 75 059
				ATSAY 17 06 059 "You MUST answer 'Y' if you want CH1QMAIL.ASP to use these settings."
				ATSAY 18 06 059 "The desired settings MUST be saved to the configuration file before"
				ATSAY 19 06 059 "you can use them!"
				SAVECFG:
				LOCATE 12 61
				KEYGET S9
				SWITCH S9
					CASE "N"
						ATSAY 12 61 079 S9
					ENDCASE
					CASE "Y"
						ATSAY 12 61 079 S9
						GOSUB FILECFG
					ENDCASE
					DEFAULT
						SOUND 440 10
						GOTO SAVECFG
					ENDCASE
				ENDSWITCH
			ENDIF
		ENDCASE
		CASE "A"						; edit CHANNEL1 phone number
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-A:
			ATGET  01 40 015 38 S0		; get new value
			FIND S0 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-A
			ENDIF
			ASSIGN S9 S0
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S0 S9
			GOSUB NULLNAME
			ATSAY  01 40 112 "                                      "
			FATSAY 01 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "B"						; edit First Name
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-B:
			ATGET  02 40 015 38 S1		; get new value
			FIND S1 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-B
			ENDIF
			ASSIGN S9 S1
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S1 S9
			GOSUB NULLNAME
			ATSAY  02 40 112 "                                      "
			FATSAY 02 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "C"						; edit Last  Name
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-C:
			ATGET  03 40 015 38 S2		; get new value
			FIND S2 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-C
			ENDIF
			ASSIGN S9 S2
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S2 S9
			GOSUB NULLNAME
			ATSAY  03 40 112 "                                      "
			FATSAY 03 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "D"						; edit Password
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-D:
			ATGET  04 40 015 38 S3		; get new value
			FIND S3 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-D
			ENDIF
			ASSIGN S9 S3
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S3 S9
			GOSUB NULLNAME
			ATSAY  04 40 112 "                                      "
			FATSAY 04 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "E"						; edit PcPlus Directory
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-E:
			ATGET  05 40 015 38 S4		; get new value
			FIND S4 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-E
			ENDIF
			ASSIGN S9 S4
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S4 S9
			GOSUB NULLNAME
			ATSAY  05 40 112 "                                      "
			FATSAY 05 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "F"						; edit QWK Directory
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-F:
			ATGET  06 40 015 38 S5		; get new value
			FIND S5 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-F
			ENDIF
			ASSIGN S9 S5
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S5 S9
			GOSUB NULLNAME
			ATSAY  06 40 112 "                                      "
			FATSAY 06 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "G"						; edit REP Directory
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-G:
			ATGET  07 40 015 38 S6		; get new value
			FIND S6 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-G
			ENDIF
			ASSIGN S9 S6
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S6 S9
			GOSUB NULLNAME
			ATSAY  07 40 112 "                                      "
			FATSAY 07 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "H"						; edit LOG Directory
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-H:
			ATGET  08 40 015 38 S7		; get new value
			FIND S7 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-H
			ENDIF
			ASSIGN S9 S7
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S7 S9
			GOSUB NULLNAME
			ATSAY  08 40 112 "                                      "
			FATSAY 08 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "I"						; edit Download Directory
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-I:
			ATGET  09 40 015 38 S8		; get new value
			FIND S8 "#null#"
			IF FOUND
				GOSUB NONULL
				GOTO CFG-I
			ENDIF
			ASSIGN S9 S8
			GOSUB NULLCHK				; check entry for null value
			ASSIGN S8 S9
			GOSUB NULLNAME
			ATSAY  09 40 112 "                                      "
			FATSAY 09 40 112 "%s>" S9
			INIT N5 1					; set cfg status flag
			GOTO CFGGET
		ENDCASE
		CASE "J"						; edit Baudrate
			BOX 17 20 22 60 024
			ATSAY 17 33 029 "[ BAUD RATE ]"
			ATSAY 18 22 024 "1)    300   4)   4800    7)  38400  "
			ATSAY 19 22 024 "2)   1200   5)   9600    8)  57600  "
			ATSAY 20 22 024 "3)   2400   6)  19200    9) 115200  "
			ATSAY 21 23 031 "Make a choice or 0 to abandon [ ]"
			CFG-J:
			LOCATE 21 54
			KEYGET S9
			SWITCH S9
				CASE "0"				; abort change
					BOX 17 20 22 60 119
					GOTO CFGGET
				ENDCASE
				CASE "1"				;    300 baud
					INIT N0 3
					INIT N5 1
				ENDCASE
				CASE "2"				;   1200 baud
					INIT N0 12
					INIT N5 1
				ENDCASE
				CASE "3"				;   2400 baud
					INIT N0 24
					INIT N5 1
				ENDCASE
				CASE "4"				;   4800 baud
					INIT N0 48
					INIT N5 1
				ENDCASE
				CASE "5"				;   9600 baud
					INIT N0 96
					INIT N5 1
				ENDCASE
				CASE "6"				;  19200 baud
					INIT N0 192
					INIT N5 1
				ENDCASE
				CASE "7"				;  38400 baud
					INIT N0 384
					INIT N5 1
				ENDCASE
				CASE "8"				;  57600 baud
					INIT N0 576
					INIT N5 1
				ENDCASE
				CASE "9"				; 115200 baud
					INIT N0 1152
					INIT N5 1
				ENDCASE
				DEFAULT					; wrong key pressed
					SOUND 440 10
					GOTO CFG-J
				ENDCASE
			ENDSWITCH
			BOX 17 20 22 60 119			; erase BAUD RATE window from screen
			ITOA N0 S9					; transfer variables
			GOSUB SHOWBPS				; update S9
			FATSAY 10 40 112 "%s    " S9	; refresh display
			GOTO CFGGET					; on to the next thing
		ENDCASE
		CASE "K"						; edit Qmail transfer
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-K:
			ATSAY 11 40 159 "_"			; make a phony flashing cursor
			LOCATE 11 40
			KEYGET S9					; get new value
			SWITCH S9
				CASE "Y"
					ATSAY 11 40 112 "Y       "
					INIT N1 1
				ENDCASE
				CASE "N"
					ATSAY 11 40 112 "N       "
					INIT N1 0
				ENDCASE
				DEFAULT
					SOUND 440 10
					GOTO CFG-K
				ENDCASE
			ENDSWITCH
			INIT N5 1
			GOTO CFGGET
		ENDCASE
		CASE "L"						; edit Zmodem download
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-L:
			ATSAY 12 40 159 "_"			; make a phony flashing cursor
			LOCATE 12 40
			KEYGET S9					; get new value
			SWITCH S9
				CASE "Y"
					ATSAY 12 40 112 "Y       "
					INIT N2 1
				ENDCASE
				CASE "N"
					ATSAY 12 40 112 "N       "
					INIT N2 0
				ENDCASE
				DEFAULT
					SOUND 440 10
					GOTO CFG-L
				ENDCASE
			ENDSWITCH
			INIT N5 1
			GOTO CFGGET
		ENDCASE
		CASE "M"						; edit Auto Logoff
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-M:
			ATSAY 13 40 159 "_"			; make a phony flashing cursor
			LOCATE 13 40
			KEYGET S9					; get new value
			SWITCH S9
				CASE "Y"
					ATSAY 13 40 112 "Y       "
					INIT N3 1
				ENDCASE
				CASE "N"
					ATSAY 13 40 112 "N       "
					INIT N3 0
				ENDCASE
				DEFAULT
					SOUND 440 10
					GOTO CFG-M
				ENDCASE
			ENDSWITCH
			INIT N5 1
			GOTO CFGGET
		ENDCASE
		CASE "N"						; edit Open Log File
			ATSAY 18 58 126 S9			; echo choice to screen
			CFG-N:
			ATSAY 14 40 159 "_"			; make a phony flashing cursor
			LOCATE 14 40
			KEYGET S9					; get new value
			SWITCH S9
				CASE "Y"
					ATSAY 14 40 112 "Y       "
					INIT N4 1
				ENDCASE
				CASE "N"
					ATSAY 14 40 112 "N       "
					INIT N4 0
				ENDCASE
				DEFAULT
					SOUND 440 10
					GOTO CFG-N
				ENDCASE
			ENDSWITCH
			INIT N5 1
			GOTO CFGGET
		ENDCASE

		DEFAULT					; wrong key pressed
			SOUND 440 10
			GOTO CFGGET
		ENDCASE
	ENDSWITCH
RETURN

;        -------------------------------------------------------------
NOCFG:		; CH1QMAIL.CFG not found; default setting initialized and
			; user is prompted to enter custom values.
	BOX 00 00 23 79 112			; draw a box on entire screen
	ATSAY 01 10 112 "                         Greetings!"
	ATSAY 03 10 112 "No  configuration  file was found, so this  will  start  out"
	ATSAY 04 10 112 "using   the  default  settings  for  your  automated   Qmail"
	ATSAY 05 10 112 "sessions. If you have previously saved a configuration file,"
	ATSAY 06 10 112 "make SURE that it is in the same directory as  CH1QMAIL.ASP,"
	ATSAY 07 10 112 "Procomm Plus, and the directory is the current DOS directory"
	ATSAY 08 10 112 "for this drive."
	ATSAY 10 10 112 "If  you want to check the above, please [Q]uit this  process"
	ATSAY 11 10 112 "at the prompt."

	INIT N0 12					; default baudrate (1200)
	INIT N1 1					; default Qmail transfer (Qmail tranfer okay)
	INIT N2 1					; default Download (download from CH1
	INIT N3 0					; default Auto Log off 1=Log off 0=don't
	INIT N4 1					; default for log file 1=open log 0=don't
	INIT N5 0
	INIT N6 0
	INIT N7 0
	INIT N8 0
	INIT N9 0
	ASSIGN S0 "1,617-354-8873"	; default CHANNEL1 phone number
	ASSIGN S1 "#null#"				; default User First Name (NULL)
	ASSIGN S2 "#null#"				; default User Last Name  (NULL)
	ASSIGN S3 "#null#"				; default User Password   (NULL)
	GOSUB HOLD
	BOX 17 05 19 75 030
	ATSAY 18 08 031 "Excuse me for a moment, while I read your current directory..."
	PAUSE 2
	BOX 00 00 23 79 112			; draw a box on entire screen
	DOS "CD>CH1QMAIL.DIR"		; put current directory pathname in temporary
								; file
		FOPENI "CH1QMAIL.DIR" TEXT
		IF SUCCESS
			FGETS S4			; read current pathname into S4
			FCLOSEI
			DOS "DEL CH1QMAIL.DIR"	; delete temporary file.
			ATSAY 12 24 112 "Please Stand By..."
			ASSIGN S9 S4			; strip ^J and place back in S4
			GOSUB STRIPLF
			ASSIGN S4 S9
		ELSE
			MESSAGE "Can't open 'CH1QMAIL.DIR' to read current directory. Using default."
			ASSIGN S4 "\"
			PAUSE 2
		ENDIF
	ASSIGN S5 S4
	ASSIGN S6 S4
	ASSIGN S7 S4
	ASSIGN S8 S4
RETURN

;        -------------------------------------------------------------
MMENU1:		; main menu (all options)
	ATSAY 10 20 047 "B. Begin   operation."
	ATSAY 11 20 047 "D. Delayed operation."
MMENU2:		; main menu (partial options)
	ATSAY 12 20 047 "E. Edit Configuration File."
	ATSAY 13 20 047 "Q. Quit (Return to PcPlus Terminal Mode)."
RETURN

;        -------------------------------------------------------------
TEMPVAR:			; if S0 - S3 are null, get temporary variables
	FIND S0 "#null#"
	IF FOUND
		ASSIGN S9 "        CHANNEL 1 phone number         "
		GOSUB NULLGET
		ASSIGN S0 S9
	ENDIF
	FIND S1 "#null#"
	IF FOUND
		ASSIGN S9 "           User's First Name           "
		GOSUB NULLGET
		ASSIGN S1 S9
	ENDIF
	FIND S2 "#null#"
	IF FOUND
		ASSIGN S9 "           User's Last  Name           "
		GOSUB NULLGET
		ASSIGN S2 S9
	ENDIF
	FIND S3 "#null#"
	IF FOUND
		ASSIGN S9 "            User's Password            "
		GOSUB NULLGET
		ASSIGN S3 S9
	ENDIF
RETURN

;        -------------------------------------------------------------
CALL:	; start a procedure with CHANNEL1
	GOSUB BAUDSET
	CLEAR						; clear the screen to default colors
	IF EQ N4 1					; if flag is set, open a log file 
		GOSUB LOGFILE
	ENDIF

CALLDIAL:
	MDIAL S0
	IF NOT CONNECTED
		HANGUP
		TIME S8 1
		STRFMT S9 "## Aborted during dial at: %s. No CONNECT. Returning to main menu." S8
		MESSAGE " "
		MESSAGE S9
		IF EQ N4 1
			MESSAGE "## Closing Log file."
			LOG CLOSE
		ENDIF
		GOTO OPENCFG
	ENDIF

	GOSUB LOGON
	FIND S9 "FAIL"
	IF FOUND
		HANGUP
		TIME S8 1
		STRFMT S9 "## Log On failure at %s. Will try again." S8
		MESSAGE " "
		MESSAGE S9
		GOTO CALLDIAL
	ENDIF
	GOSUB CFGPATH				; restore path variables from CH1QMAIL.CFG
	FIND S9 "FAIL"
	IF FOUND
		TIME S8 1
		STRFMT S9 "## Configuration File failure. Discontinuing script file at %s" S8
		MESSAGE " "
		MESSAGE S9
		GOTO CALLOFF
	ENDIF

	IF EQ N1 1					; if flag is set, transfer Qmail packets
		GOSUB QMAIL
	ENDIF

	IF EQ N2 1					; if flag is set, use CH1DLOAD.LST
		GOSUB ZDOOR
	ENDIF

CALLOFF:						; log off (if flag is set)
	IF EQ N3 1					; if flag is set, Auto Logoff
		GOSUB LOGOFF
	ELSE
		ALARM 5					; sound an alarm when through, and staying 
	ENDIF						; online, to alert the user

	IF EQ N2 1					; if download flag is set, update CH1DLOAD.LST
		GOSUB DLCHECK
		GOSUB DLMOVE			; move dl's from default dir to download dir
	ENDIF

	IF EQ N3 1					; if log off flag is set
		IF EQ N4 1				; and if log file flag is set
			MESSAGE " "
			MESSAGE "## Closing Log File Now."
			LOG CLOSE			; close the log file-- otherwise leave alone.
		ENDIF
	ENDIF

CALLEXIT:						; subroutine exit
RETURN

;        -------------------------------------------------------------
GETDELAY:			; subroutine prompts user for time of delayed operation
	BOX 00 00 23 79 119			; clear the screen
	BOX 06 18 17 62 027			; draw a window for menu
	ATSAY 06 27 027 "[ Delayed Operation Menu ]"
	ATSAY 08 20 031 "B. Begin  Delayed Operation"
	ATSAY 09 20 031 "C. Cancel Delay (immediate)"
	ATSAY 10 20 031 "H. Set Hour"
	ATSAY 11 20 031 "M. Set Minute"
	ATSAY 12 20 031 "Q. Quit (Return to Main Menu)"
	ATSAY 15 20 027 "Current setting hh:mm (24hr. time)"
	ATSAY 16 20 027 "Current time          (24hr. time)"
	TIME S8 1
	SUBSTR S9 S8 0 2
	ATOI S9 N7					; N7 stores Hour (00<=N7<=23)
	SUBSTR S9 S8 3 2
	ATOI S9 N8					; N8 stores Minute (00<=N8<=59)
DLYLOOP1:
	TIME S8 1
	SUBSTR S8 S8 0 5
	FATSAY 15 36 027 "%2.2u:%2.2u" N7 N8
	ATSAY 16 36 027 S8
	ATSAY 13 20 030 "   Make a Selection [ ]"
	LOCATE 13 41
	KEYGET S9
	SWITCH S9
		CASE "B"
			ATSAY 13 41 030 "B"
			BOX 00 00 23 79 119	; clear the screen
			BOX 10 11 15 69 027	; draw a window for message
			FATSAY 12 13 031 "Operation delayed until %2.2u:%2.2u (24hr. time)." N7 N8
			ATSAY 12 57 155 "Waiting"
			STRFMT S9 "%2.2u:%2.2u" N7 N8
			DLYLPB1:			; beginning of time compare loop
			TIME S8 1			; get current time
			FATSAY 13 16 031 "The current time is: %3.5s        " S8
			SUBSTR S8 S8 0 5	; extract hh:mm only- prevent mm:ss match
			FIND S8 S9			; test delay time against current time
			IF NOT FOUND
				GOTO DLYLPB1	; repeat the loop until match is found
			ENDIF
			; SUSPEND UNTIL S8 S9
			ATSAY 12 57 030 "Wait Done!"
			ASSIGN S9 "B"
			BOX 10 11 15 69 119	; erase window
			GOTO DLYLOOP2
		ENDCASE
		CASE "C"
			ATSAY 13 41 030 "C"
			GOTO DLYLOOP2
		ENDCASE
		CASE "H"
			ATSAY 13 41 030 "H"
			DLYSETHR:		; set hour of delay
			ATGET 15 36 015 02 S9
			ATOI S9 N7
			IF LT N7 0
				SOUND 440 10
				GOTO DLYSETHR
			ENDIF
			IF GT N7 23
				SOUND 440 10
				GOTO DLYSETHR
			ENDIF
		ENDCASE
		CASE "M"
			ATSAY 13 41 030 "M"
			DLYSETMN:		; set minutes of delay
			ATGET 15 39 015 02 S9
			ATOI S9 N8
			IF LT N8 0
				SOUND 440 10
				GOTO DLYSETMN
			ENDIF
			IF GT N8 59
				SOUND 440 10
				GOTO DLYSETMN
			ENDIF
		ENDCASE
		CASE "Q"
			ATSAY 13 41 030 "Q"
			GOTO DLYLOOP2
		ENDCASE
		DEFAULT
			SOUND 440 10
			GOTO DLYLOOP1
		ENDCASE
	ENDSWITCH
	GOTO DLYLOOP1
DLYLOOP2:						; leave this subroutine
RETURN

;        -----------------=[ INITIALIZE VARIABLES ]=------------------

OPENCFG:
ISFILE "CH1QMAIL.LF"
IF NOT SUCCESS
	CLEAR
	BOX 10 12 14 68 078
	ATSAY 11 14 079 "Can't find CH1QMAIL.LF. File is required for operation of"
	ATSAY 12 14 079 "CH1QMAIL.ASP. See CH1QMAIL.DOC for more information."
	ATSAY 13 14 079 "Aborting CH1QMAIL.ASP now."
	GOSUB HOLD
	CLEAR
	EXIT
ENDIF
ISFILE CH1QMAIL.CFG
IF NOT SUCCESS
	GOSUB NOCFG
	GOSUB EDITCFG
	GOTO OPENCFG
ENDIF
	BOX 00 00 23 79 119
	BOX 04 10 14 70 029
	ATSAY 05 27 030 "CH1QMAIL.ASP Version 3.00"
	ATSAY 06 22 030 "Copyright 1989,1990 (C) Marty Acuff"
	ATSAY 08 12 031 "This is a Procomm Plus script file to automate Qmail 3.0"
	ATSAY 09 12 031 "transfers & ZDoor downloads from CHANNEL1."
	ATSAY 11 29 031 "Reading CH1QMAIL.CFG."
	ATSAY 12 12 049 "                                                         "
	ATSAY 13 25 031 "This will take a few moments."
	CUROFF
	GOSUB READCFG
	CURON
	FIND S9 "FAIL"
	IF FOUND
		INIT N6 0				; reset configuration okay flag
	ELSE
		INIT N6 1				; set   configuration okay flag
	ENDIF

;        ---------------------=[ MAIN PROGRAM ]=----------------------

MAINMENU:
	BOX 00 00 23 79 119
	IF EQ N6 0					; display warning that config file is bad
		BOX 01 10 05 70 079
		ATSAY 02 13 079 "Configuration file is not valid. You may not proceed"
		ATSAY 03 13 079 "with a  session until  you  update the Configuration"
		ATSAY 04 13 079 "with E. Edit Configuration File."
	ENDIF
	BOX 08 17 16 63 046
	ATSAY 08 33 046 "[ Main Menu ]"
	IF EQ N6 1					; if configuration tested okay
		GOSUB MMENU1			; display full menu
		MAIN01:					; trap Main Menu keys (CFG okay)
			ATSAY 15 23 046 "Please make a selection [ ]    "
			LOCATE 15 48
			KEYGET S9
			SWITCH S9
				CASE "B"
					ATSAY 15 48 046 S9
					BOX 08 17 16 63 119		; erase main menu box
					GOSUB TEMPVAR			; fill in the blanks, if necessary
					GOSUB CALL				; ...on with it, already...
				ENDCASE
				CASE "D"
					ATSAY 15 48 046 S9
					BOX 08 17 16 63 119		; erase main menu box
					GOSUB TEMPVAR			; fill in the blanks, if necessary
					GOSUB GETDELAY
					FIND S9 "Q"
					IF FOUND
						INIT N6 1
						GOTO MAINMENU
					ENDIF
					GOSUB CALL	; let the show begin...
				ENDCASE
				CASE "E"
					ATSAY 15 48 046 S9
					GOSUB EDITCFG
					INIT N6 1	; set config okay flag
					GOTO MAINMENU
				ENDCASE
				CASE "Q"
					ATSAY 15 48 046 S9
					CLEAR
					EXIT
				ENDCASE
				DEFAULT
					SOUND 440 15	; honk at user for hitting wrong key
					GOTO MAIN01
				ENDCASE
			ENDSWITCH
	ELSE
		GOSUB MMENU2			; display partial menu
		MAIN02:					; trap Main Menu keys (CFG bad)
			ATSAY 15 23 046 "Please make a selection [ ]    "
			LOCATE 15 48
			KEYGET S9
			SWITCH S9
				CASE "E"
					ATSAY 15 48 046 S9
					GOSUB EDITCFG
					INIT N6 1	; set config okay flag
					GOTO MAINMENU
				ENDCASE
				CASE "Q"
					ATSAY 15 48 046 S9
					CLEAR
					EXIT
				ENDCASE
				DEFAULT
					SOUND 440 15	; honk at user for hitting wrong key
					GOTO MAIN02
				ENDCASE
			ENDSWITCH
	ENDIF

	IF EQ N3 1					; if Auto Logoff flag is set,
		QUIT					; quit to DOS
	ENDIF

DONE:
EXIT
