/* Last Search Imp Uses Pointers and things */

address spot
options results

parse arg area,patt

maxsearch=200

'gotoarea'area
'messagelist'

nsel = 'spot/marknewmail'(area)

if nsel~=0 then do
	/* Includes all mail with subject that fit the Iment */
	'exclude STRING "'patt'" TEXT UNREAD NOGUI NOREQ'

	'getnumselected'
	esel=result

	if esel=nsel then do
		'excludeflag all'
	end

	if esel<nsel then do
		end=0
		'firstmessage'
		'nextmarked'
		'prevmarked'
		do until end=1
			'markmessage toggle'
			'nextmessage'
			if rc>0 then end=1
		end
	end
end

/* Otherwise it's faster to do it the normal way! */

if nsel=0 then do
	'include STRING "'patt'" TEXT UNREAD NOGUI NOREQ'
end

'getnumselected'
selec=result

exit selec