Metropoli BBS
VIEWER: wilpegasus MODE: TEXT (ASCII)
AddExtender ("wwwsk32i.dll")
IntControl (35, 500, 0, 0, 0)
bOK = @TRUE
sDial     = "<dialupname>"
nMaxRedial = <numredials>
nRedialDelay = 10
sPgmPath  = "<pgmpath>"
sPgmDir   = "<pgmdir>"
bGetMail   = <getmail>
bSendMail  = <sendmail>
bGetSend   = <getsend>
sErrDesc  = ""
nWait      = 1 ; How many minutes to wait for Agent to finish its work


;Dial our host (unless user is on a direct connect)...
hConn = 0
nNumRedials = 0
if ((bGetMail || bSendMail || bGetSend) && sDial <> "")
	:DialIt
	hConn = DUNConnect (sDial)
	nErr = SGetLastErr ()
	if (!hConn)
		switch nErr
		case @SErrNotFound
			sErrDesc = "Couldn't connect to %sDial%: no such dial-up"
			break
		case @SErrBusy
			if (nNumRedials <= nMaxRedial)
				nNumRedials = nNumRedials + 1
				Delay (nRedialDelay)
				goto DialIt
			else
				sErrDesc = "Couldn't connect to %sDial%: Line busy"
			endif
			break
		case @SErrNoAnswer
			if (nNumRedials <= nMaxRedial)
				nNumRedials = nNumRedials + 1
				Delay (nRedialDelay)
				goto DialIt
			else
				sErrDesc = "Couldn't connect to %sDial%: No answer"
			endif
			break
		case @SErrVoice
			sErrDesc = "Couldn't connect to %sDial%: A human answered"
			break
		case nErr ; <--default
			sErrDesc = "Couldn't connect to %sDial% - error %nErr%"
		endswitch
		bOK = @FALSE
		goto LogIt
	else
		if (nErr == @SAlready)
			; We're already connected. Don't hang up when this event is thru...
			hConn = 0 
		endif
	endif
endif


; Run Pegasus Mail & make it do things...
sTitle = ""
if (WinExist ("Pegasus Mail")) then sTitle = "Pegasus Mail"
if (sTitle <> "")
	WinActivate (sTitle)
else
	DirChange (sPgmDir)
	Run (sPgmPath, "")
	delay (6)
	if (WinExist ("Pegasus Mail")) then sTitle = "Pegasus Mail"
endif


; Check for new mail on server (if chosen)...
if (bGetMail)
	SendKeysTo (sTitle, "!fc")
	Delay (10)
endif

; Send queued mail (if chosen)...
if (bSendMail)
	SendKeysTo (sTitle, "!fa")
	Delay (10)
endif

; Get new mail and send mail (if chosen)...
if (bGetSend)
	SendKeysTo (sTitle, "!fh")
	Delay (10)
endif

if (hConn)
	; Wait for nWait minutes, or till user kills off Pegasus Mail manually...
	for n=1 to nWait * 6
		if (WinExist (sTitle))
			Delay (10)
			MouseMove (100+n, 100, "", "")
		endif
	next n
endif


; If user hit Ctrl+Break, WIL will bring us here...
:Cancel

; Hang up if we're on a dial-up connection...
:HangUp
if (hConn)
	nRet = DUNDisconnect (hConn)
endif


; Log what we did...
:LogIt
if bOK == @TRUE
	sLog = "Ran Pegasus Mail"
else
	sLog = strcat ("Error attempting to automate Pegasus Mail:", @CRLF, sErrDesc)
endif

CMLogMessage (sLog)
Display (8, "ClockMan95", sLog)
exit

[ RETURN TO DIRECTORY ]