#!/usr/bin/perl

=comment
/****
* GLIST - LIST MANAGER
* ============================================================
* FILENAME
*       cleanq
* PURPOSE
*       Queue cleanup. Remove stale queue entries.
* AUTHORS
*       Ask Solem Hoel, <ask@unixmonks.net>
* ============================================================
* This file is a part of the glist mailinglist manager.
* (c) 2001 Ask Solem Hoel <http://www.unixmonks.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
=cut

use strict;
use lib '@@INCLUDE@@';
use Glist;
use Queue;
use vars qw($me);

my $PREFIX = '@@PREFIX@@';
($me = $0) =~ s%.*/%%;

my $glist = Glist::new(prefix=>$PREFIX,daemon=>1);
my $q = new Queue ($glist);

$q->openqueue();
my $queue = $q->queue();
foreach my $entry (keys %$queue) {
	my $file = $q->fetch($entry)->[0]. '/'. $entry;	
	unless(-f $file) {
		print STDERR "Deleting stale queue file: $file\n";
		unlink($file) || 
			print STDERR "Couldn't unlink stale queue file $file: $!\n"
		;
	}
}
$q->closequeue();
