/* 
 *            Imp Mail List Util
 * The Ultimate Accessory to Spot Imp Master
 * 
 *         (C)1995 Steve Pearson
 *
 *          This is Tailor-Ware
 *         Edit it as YOU NEED it
 *
 *    $VER : Imp Mail List V1 (1.6.95)
 *
 */


/* This should point to the same file as the main script */

pref = 'Mail:Imp.Pref'

/* From here on is the gubbins that makes it go */

Address SPOT
Options Results


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


CR='0d'x

/* Open prefs File and Check version */

yname='spot/readprefs'(pref,"NAME")
yaddr='spot/readprefs'(pref,"ADDRESS")

/* Now comes th actual choice bit */

'Requestresponse TITLE "Imp Master Mailing List" PROMPT "Select Action" GADGETS "Post|Create|Delete|Quit" CENTER'
resp=RC
if resp~=0 then do
	if resp=1 then do
		/* Post Module */


		'requestfile TITLE "Select Mailing List" PATH "MAIL:MAILINGLISTS/" PATTERN "#?.MLIST"'
		mlhid=result
		if mlhid="RESULT" then exit
		mlhid=upper(mlhid)

                mlhid=substr(mlhid,lastpos('/',mlhid)+1,length(mlhid)-lastpos('/',mlhid)-6)

		if mlhid='' then mlhid=left(mlhidt,1,length(mlhidt)-6)
		if ~open('ml','MAIL:MAILINGLISTS/'mlhid'.MLIST','r') then do
			'requestnotify PROMPT "ERROR: Could not open Mailing list" '
			exit
		end

                interpret "Address command '"||'spot/spotedit'("T:TEMPMLIST")||"'"

		size=word(statef("T:TEMPMFLIST"),2)

		if size ~=0 then do
			'requestresponse TITLE "Imp Master Mailing List" Prompt "Confirm Post to 'mlhid'" Gadgets "_Post|_Abort" center'
			if rc~=0 then do
			        call open('mlpost','t:tempwiddle','w')
				call writeln('mlpost',"                              _ _|")
				call writeln('mlpost',"                                |  __ `__ \  __ \")
				call writeln('mlpost',"                                |  |   |   | |   |")
				call writeln('mlpost',"                              ___|_|  _|  _| .__/")
				call writeln('mlpost',"                                            _|")
				call writeln('mlpost',"                           \  |            |")
				call writeln('mlpost',"                          |\/ |  _` |  __| __| _ \  __|")
				call writeln('mlpost',"                          |   | (   |\__ \ |   __/ |")
				call writeln('mlpost',"                         _|  _|\__,_|____/\__\___|_|")
				CALL WRITELN('mlpost','')
				CALL WRITELN('mlpost','')
				CALL WRITELN('mlpost','                             Mailing List Message')
				CALL WRITELN('mlpost','')
				CALL WRITELN('mlpost','')
				call close('mlpost')
				address command
				'c:type t:tempmlist >> t:tempwiddle'
				'delete t:tempmlist > nil:'
				address spot
				'gotomatrixarea'
				'messages'
				do until eof('ml')
					line=readln('ml')
					parse var line from " @ " fromaddress
	      				'write TO "'from'" TOADDR "'fromaddress'" FROM "'yname'" SUBJECT "Mailing List Message" ORIGIN "Imp Master V1.0 (C) Steve Pearson" FILE "t:tempwiddle" nosig noedit nogui'
				end
			end
		end

	end
	if resp=2 then do

	/* Create / Edit Module */

		'requeststring TITLE "ImpMaster Mailing List" PROMPT "Enter Mailing List ID" CENTER'
		mlhid=result
		if mlhid="RESULT" then exit
		'requestnotify TITLE "ImpMaster Mailing LIst" Prompt "Please Enter the Welcome Text 'cr'that will confirm a users addition to your Mailing List" CENTER'

		cmd = "'"||'spot/spotedit'("MAIL:MAILINGLISTS/"||MLHID||".ADD")||"'"

		address command
                interpret cmd
		address spot

		'requestnotify TITLE "ImpMaster Mailing LIst" Prompt "Please Enter the Information Text 'cr'that will be used to answer users requests for info" CENTER'

		interpret  "address command '" || 'spot/spotedit'("MAIL:MAILINGLISTS/"||MLHID||".INFOT")||"'"

		'requestnotify TITLE "ImpMaster Mailing LIst" Prompt "Please Enter the GoodBye Text 'cr'that will confirm a users Removal from your Mailing List" CENTER'

		interpret  "address command '" || 'spot/spotedit'("MAIL:MAILINGLISTS/"||MLHID||".REM")||"'"

		if ~open('mlpref','MAIL:mailinglists/'||MLHID||'.MLP','w') then do
			'requestnotify Title "ImpMaster Mailing List" Prompt "Unable to create New Prefs"'
                         exit
		end
		call writeln('mlpref','ADDTEXT MAIL:mailinglists/'||MLHID||'.ADD')
		call writeln('mlpref','REMOVETEXT MAIL:mailinglists/'||MLHID||'.REM')
		call writeln('mlpref','INFOTEXT MAIL:mailinglists/'||MLHID||'.INFOT')
		call close('mlpref')

	end


/* The delete list bit */

	if resp=3 then do


		'requestfile TITLE "DELETE MAILING LIST!" PATH "MAIL:mailinglists/" PATTERN "#?.MLP"'
		mlhid=upper(result)
		if mlhid="RESULT" then exit
		mlhid=substr(mlhid,lastpos('/',mlhid)+1,length(mlhid)-lastpos('/',mlhid)-4)

		'requestresponse TITLE "IMP MASTER DELETE!" Prompt "Confirm the Deletion of'cr||mlhid'" GAdgets "DELETE|_ABORT" center'

		if rc=0 then exit
		if ~open('mlpref','MAIL:mailinglists/'||mlhid||'.MLP') then do
			'requestnotify TITLE "Imp Master Delete" Prompt "ERROR: Could not open 'mlhid' Prefs"'
                        exit
		end

                do until eof('mlpref')
			line=readln('mlpref')
                        id=upper(subword(line,1,1))
			if id='ADDTEXT' then do
				ADDT=strip(substr(line,pos('ADDTEXT',line)+8,length(line)),'B')
			end
			if id='REMOVETEXT' then do
				REMT=strip(substr(line,pos('REMOVETEXT',line)+11,length(line)),'B')
			end
			if id='INFOTEXT' then do
				INFOT=strip(substr(line,pos('INFOTEXT',line)+9,length(line)),'B')
                        end
		end

		call close('mlpref')

                address command
		'delete > nil: "'infot'"'
		'delete > nil: "'addt'"'
		'delete > nil: "'remt'"'
		'delete > nil: "MAIL:mailinglists/'mlhid'.MLIST"'
		'delete > nil: "MAIL:mailinglists/'mlhid'.MLP"'
                address spot
	end


end