/**************************************************************/
/*                      Finish Up v1.0                        */
/*           Written by Jan-willem van Eys (JAVE)             */
/*       Inspired by COP.Spot by Brett Lappan (Fu Lee)        */
/**************************************************************/
/* Why not use this script as '_Quit.Spot' (I do...)          */
/**************************************************************/
/*   Saves settings (unless you select 'quit')                */
/* Option to:                                                 */
/*   Unmark ALL unanswered messages                           */
/*   Unmark ALL unread messages                               */
/*   Export all mail                                          */
/*   Maintenance                                              */
/*   Optimize                                                 */
/**************************************************************/
/*                                                            */
/* It probably isn't the most beatiful way of getting it done */
/* in Arexx, but at least it works (and that for the second   */
/* thing I ever wrote in Arexx...)                            */
/* Anyway, suggestions are welcome...                         */
/*                                                            */
/* Fido:  2:283/2.11                                          */
/*  NLA: 14:100/108.4                                         */
/**************************************************************/

/* Set some defaults */

NL='0d'x
exp='NO '
mai='NO '
opt='NO '
unr='NO '
unp='NO '

/* Start it all... */

ADDRESS spot
OPTIONS RESULTS

/* What do they want? */

'requestresponse TITLE "Finish Up" PROMPT "Export messages?" GADGETS "_Yes|_Quit|_No"'

IF rc = 1 THEN DO
	Exporteer=1
	exp=YES
END
IF rc = 2 THEN DO
	'quitspot NOREQ'
	EXIT
END

'requestresponse TITLE "Finish Up" PROMPT "Maintenance?'NL''NL'WARNING!'NL'~~~~~~~~'NL'May delete messages" CENTER GADGETS "_Yes|_No"'

IF rc = 1 THEN DO
	onderhoud=1
	mai=YES
END

'requestresponse TITLE "Finish Up" PROMPT "Optimize?'NL''NL'WARNING!'NL'~~~~~~~'NL'May take a while" CENTER GADGETS "_Yes|_No"'

IF rc = 1 THEN DO
	optimaal=1
	opt=YES
END

'requestresponse TITLE "Finish Up" PROMPT "Clear following flags?" GADGETS "Un_replied|_Unread|_Both|_None"'

IF rc = 1 THEN DO
	antwoord=1
	unp=YES
	lezen=0
END

IF rc = 2 THEN DO
	antwoord=0
	lezen=1
	unr=YES
END

IF rc = 3 THEN DO
	antwoord=1
	lezen=1
	unp=YES
	unr=YES
END


'requestresponse TITLE "Finish Up" PROMPT "LAST CHANCE'NL'Continue?'NL''NL'     Export: 'exp''NL'Maintenance: 'mai''NL'   Optimize: 'opt''NL'     Unread: 'unr''NL'  Unreplied: 'unp'" CENTER GADGETS "_Yes|Just _Quit|_Abort"'

IF rc = 2 THEN DO
	'quitspot NOREQ'
	EXIT
END
IF rc = 0 THEN DO
	EXIT
END

/* All questions done, now get on with it */
/* First clear chosen flags */

IF antwoord=1 THEN DO
	'unrepliedarea'
	DO UNTIL rc = 2
		'messagelist'
		'excludeflag ALL'
		'includeflag UNREPLIED'
		'clearflags UNREPLIED'
		'excludeflag ALL'
		'unrepliedarea'
	END
END
IF lezen=1 THEN DO
	'unreadarea'
	DO UNTIL rc = 2
		'messagelist'
		'excludeflag ALL'
		'includeflag UNREAD'
		'clearflags UNREAD'
		'excludeflag ALL'
		'unreadarea'
	END
END

/* Export, Maintenance & Optimize */

'arealist'
IF exporteer=1 THEN DO
	'export QUIET CLOSEWIN'
END
IF onderhoud=1 THEN DO
	'maintenance NOREQ CLOSEWIN'
END
IF optimaal=1 THEN DO
	'optimize NOREQ CLOSEWIN'
END

/* Save settings & Quit */

'savesettings NOREQ'
'quitspot NOREQ'
EXIT
