File: mailq_search.cgi

package info (click to toggle)
webmin-extra 1.180-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 12,324 kB
  • ctags: 1,200
  • sloc: perl: 39,117; makefile: 125
file content (116 lines) | stat: -rwxr-xr-x 4,315 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/local/bin/perl
# mailq_search.cgi
# Display some messages from the mail queue

require './sendmail-lib.pl';
require './boxes-lib.pl';
&ReadParse();
$access{'mailq'} || &error($text{'mailq_ecannot'});
&ui_print_header(undef, $text{'searchq_title'}, "");

# Get all of the queued messages that this user can see
$conf = &get_sendmailcf();
foreach $mqueue (&mailq_dir($conf)) {
	opendir(QDIR, $mqueue);
	push(@qfiles, map { "$mqueue/$_" } grep { /^qf/ } readdir(QDIR));
	closedir(QDIR);
	}
@qmails = grep { &can_view_qfile($_) }
	       map { $qf = $_;
		     ($df = $qf) =~ s/\/qf/\/df/;
		     &mail_from_queue($qf, $df) } @qfiles;

# Do the search
$fields = [ [ $in{'field'}, $in{'match'} ] ];
@qmails = grep { &mail_matches($fields, 1, $_) } @qmails;
print "<p><b>",&text($in{'field'} =~ /^\!/ ? 'search_results3' :
	  'search_results2', scalar(@qmails), "<tt>$in{'match'}</tt>"),"</b><p>\n";

if (@qmails) {
	print "<form action=del_mailqs.cgi method=post>\n";
	if ($config{'top_buttons'}) {
		if ($access{'mailq'} == 2) {
			print "<input type=submit value='$text{'mailq_delete'}'>\n";
			print "<input type=checkbox name=locked value=1> $text{'mailq_locked'}<p>\n";
			}
		print &select_all_link("file", 0, $text{'mail_all'}),"&nbsp;\n";
		print &select_invert_link("file", 0, $text{'mail_invert'}),"<br>\n";
		}
	print "<table border width=100%>\n";
	print "<tr $tb> ";
	if ($access{'mailq'} == 2) {
		print "<td><br></td> ";
		}
	foreach $s (split(/,/, $config{'mailq_show'})) {
		$show{$s}++;
		}
	print "<td><b>$text{'mailq_id'}</b></td>\n";
	print "<td><b>$text{'mailq_sent'}</b></td>\n" if ($show{'Date'});
	print "<td><b>$text{'mailq_from'}</b></td>\n" if ($show{'From'});
        print "<td><b>$text{'mailq_to'}</b></td>\n" if ($show{'To'});
        print "<td><b>$text{'mailq_cc'}</b></td>\n" if ($show{'Cc'});
        print "<td><b>$text{'mailq_subject'}</b></td>\n" if ($show{'Subject'});
        print "<td><b>$text{'mailq_size'}</b></td>\n" if ($show{'Size'});
	print "<td><b>$text{'mailq_status'}</b></td>\n" if ($show{'Status'});
	print "</tr>\n";
	foreach $mail (@qmails) {
		local $f = $mail->{'file'};
		($n = $f) =~ s/^.*\///;
		$mail->{'header'}->{'from'} ||= $text{'mailq_unknown'};
		$mail->{'header'}->{'to'} ||= $text{'mailq_unknown'};
		$mail->{'header'}->{'date'} ||= $text{'mailq_unknown'};
		$mail->{'header'}->{'subject'} ||= $text{'mailq_unknown'};
		$mail->{'header'}->{'cc'} ||= "&nbsp;";
		$mail->{'status'} ||= $text{'mailq_sending'};

		$mail->{'header'}->{'from'} =
			&html_escape($mail->{'header'}->{'from'});
		$mail->{'header'}->{'to'} =
			&html_escape($mail->{'header'}->{'to'});
		$mail->{'header'}->{'date'} =~ s/\+.*//g;

		($d = $f) =~ s/\/qf/\/df/;
		if ($mail->{'size'} > 1000000) {
			$size = int($mail->{'size'} / 1000000)." MB";
			}
		elsif ($mail->{'size'} > 1000) {
			$size = int($mail->{'size'} / 1000)." kB";
			}
		else {
			$size = "$mail->{'size'} b";
			}
		print "<tr $cb>\n";
		if ($access{'mailq'} == 2) {
			print "<td><input type=checkbox name=file ",
			      "value=$f></td>\n";
			print "<td><a href=\"view_mailq.cgi?",
			      "file=$f\">$n</a></td>\n";
			}
		else {
			print "<td><font size=1>$n</font></td>\n";
			}
		print "<td><font size=1>$mail->{'header'}->{'date'}</font></td>\n" if ($show{'Date'});
		print "<td><font size=1>$mail->{'header'}->{'from'}</font></td>\n" if ($show{'From'});
		print "<td><font size=1>$mail->{'header'}->{'to'}</font></td>\n" if ($show{'To'});
		print "<td><font size=1>$mail->{'header'}->{'cc'}</font></td>\n" if ($show{'Cc'});
		print "<td><font size=1>$mail->{'header'}->{'subject'}</font></td>\n" if ($show{'Subject'});
		print "<td><font size=1>$size</font></td>\n" if ($show{'Size'});
		print "<td><font size=1>$mail->{'status'}</font></td>\n" if ($show{'Status'});
		print "</tr>\n";
		}
	print "</table>\n";
	print &select_all_link("file", 0, $text{'mail_all'}),"&nbsp;\n";
	print &select_invert_link("file", 0, $text{'mail_invert'}),"<p>\n";
	if ($access{'mailq'} == 2) {
		print "<input type=submit value='$text{'mailq_delete'}'>\n";
		print "<input type=checkbox name=locked value=1> $text{'mailq_locked'}<p>\n";
		}
	print "</form>\n";
	}
else {
	print "<b>$text{'searchq_none'}</b> <p>\n";
	}

&ui_print_footer("list_mailq.cgi", $text{'mailq_return'},
	"", $text{'index_return'});