/* COU - Clear Old Unreplieds */

address spot
options results

signal on Syntax
signal on failure
options failat 20

parse arg area,kp

yname=getclip('IMP_NAME')

'gotoarea NAME ' Area
if rc=0 then do

	'MessageList'

	'firstmessage'
	'excludeflag all'


	unrep=1

	selected=0


	do until (unrep=0)

	'markmessage'
	'getmessageflags'
	flags=result
	'getto'
	to=result
	unrep=0
	if flags>=65536 then if bittst(x2c(d2x(flags)),16) then unrep=1
	if unrep=1 then selected=selected+1
	if ((unrep=1) & (KP=1) & (to=yname)) then do
		'markmessage clear'
		selected=selected-1
	end
	'nextmessage'
	if rc>0 then unrep=0
end

'clearflags unreplied'

'excludeflag all'

exit selected

syntax:
failure:

signal off failure
signal off syntax

parse source . . . program

program = subword(program,1,words(program)-2)

call 'spot/impmaster/imperror'(program,rc,sigl,sourceline(sigl))

exit
