6 use POSIX qw(strftime tzset);
12 #require '/usr/lib/debbugs/errorlib';
13 require './common.pl';
15 require '/etc/debbugs/config';
16 require '/etc/debbugs/text';
18 use vars(qw($gEmailDomain $gHTMLTail $gSpoolDir $gWebDomain));
20 my %param = readparse();
24 my $ref = $param{'bug'} || quitcgi("No bug number");
25 $ref =~ /(\d+)/ or quitcgi("Invalid bug number");
28 my $msg = $param{'msg'} || "";
29 my $att = $param{'att'};
30 my $boring = ($param{'boring'} || 'no') eq 'yes';
31 my $terse = ($param{'terse'} || 'no') eq 'yes';
32 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
33 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
35 my $buglog = buglog($ref);
37 if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
38 print "Content-Type: text/html\n";
39 my @stat = stat $buglog;
41 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
42 print "Last-Modified: $mtime\n";
48 my %maintainer = %{getmaintainers()};
49 my %pkgsrc = %{getpkgsrc()};
61 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
62 $tail_html = $debbugs::gHTMLTail;
63 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
65 my %status = %{getbugstatus($ref)};
68 Content-Type: text/html
70 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
72 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
74 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
75 <p>There is no record of $debbugs::gBug $short.
76 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
77 $tail_html</body></html>
84 $tpack = lc $status{'package'};
85 my @tpacks = splitpackages($tpack);
87 if ($status{severity} eq 'normal') {
89 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
90 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
92 $showseverity = "Severity: <em>$status{severity}</em>;\n";
95 $indexentry .= "<p>$showseverity";
96 $indexentry .= htmlpackagelinks($status{package}, 0);
98 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
99 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
101 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
102 $indexentry .= "Date: ".$dummy.";\n<br>";
106 push @descstates, "Tags: <strong>"
107 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
109 if length($status{tags});
111 my @merged= split(/ /,$status{mergedwith});
113 my $descmerged = 'merged with ';
115 for my $m (@merged) {
116 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
119 push @descstates, $descmerged;
122 if (length($status{done})) {
123 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
124 } elsif (length($status{forwarded})) {
125 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
128 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
130 $descriptivehead = $indexentry;
131 foreach my $pkg (@tpacks) {
132 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
133 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
135 $descriptivehead .= "Maintainer for $pkg is\n".
136 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
137 $descriptivehead .= ";\nSource for $pkg is\n".
138 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
139 $descriptivehead .= ".\n<br>";
142 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
143 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
144 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
150 my $suppressnext = 0;
157 my $normstate= 'kill-init';
161 while(my $line = <L>) {
163 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
166 my $statenum = ord($line);
168 $newstate = 'autocheck' if ($statenum == 1);
169 $newstate = 'recips' if ($statenum == 2);
170 $newstate = 'kill-end' if ($statenum == 3);
171 $newstate = 'go' if ($statenum == 5);
172 $newstate = 'html' if ($statenum == 6);
173 $newstate = 'incoming-recv' if ($statenum == 7);
175 # disallowed transitions:
176 $_ = "$normstate $newstate";
177 unless (m/^(go|go-nox|html) kill-end$/
178 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
179 || m/^kill-body go$/)
181 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
184 #$this .= "\n<br>states: $normstate $newstate<br>\n";
186 # if ($newstate eq 'go') {
187 # $this .= "<pre>\n";
189 if ($newstate eq 'html') {
193 if ($newstate eq 'kill-end') {
197 if ($suppressnext && $normstate ne 'html');
199 $show = ($xmessage == $msg) if ($msg);
201 push @mails, join( '', @mail ) if ( $mbox && @mail );
203 my $downloadHtml = '';
205 my $parser = new MIME::Parser;
206 $parser->tmp_to_core(1);
207 $parser->output_to_core(1);
208 # $parser->output_under("/tmp");
209 my $entity = $parser->parse( new IO::Lines \@mail );
210 # TODO: make local subdir, clean it outselves
211 # the following does NOT delete the msg dirs in /tmp
212 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
213 my @attachments = ();
214 if ( $entity->is_multipart ) {
215 my @parts = $entity->parts_DFS;
216 # $this .= htmlsanit($entity->head->stringify);
220 # $head->mime_attr("content-transfer-encoding" => "8bit")
221 # if !$head->mime_attr("content-transfer-encoding");
222 my ($disposition,$type) = (
223 $head->mime_attr("content-disposition"),
224 lc $head->mime_attr("content-type")
227 #print STDERR "'$type' '$disposition'\n";
228 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
229 push @attachments, $_;
230 my $file = $_->head->recommended_filename;
231 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
232 if ($msg && defined($att) && $att eq $#attachments) {
235 chomp($type = $head->mime_attr("content-type"));
236 my $body = $_->stringify_body;
237 print "Content-Type: $type; name=$file\n\n";
238 my $decoder = new MIME::Decoder($head->mime_encoding);
239 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
242 if ($type eq 'text/plain') {
245 # $this .= htmlsanit($_->head->stringify);
247 # $this .= htmlsanit($_->head->stringify);
250 # $this .= "\n" . htmlsanit($_->stringify_body);
252 # $entity->parts(\@keep) if (!$msg);
254 $this .= htmlsanit($entity->stringify);
256 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
257 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
258 if ($normstate ne 'html') {
259 $this = "<pre>\n$this</pre>\n";
261 if ($normstate eq 'html') {
262 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
264 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
265 $this = "$downloadHtml" if ($terse && $normstate ne 'html');
268 my $delim = $terse ? "<p>" : "<hr>";
270 $log = "$this\n$delim$log";
272 $log .= "$this\n$delim\n";
276 $xmessage++ if ($normstate ne 'html');
278 $suppressnext = $normstate eq 'html';
281 $normstate = $newstate;
287 if ($normstate eq 'incoming-recv') {
290 m/^Received: \(at (\S+)\) by (\S+)\;/
291 || &quitcgi("bad line \`$pl' in state incoming-recv");
292 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
297 } elsif ($normstate eq 'html') {
299 } elsif ($normstate eq 'go') {
304 $this .= htmlsanit($_);
306 } elsif ($normstate eq 'go-nox') {
311 $this .= htmlsanit($_);
313 } elsif ($normstate eq 'recips') {
315 $thisheader = "<h2>Message sent:</h2>\n";
318 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
321 $normstate= 'kill-body';
322 } elsif ($normstate eq 'autocheck') {
323 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
324 $normstate= 'autowait';
325 $thisheader = "<h2>Message received at $2:</h2>\n";
328 } elsif ($normstate eq 'autowait') {
330 $normstate= 'go-nox';
332 &quitcgi("$ref state $normstate line \`$_'");
335 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
339 print "Content-Type: text/plain\n\n";
341 my @lines = split( "\n", $_, -1 );
342 if ( $lines[ 1 ] =~ m/^From / ) {
343 my $tmp = $lines[ 0 ];
344 $lines[ 0 ] = $lines[ 1 ];
347 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
348 my $date = strftime "%a %b %d %T %Y", localtime;
349 unshift @lines, "From unknown $date";
351 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
352 $_ = join( "\n", @lines ) . "\n";
354 print join("", @mails );
357 print "Content-Type: text/html\n\n";
359 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
360 print "<HTML><HEAD>\n" .
361 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
363 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
365 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
366 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
368 print "$descriptivehead\n";
369 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
374 print "</BODY></HTML>\n";