Handle hostnames with upper-case letters
[webmin.git] / sendmail / view_mailq.cgi
1 #!/usr/local/bin/perl
2 # view_mailq.cgi
3 # Display some message from the mail queue
4
5 require './sendmail-lib.pl';
6 require './boxes-lib.pl';
7 &ReadParse();
8 $access{'mailq'} || &error($text{'mailq_ecannot'});
9 $in{'file'} =~ /\.\./ && &error($text{'mailq_ecannot'});
10 $conf = &get_sendmailcf();
11 foreach $mqueue (&mailq_dir($conf)) {
12         $ok++ if ($in{'file'} =~ /^$mqueue\//);
13         }
14 $ok || &error($text{'mailq_ecannot'});
15
16 $qfile = $in{'file'};
17 $mail = &mail_from_queue($qfile, "auto");
18 $mail || &error($text{'view_egone'});
19 &can_view_qfile($mail) || &error($text{'mailq_ecannot'});
20 &parse_mail($mail);
21 @sub = split(/\0/, $in{'sub'});
22 $subs = join("", map { "&sub=$_" } @sub);
23 foreach $s (@sub) {
24         # We are looking at a mail within a mail ..
25         local $amail = &extract_mail($mail->{'attach'}->[$s]->{'data'});
26         &parse_mail($amail);
27         $mail = $amail;
28         }
29
30 ($name = $in{'file'}) =~ s/^.*\///;
31 if (!@sub) {
32         $desc = &text('view_qdesc', "<tt>$name</tt>");
33         }
34 else {
35         $desc = $text{'view_sub'};
36         }
37 &ui_print_header($desc, $text{'view_title'}, "");
38
39 print &ui_form_start("del_mailq.cgi");
40 if (!@sub && $config{'top_buttons'} == 2) {
41         print &ui_submit($text{'view_delete'}, "delete");
42         print &ui_submit($text{'view_flush'}, "flush");
43         print "<p>\n";
44         }
45 print &ui_hidden("file", $in{'file'});
46
47 # Start of headers section
48 if ($in{'headers'}) {
49         $rlink = "<a href='view_mailq.cgi?file=$in{'file'}&headers=0$subs'>$text{'view_noheaders'}</a>";
50         }
51 else {
52         $rlink = "<a href='view_mailq.cgi?file=$in{'file'}&headers=1$subs'>$text{'view_allheaders'}</a>";
53         }
54 print &ui_table_start($text{'view_headers'}, "width=100%", 2, undef, $rlink);
55
56 if ($in{'headers'}) {
57         # Show all the headers
58         if ($mail->{'fromline'}) {
59                 print &ui_table_row($text{'mail_rfc'},
60                                     &html_escape($mail->{'fromline'}));
61                 }
62         foreach $h (@{$mail->{'headers'}}) {
63                 print &ui_table_row($h->[0],
64                         &html_escape(&decode_mimewords($h->[1])));
65                 }
66         }
67 else {
68         # Just show the most useful headers
69         print &ui_table_row($text{'mail_from'},
70                 &html_escape($mail->{'header'}->{'from'}));
71         print &ui_table_row($text{'mail_to'},
72                 &html_escape($mail->{'header'}->{'to'}));
73         print &ui_table_row($text{'mail_cc'},
74                 &html_escape($mail->{'header'}->{'cc'}))
75                 if ($mail->{'header'}->{'cc'});
76         print &ui_table_row($text{'mail_date'},
77                 &html_escape($mail->{'header'}->{'date'}));
78         print &ui_table_row($text{'mail_subject'},
79                 &html_escape($mail->{'header'}->{'subject'}));
80         }
81 print &ui_table_end();
82
83 # Find body attachment
84 @attach = @{$mail->{'attach'}};
85 foreach $a (@attach) {
86         if ($a->{'type'} eq 'text/plain') {
87                 $body = $a;
88                 last;
89                 }
90         }
91 if ($body) {
92         print &ui_table_start($text{'view_body'}, "width=100%", 2);
93         $bodyhtml = "";
94         foreach $l (&wrap_lines($body->{'data'}, $config{'wrap_width'})) {
95                 $bodyhtml .= &link_urls_and_escape($l)."\n";
96                 }
97         print &ui_table_row(undef, "<pre>".$bodyhtml."</pre>", 2);
98         print &ui_table_end();
99         }
100
101 # Display other attachments
102 @attach = grep { $_ ne $body } @attach;
103 @attach = grep { !$_->{'attach'} } @attach;
104 if (@attach) {
105         print &ui_columns_start([ $text{'view_afile'}, $text{'view_atype'},
106                                   $text{'view_asize'} ], 100, 0);
107         foreach $a (@attach) {
108                 if ($a->{'type'} eq 'message/rfc822') {
109                         print &ui_columns_row([
110                                 "<a href='view_mailq.cgi?file=$qfile$subs&sub=$a->{'idx'}'>$text{'view_sub'}</a>",
111                                 undef,
112                                 &nice_size(length($a->{'data'})),
113                                 ]);
114                         }
115                 else {
116                         print &ui_columns_row([
117                                 "<a href='qdetach.cgi/$a->{'filename'}?file=$qfile&attach=$a->{'idx'}$subs'>$a->{'filename'}</a>",
118                                 $a->{'type'},
119                                 &nice_size(length($a->{'data'})),
120                                 ]);
121                         }
122                 }
123         print &ui_columns_end();
124         }
125
126 # Display buttons
127 if (!@sub) {
128         print &ui_submit($text{'view_delete'}, "delete");
129         print &ui_submit($text{'view_flush'}, "flush");
130         }
131 print &ui_form_end();
132
133 &ui_print_footer(!@sub ? ( ) : ( "view_mailq.cgi?file=$qfile", $text{'view_return'} ),
134         "list_mailq.cgi", $text{'mailq_return'},
135         "", $text{'index_return'});
136