/* Imp-Master Generate Quick List Routine */

/* Returns Number Added to List */

address spot
options results

parse arg LID

adl=0

/* Does the list exist? */

if ~exists('MAIL:QUICKLISTS/'LID) then do
	address command
	'c:makedir "MAIL:QUICKLISTS/'LID'" >nil:'
	address spot
end

/* Get the Info for this area */

'getnumselected'
selected=result
'getareaname'
area=result

/* Retrieve Message Number of New Mail */

NewM = 'spot/newmail'(area)

/* MOve to first marked message */

'firstmessage'
'nextmarked'
'prevmarked'

address command

'c:list "MAIL:QUICKLISTS/'LID'/#?" lformat "%n" > t:tempowib'

address spot


'progressopen TITLE "Imp Master Quick List Processor" Prompt "0 Added 0 Dupes"'
progdat=result


do loop = 1 to selected
	'getfrom'
	 from = strip(substr(compress(result,"-[]!:&%^$/|\*#?()"||'27'x||'22'x),1,13))
	'getsubject'
	subj=result
	if upper(substr(subj,1,3))="RE:" then subj=strip(substr(subj,4),'B')
	subj=strip(substr(compress(subj,"-:&%^$[]!/|\*#?()"||'27'x||'22'x),1,13),'T')
	'getmessagenum'
        mnum=result

	if mnum>=newm then do

		address command

		'c:search "t:tempowib" "?-'substr(from,1,13)'-'subj'#?" pattern nonum > t:tempwibble '

		address spot

		if open('tempo','t:tempwibble') then do
			state=upper(readln('tempo'))

			call close('tempo')

			if state = "" then do

				adl=adl+1
				char=d2c(((loop-1)//26)+65)
			        address command
				'c:echo "'area'*n'mnum'" > "MAIL:QUICKLISTS/'LID'/'char'-'substr(from,1,13)'-'subj'"'
				address spot

			end


	        end
	end

	if loop~=selected then 'nextmarked'
	'progressupdate REQ "'progdat'" CURRENT "'LOOP'" TOTAL "'SELECTED'" PROMPT "'adl' Added 'loop-adl' Dupes"'
	if rc=5 then loop=selected

end

'progressclose ' progdat

address command

'c:delete t:tempwibble >nil:'
'c:delete t:tempowib >nil:'

address spot

exit adl
