#!/usr/local/bin/perl
# del_mailq.cgi
# Delete some mail message from the queue

require './sendmail-lib.pl';
&ReadParse();
&error_setup($text{'delq_err'});
$access{'mailq'} == 2 || &error($text{'delq_ecannot'});
$in{'file'} =~ /\.\./ && &error($text{'delq_ecannot'});
$conf = &get_sendmailcf();
foreach $mqueue (&mailq_dir($conf)) {
	$ok++ if ($in{'file'} =~ /^$mqueue\//);
	}
$ok || &error($text{'mailq_ecannot'});

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

if (-r $lfile && !$in{'force'}) {
	&header($text{'delq_title'}, "");
	print "<hr>\n";
	print "<center><form action=del_mailq.cgi>\n";
	print "<b>$whatfailed : $text{'delq_locked'}</b><p>\n";
	print "<input type=hidden name=file value='$in{'file'}'>\n";
	print "<input type=submit name=force value='$text{'delq_force'}'>\n";
	print "</form></center>\n";
	print "<hr>\n";
	&footer("list_mailq.cgi", $text{'mailq_return'});
	exit;
	}

open(QFILE, $qfile);
while(<QFILE>) {
	if (/^[^\-]*To:\s+(.*)/) { $to = $1; }
	elsif (/^[^\-]*From:\s+(.*)/) { $from = $1; }
	}
close(QFILE);

unlink($qfile);
unlink($dfile);
unlink($lfile);
&webmin_log("delmailq", undef, undef, { 'to' => $to, 'from' => $from });
&redirect("list_mailq.cgi");

