.KEY HOST,GROUPS/K,HISTORY/K,STAMP/K,KILL/K,TO/K,PANIC/K,BATCH/K/N,BLIP/K/N,TRACE/K,MODE/K
;*
;*   Sample script to invoke nntp client and add news to uucp Newsbase
;*
;*  Mandatory parameter of name of news server; all other parameters have
;*  reasonable defaults (assuming you have a uulib:NewsGroups file).
;*
;*  Small changes to allow:
;*    1) Auto disconnection when news transfer complete
;*    2) List of new news groups to be saved in uulib:NewNewsGroups
;*
.def HOST distort.demon.co.uk		      ;for Demon subscribers only !
.def GROUPS "UULIB:NewsGroups"		   ;file containing list of groups
.def HISTORY "AmiTCP:db/NewsHistory"	;file containing news history
.def STAMP "AmiTCP:db/NewsStamp"	      ;file containing date news last retrieved
.def KILL "AmiTCP:db/nntpkillfile"	   ;file containing kill instructions
.def BLIP 10				               ;frequency of display of blipmsg
.def TO "uuspool:NewsBatch"		      ;file to contain batched news
.def PANIC 200000			               ;maximum size of pending news in T:
.def BATCH 12				               ;maximum number of requests batched to server
.def TRACE 3				               ;amount of information displayed
.def MODE "NEWS"		    	           ; don't drop link by default
.BRA {
.KET }

if NOT EXISTS {Groups}			;Check we have a Groups file
	echo "You must set up a '{Groups}' file, or give the name"
	echo "of another file containing the news groups you want"
	quit 10
endif

if {Host} eq localhost
	echo "NNTPTransfer: Not connected."
	quit 10
	if {Host} eq $HostName
		echo "NNTPTransfer: Not connected."
		quit 10
		if {Host} eq $NodeName
				echo "NNTPTransfer: Not connected."
				quit 10
		endif
	endif
endif


echo "Pulling News..."

changetaskpri 5

if "{MODE}" eq "AUTONEWS"
	echo "Link will be automatically disconnected when complete"
endif

echo >t:nntpclient-Commands "NEWGROUPS t:nntp-NewGroups*NNEWNEWS {Groups} {to}"

failat 16                   ;nntpclient has done something at error level 10
nntpclient <t:nntpclient-Commands {host} COMPLEX BATCH {batch} BLIP {blip} BLIPMSG "NNTP: %5ld articles received" HISTORYFILE {history} STAMPFILE {stamp} TRACE {trace} KILLFILE {kill}
if $RC EQ 15                ; at error level 15 connect refused
        wait 5
        nntptransfer
        quit
endif
failat 10 

delete t:nntpclient-Commands QUIET	;don't want command file now

if exists t:nntp-NewGroups		;Got any new groups ?
	echo "----- New News Groups -----" >>uulib:NewNewsGroups
	type t:nntp-NewGroups >>uulib:NewNewsGroups
	; uncomment the above two lines if you want to save the new newsgroups file
	echo "{host} has the following new news groups:"
	echo
	type t:nntp-NewGroups		; Show new groups
	delete t:nntp-NewGroups	quiet	; and get rid of the file
endif

if exists {to}
	echo "unbatching news ..."
	failat 30					;don't worry if we can't find GetPriority
	getpriority >nil:			;preserve the current priority in a local variable
	failat 20					;back to default
	changetaskpri -1			;postprocessing is a background task
	dannews {to} delete -h	;postprocess news to uucp news base
	failat 10					
	get >nil: Priority		;check that Priority local var. was set
	if exists {history}
		rename {history} {history}.old
		tail -1500 {history}.old >{history}
		delete {history}.old quiet
	endif
	if not WARN
		changetaskpri $Priority ;re-instate the saved priority
	endif
else
	echo "Sorry, no news transferred"
endif

