string newfil
integer letter=65
proc main
WAITFOR "o?"
TRANSMIT "N Q^M"
WAITFOR "ame?"
;**************************************************************
;Change next line to transmit your name and password
;**************************************************************
TRANSMIT "First Last Password^M"
WAITFOR "?"
TRANSMIT "^M"

        ; Now upload mail if exists, then download and exit.

init N7 23
transmit "^M"
waitquiet 3 forever

CHOOSIT:
transmit "^M"
sound 440 25
box 5 40 7 65 79
atsay 6 42 79 "Get/Send Mail? "
atget 6 60 79 1 s3
strupr s3
switch s3
        case "Y"
                call BLANKIT
                goto MAIL
        case "N"
                call BLANKIT
                exit
        endcase
        default
;**************************************************************
;Change last argument of next statement if using B&W monitor.
;If normal background is black, set it to 112.
;If normal background is white, set it to 7.
;**************************************************************
                box 5 40 7 65 17
                goto CHOOSIT
        endcase
endswitch

MAIL:
;**************************************************************
;Change next line if necessary to subdirectory holding REP file
;**************************************************************
assign s1 "c:\ez2\qwk\d&dpcb.rep" ; subdirectory with QWK files
isfile s1                       ; Check for REP file and upload if there
if success
        transmit "^M"
        pause 1
        transmit "KMail U D Y Q^M"
        waitfor "0000" 60
        if  waitfor             ; Upload REP file
                Sendfile zmodem s1
                IF SUCCESS      ; Delete REP file after good upload
                        delete s1
                endif
                goto GETQWK
        else
                goto GOOF2
        endif
else
        sound 440 50
        message "^M"
        message "No File to Upload.  Download mail packet.^M"
        transmit "KMail D Y Q^M"
endif

GETQWK:                         ;Download mail packet
string oldfil
assign oldfil "D&DPCB.QWK"
;**************************************************************
;Change next line if necessary to subdirectory to store QWK file
;**************************************************************
chdir "c:\ez2\qwk"              ;Switch to QWK mail subdirectory
isfile oldfil                   ;Check for old D&DPCB.QWK
if success
        ;Rename if present to D&xxyyS.QWK
        ;xx is month, dd is date
        ;S is sequence letter (A,B,etc.)
        string fdate
        integer char
        init n0 32
        init n1 48
        init n2 0
        getfdate oldfil fdate
        strpeek fdate 0 char
        if eq char n0
                strpoke fdate 0 n1
        endif
        strpeek fdate 3 char
        if eq char n0
                strpoke fdate 3 n1
        endif
        substr newfil oldfil 0 2             
        substr s3 fdate 0 2
        strcat newfil s3
        substr s3 fdate 3 2
        strcat newfil s3
        strcat newfil "A.QWK"
        call NAMFIX
        rename oldfil newfil
;**************************************************************
;Change next line if necessary to switch to ProComm program subdirectory
;**************************************************************
        chdir "c:\prcp"         ;Return to Procomm subdirectory
endif
;**************************************************************
;Change next line if necessary to subdirectory to store QWK file
;**************************************************************
set dldir "c:\ez2\qwk"
;**************************************************************
;Delete next two lines if you wish to use internal Zmodem
;**************************************************************
set zmodem autodload off
set protocol extproto2
waitfor "0000" 60
if waitfor
        pause 1
;**************************************************************
;Change next line to "Getfile Zmodem" if using internal Zmodem
;If using external Zmodem, then change to appropriate "DOS ----------"
;to match your setup of external Zmodem downloads.
;**************************************************************
        dos "zmqwk-d.bat"
        if SUCCESS
                goto FINI
        else
                goto GOOF1
        endif
else
        goto GOOF1
endif

GOOF1:
message "^MQMAIL download unsuccessful.  ABORT.^M"
pause 1
goto FINI

GOOF2:                          ;Error exit. REP file upload not completed.
clear N7
alarm 1
message "^MREP file upload unsuccessful.  ABORT.^M"
pause 1
goto GETQWK

FINI:
        ;Controlled exit from script file.
;**************************************************************
;Change or delete next 3 lines if you send downloaded files to
;a different subdirectory, if you don't use an external protocol to
up/download files, and if your Procomm program subdirectory is different.
;**************************************************************
        set dldir "c:\prcp\pfilp"
        set protocol extproto1
        chdir "c:\prcp"
        exit
endproc

proc BLANKIT
        box 5 40 7 65 17
        transmit "^M"
        return
endproc

proc NAMFIX
        ;look for QWK filename duplication and change if necessary
        REPT:
        isfile newfil
        if success
                inc letter
                strpoke newfil 6 letter
                goto REPT
        else
                return
        endif
        endproc
