/*
 *                              Imp Master
 *                   The Ultimate Spot Import Manager
 *
 *                         (C)1995 Steve Pearson
 *
 *                          This is Tailor-Ware
 *                        Edit it as you NEED it
 *
 *             DO NOT DISTRIBUTE YOUR CUSTOMISED VERSIONS!!!
 *
 *                    $VER: Imp Master V1.1 (4.8.95)
 *
 */

/* This Code is MODULAR to use it you NEED the following Modules
 *
 *  The Modules MUST be installed into the correct path!!!
 *
 *
 *
 *  The Main Script NEEDS!
 *
 *  rexx:spot/Impmaster/impmaster
 *	rexx:spot/StoreStat
 *	rexx:spot/ReStoreStat
 *  	rexx:spot/impmaster/readprefs
 *  	rexx:spot/ReadPrefs
 *	rexx:spot/unreadareas
 *	rexx:spot/impmaster/updateimp
 *	rexx:spot/updatenewmail
 *
 *  The Processors NEED!
 *
 *	rexx:spot/AddToList
 *	rexx:spot/uudecode
 *	rexx:spot/QuickSearch
 *	rexx:spot/newmail
 *	rexx:spot/marknewmail
 *
 *  Then you can install any of these process you need
 *
 *  rexx:spot/Imp/GMM
 *  rexx:spot/Imp/UUD
 *  rexx:spot/Imp/QLD
 *  rexx:spot/Imp/INT
 *  rexx:spot/Imp/QLM
 *  rexx:spot/Imp/QLI
 *  rexx:spot/Imp/GMA
 *  rexx:spot/Imp/QLA
 *  rexx:spot/Imp/GMS
 *  rexx:spot/Imp/GMF
 *  rexx:spot/Imp/QLS
 *  rexx:spot/Imp/QLF
 *  rexx:spot/Imp/NNA
 *  rexx:spot/Imp/MLH
 *  rexx:spot/Imp/COU
 *  rexx:spot/Imp/EMF
 *  rexx:spot/Imp/PNR
 *  rexx:spot/Imp/NFA
 *  rexx:spot/imp/rrr
 *
 *
 *  Imp Master also needs THESE Commands in your "C:" directory
 *
 *  Delete
 *  Sort
 *  Search
 *  List
 *
 *  These should be the standard WB commands or Fully Compatible
 *
 */

pref = 'MAIL:IMP.PREF'


/******************************************************************/
/* Only Venture Beyond Here If You intend want to make a mess =)  */
/******************************************************************/

/* Load in the Rexx Support Library */

if pos('rexxsupport.library',show('l'))=0 then do
	IF ~EXISTS('LIBS:rexxsupport.library') THEN DO
		'requestnotify "Imp-Master NEEDS Rexxsupport.library"'
		exit
	END
	CALL ADDLIB('rexxsupport.library',0,-30,0)
end

/* Put Prefs file onto Clip List */

call setclip('IMP_PREF',pref)

Address SPOT
Options Results

/* Store The Status of Spot so we can return him l8r */

status = 'spot/storestat'()

'messageadvance off'

/* Init some vars */

NL='0d'x
LF='0a'x
space=' '

/* Read Prefs File */

call 'spot/impmaster/readprefs'()

/* Get PRefs From ClipList */

yname=getclip('IMP_NAME')

taddr=getclip('IMP_ADDR')
rarea=getclip('IMP_REPORT')
uuxc=getclip('IMP_UUXC')

/* Check that Quick Lists are creatable */

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

/* Get The Unread Area List */

unlist='spot/unreadareas'()

/* Initialise the report holding variables */

report.gma=''
gmatot=0
report.qla=''
qlatot=0
report.gms=''
gmstot=0
report.qls=''
qlstot=0
report.gmm=''
gmmtot=0
report.qlm=''
qlmtot=0
report.int=''
inttot=0
report.qli=''
qlitot=0
report.gmf=''
gmftot=0
report.qlf=''
qlftot=0
report.uud=''
uudtot=0
report.qld=''
qldtot=0
report.nna=''
nnatot=0
report.mlha=''
addtot=0
report.mlhr=''
remtot=0
report.mlhi=''
infotot=0
report.pnr=''
pnrtot=0
report.nfa=''
nfatot=0
report.cou=''
coutot=0
report.emf=''
emftot=0
report.rrr=''
rrrtot=0

/* Process rest of prefs file line by line */

call open('Prefs',pref,'r')

do until substr(line,1,3)="---"
	line=readln('Prefs')
end

line=''

do until ((eof('Prefs')) | (substr(line,1,3)="---"))
	line = readln('Prefs')
	action = upper(subword(line,1,1))

	area=subword(line,2,1)
	if pos('<'||area||'>',unlist)~=0 then do

		select

			when action='GMA' then do

				selected='spot/imp/gma'(area)

				if selected>0 then do
					report.gma=report.gma||left(space,5-length(selected))||selected||' in area '||area||lf
					gmatot=gmatot+selected
				end

	                end

			when action ='QLA' then do

	                        Lid=strip((substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

				selected='spot/imp/qla'(area,lid)

				if selected>0 then do

					report.qla=report.qla||left(space,5-length(selected))||selected||' In Area '||substr(area,1,10)||' Listed To '||lid||lf

					qlatot=qlatot+selected
				end

			end

			when action = 'GMS' then do

				Isub=strip(upper(substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

				selected='spot/imp/gms'(area,lid)

				if selected >0 then do

					report.gms=report.gms||left(space,5-length(selected))||selected||' With Subject '||substr(isub,1,15)||' In Area '||area||lf
					gmstot=gmstot+selected

				end
			end

			when action = 'QLS' then do

				lid=subword(line,3,1)
				Isub=strip(upper(substr(line,pos(lid,line)+length(lid)+1,length(line))),'B')

				selected = 'spot/imp/qls'(area,lid,isub)

				if selected > 0 then do

					report.qls=report.qls||left(space,5-length(selected))||selected||' With Subject '||substr(isub,1,10)||' In Area '||substr(area,1,10)||' Listed To '||LID||lf
					qlstot=qlstot+selected

				end
			end

			when action = 'GMM' then do

				IMent=strip(upper(substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

				selected='spot/imp/gmm'(area,iment)

				if selected > 0 then do

					gmmtot=gmmtot+selected

					report.gmm=report.gmm||left(space,5-length(selected))||selected||' Who Mentioned '||substr(iment,1,10)||' In Area '||area||lf

				end
			end

	                when action = 'QLM' then do

				LID=subword(line,3,1)
				IMent=strip(upper(substr(line,pos(lid,line)+length(lid)+1,length(line))),'B')

				selected = 'spot/imp/qlm'(area,lid,iment)

				if selected > 0 then do

					qlmtot=qlmtot+selected
					report.qlm=report.qlm||left(space,5-length(selected))||selected||' Who Mentioned '||substr(iment,1,10)||' In Area '||substr(area,1,10)||' Listed To '||LID||lf
				end
			end

			when action = 'INT' then do

				Iname=strip(upper(substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

	                        selected='spot/imp/int'(area,iname)

				if selected>0 then do

					inttot=inttot+selected
	                                report.int=report.int||left(space,5-length(selected))||selected||' Addressed To '||substr(iname,1,15)||' In Area '||area||lf
				end

			end

	                when action = 'QLI' then do

				lid=subword(line,3,1)
				Iname=strip(upper(substr(line,pos(lid,line)+length(lid)+1,length(line))),'B')

	                        selected='spot/imp/qli'(area,lid,iname)

				if selected>0 then do

						qlitot=qlitot+selected
						report.qli=report.qli||left(space,5-length(selected))||selected||' Addressed To '||substr(iname,1,15)||' In Area '||substr(area,1,10)||' Listed To '||LID||lf

				end
			end

	                when action = 'GMF' then do

				Iname=strip(upper(substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

	                        selected='spot/imp/gmf'(area,iname)

				if selected > 0 then do
					report.gmf=report.gmf||left(space,5-length(selected))||selected||' Written From '||substr(iname,1,15)||' In Area '||area||lf
					gmftot=gmftot+selected
				end
			end

			when action = 'QLF' then do

				lid=subword(line,3,1)
				Iname=strip(upper(substr(line,pos(lid,line)+length(lid)+1,length(line))),'B')


	                        selected='spot/imp/qlf'(area,lid,iname)

				if selected > 0 then do
					report.qlf=report.qlf||left(space,5-length(selected))||selected||' Written From '||substr(iname,1,15)||' In Area '||substr(area,1,10)||' Listed To '||LID||lf
					qlftot=qlftot+selected
				end
			end

			when action = 'UUD' then do

				uupath=strip(upper(substr(line,pos(AREA,line,3)+length(area)+1,length(line))))

				selected='spot/imp/uud'(area,uupath)

				if selected>0 then do

					report.uud=report.uud||left(space,5-length(selected))||selected||' UUDecoded From '||substr(area,1,10)||' To '||uupath||lf
					uudtot=uudtot+selected

				end
			end

			when action = 'QLD' then do

				lid=subword(line,3,1)
				uupath=strip(upper(substr(line,pos(lid,line,3)+length(lid)+1,length(line))))

				selected='spot/imp/qld'(area,lid,uupath)

				if selected >0 then do

					qldtot=qldtot+selected
					report.QLD=report.QLD||left(space,5-length(selected))||selected||' UUdecoded From '||substr(area,1,10)||' To '||substr(uupath,1,20)||' Listed To '||lid||lf

				end
			end

			when action = 'NNA' then do

				selected = 'spot/imp/nna'(area)

				if selected > 0 then do

					report.NNA=report.NNA||left(space,5-length(selected))||selected||' From '||AREA||lf
					nnatot=nnatot+selected

				end

			end

	        	when action = 'MLH' then do

				MLHID=subword(line,3,1)

				mlhdata='spot/imp/mlh'(area,mlhid)

				parse var mlhdata atot "#" rtot "#" itot

				if (atot+rtot+itot)>0 then do
					if atot>0 then report.mlha=report.mlha||left(space,5-length(addtot))||atot||' Requested Addition To '||MLHID||lf
					if rtot>0 then report.mlhr=report.mlhi||left(space,5-length(remtot))||rtot||' Requested Removal From '||MLHID||lf
					if itot>0 then report.mlhi=report.mlhi||left(space,5-length(infotot))||itot||' Requested Info About '||MLHID||lf
					addtot=addtot+atot
					remtot=remtot+rtot
					infotot=infotot+itot
				end
			end

	                when action = 'PNR' then do

				REQID=subword(line,3,1)
				fpost=strip(substr(line,pos(reqid,line,3)+length(reqid)+1,length(line)),'B')

				selected='spot/imp/pnr'(area,reqid)

				if selected>0 then do
					report.pnr=report.pnr||left(space,5-length(selected))||selected||' Requests For '||REQID||lf
					pnrtot=pnrtot+selected
				end
			end

			when action = 'NFA' then do
				naddr=strip(upper(substr(line,pos(AREA,line)+length(area)+1,length(line))),'B')

	                        selected='spot/imp/nfa'(area,naddr)

				if selected > 0 then do
					report.nfa=report.nfa||left(space,5-length(donethem))||donethem||' Nuked From '||substr(naddr,1,15)||' In Area '||area||lf
					nfatot=nfatot+selected
				end
			end

			when action='COU' then do

				KP=subword(line,3,1)
				selected='spot/imp/cou'(area,kp)

				if selected>0 then do
					report.cou=report.cou||left(space,5-length(selected))||selected||' Unreplieds Cleared From '||area||lf
					coutot=coutot+selected
				end
	                end

			when action='EMF' then do

				selected='spot/imp/emf'(area)

				if selected>0 then do

					emftot=emftot+selected
					report.emf=report.emf||left(space,5-length(selected))||selected||' EMails Changed in '||area||lf

				end

			end

                	when action='RRR' then do
				
                                selected='spot/imp/rrr'(area)

				if selected>0 then do

					rrrtot=rrrtot+selected
					report.rrr=report.rrr||left(space,5-length(selected))||selected||' Receipt Requests Replied to in '||area||lf
				end
			end

			otherwise NOP

		end
	end

end

call 'spot/updatenewmail'()

/* Write the report */

If ~open('report','t:impreporttemp','w') then Do
	'Requestnotify TITLE "Imp Master" Prompt "Unable to open Report File"'
	call quit
end

/* Output the ImpMAster Header */
/* To the Report File */

call writeln('report',"                              _ _|"||lf||"                                |  __ `__ \  __ \"||lf||"                                |  |   |   | |   |"||lf||"                              ___|_|  _|  _| .__/"||lf||"                                            _|"||lf||"                           \  |            |"||lf||"                          |\/ |  _` |  __| __| _ \  __|"||lf||"                          |   | (   |\__ \ |   __/ |"||lf||"                         _|  _|\__,_|____/\__\___|_|"||lf||lf)
CALL WRITELN('report','                                Import Report'||lf||lf)

/* Generate the Middle bit =) */

if (gmatot+gmstot+gmmtot+gmftot+inttot)>0 then call Writeln('report','                         Mail Marked As Unreplied'||lf)

if report.gma~='' then call Writeln('report','GMA - Give Me All Processed'||lf||lf||report.gma||lf||'GMA Processed '||gmatot||' Messages'||lf)
if report.gms~='' then call Writeln('report','GMS - Give Me Subject Processed'||lf||lf||report.gms||lf||'GMS Processed '||gmstot||' Messages'||lf)
if report.gmm~='' then call Writeln('report','GMM - Give Me Mention Processed'||lf||lf||report.gmm||lf||'GMM Processed '||gmmtot||' Messages'||lf)
if report.INT~='' then call Writeln('report','INT - Intercept Processed'||lf||lf||report.int||lf||'INT Processed '||INTtot||' Messages'||lf)
if report.gmf~='' then call Writeln('report','GMF - Give Me From Processed'||lf||lf||report.gmf||lf||'GMF Processed '||gmftot||' Messages'||lf)

if gmatot+gmstot+gmmtot+gmftot+inttot>0 then call writeln('report','Total Mail Marked as Unreplied '||gmatot+gmstot+gmmtot+gmftot+inttot||lf||lf)

if qlatot+qlstot+qlmtot+qlftot+qlitot>0 then call Writeln('report','                         Mail Added to Quick Lists'||lf)

if report.qla~='' then call Writeln('report','QLA - Quick List All Processed'||lf||lf||report.qla||lf||'QLA Processed '||qlatot||' Messages'||lf)
if report.QLs~='' then call Writeln('report','QLS - Quick List Subject Processed'||lf||lf||report.QLs||lf||'QLS Processed '||qlstot||' Messages'||lf)
if report.QLm~='' then call Writeln('report','QLM - Quick List Mention Processed'||lf||lf||report.QLM||lf||'QLM Processed '||qlmtot||' Messages'||lf)
if report.QLI~='' then call Writeln('report','QLI - Quick List Intercept Processed'||lf||lf||report.QLi||lf||'QLI Processed '||qlitot||' Messages'||lf)
if report.QLf~='' then call Writeln('report','QLF - Quick List From Processed'||lf||lf||report.QLF||lf||'QLF Processed '||qlatot||' Messages'||lf)

if qlatot+qlstot+qlmtot+qlftot+qlitot>0 then call Writeln('report','Total Mail Added to Quick Lists '||qlatot+qlstot+qlmtot+qlftot+qlitot||lf||lf)

if uudtot+qldtot>0 then call writeln('report','                             UUEncodes Decoded'||lf||lf)

if report.uud~='' then call Writeln('report','UUD - UUDecode Processed'||lf||lf||report.uud||lf||'UUD Processed '||uudtot||' Messages'||lf)
if report.QLd~='' then call Writeln('report','QLD - Quick List UUDecode Processed'||lf||lf||report.QLd||lf||'QLD Processed '||qlDtot||' Messages'||lf)

if uudtot>0 then call writeln('report',left(space,5-length(uudtot))||uudtot||' UUEnecodes Marked as Unreplied')
if QLdtot>0 then call writeln('report',left(space,5-length(qldtot))||qldtot||' UUEnecodes Added to lists')
if uudtot+qldtot>0 then call writeln('report',lf||'Total Messages UUDecoded 'uudtot+qldtot||lf||lf)

if nnatot+nfatot>0 then call Writeln('report','                       Mail Nuked From Message Base'||lf)
if report.NNA~='' then call Writeln('report','NNA - Nuke Not All Nuked'||lf||lf||report.nna||lf||' NNA Nuked '||nnatot||lf)
if report.nfa~='' then call writeln('report','NFA - Nuke From Address Nuked'||lf||lf||report.nfa||lf||' NFA Nuked '||nfatot||lf)
if nnatot+nfatot>0 then call Writeln('report','Total Messages Nuked '||nnatot+nfatot||lf)

if addtot+remtot+infotot>0 then call Writeln('report','                          Mailing List Processes'||lf)

if report.mlha~='' then call Writeln('report','MLH - Mailing List Handler Additions'||lf||lf||report.mlha||lf||left(space,5-length(addtot))||addtot||' Added to Mailing Lists'||lf)
if report.mlhi~='' then call Writeln('report','MLH - Mailing List Handler Information'||lf||lf||report.mlhi||lf||left(space,5-length(infotot))||infotot||' Information Texts Posted'||lf)
if report.mlhr~='' then call Writeln('report','MLH - Mailing List Handler Removals'||lf||lf||report.mlhr||lf||left(space,5-length(remtot))||remtot||' Removed From Mailing Lists'||lf)
if report.PNR~='' then call Writeln('report','PNR - Post Net Request Processed'||lf||lf||report.PNR||lf||left(space,5-length(pnrtot))||pnrtot||' Request Postings'||lf)

if coutot+emftot+rrrtot>0 then call writeln('report','                               Miscellaneous'||lf)

if report.cou~='' then call writeln('report','COU - Clear Old Unreplieds'||lf||lf||report.cou||lf||'Total Unreplieds Cleared '||coutot||lf)
if report.emf~='' then  call writeln('report','EMF - EMail From'||lf||lf||report.emf||lf||'Total Emails Changed '||emftot||lf)
if report.rrr~='' then   call writeln('report','RRR - Receipt Request Reply'||lf||lf||report.rrr||lf||'Total Receipt Replies Posted '||rrrtot||lf)


/* Tag The Ending onto the report */

call writeln('report','          ******************************************************'||lf||'          * Imp Master V1 (C)1995 Steve Pearson (2:250/563.12) *'||lf||'          ******************************************************')
call close('report')

'gotoarea NAME 'rarea
'excludeflag all'

/* Posts the report to you =) */


'write TO "'yname'"  FROM "Imp Master" TOADDR "'YADDR'" FROMADDR "'YADDR'" SUBJECT "Imp Master Report" ORIGIN "Imp Master V1 (c) Steve Pearson" FILE "t:impreporttemp" NOSIG NOEDIT NOGUI'


'lastmessage'
'markmessage toggle'
'clearflags EXPORT'
'setflags UNREAD UNREPLIED'

call 'spot/restorestat'(status)

'messageadvance on'

exit