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