#!/usr/local/bin/perl
# del_mailqs.cgi
# Delete some mail messages from the queue

require './sendmail-lib.pl';
&ReadParse();
&error_setup($text{'delq_err'});
$access{'mailq'} == 2 || &error($text{'delq_ecannot'});
&header($text{'delq_titles'}, "");
print "<hr><p>\n";

$count = 0;
$conf = &get_sendmailcf();
foreach $file (split(/\0/, $in{'file'})) {
	print &text('delq_file', "<tt>$file</tt>"),"&nbsp;&nbsp;&nbsp;\n";

	local $ok;
	foreach $mqueue (&mailq_dir($conf)) {
		$ok++ if ($file =~ /^$mqueue\//);
		}
	if (!$ok) {
		print $text{'delq_efile'},"<br>\n";
		next;
		}

	if ($file =~ /\.\./) {
		print $text{'delq_efile'},"<br>\n";
		next;
		}
	if (!-r $file) {
		print $text{'delq_egone'},"<br>\n";
		next;
		}

	$qfile = $file;
	($dfile = $qfile) =~ s/\/qf/\/df/;
	($lfile = $qfile) =~ s/\/qf/\/xf/;

	if (-r $lfile && !$in{'locked'}) {
		print $text{'delq_elocked'},"<br>\n";
		next;
		}

	unlink($qfile);
	unlink($dfile);
	unlink($lfile);
	print $text{'delq_ok'},"<br>\n";
	$count++;
	}
&webmin_log("delmailq", undef, undef, { 'count' => $count }) if ($count);
print "<p><hr>\n";
&footer("list_mailq.cgi", $text{'mailq_return'});

