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';
34 my $mime = ($param{'mime'} || 'yes') eq 'yes';
36 # Not used by this script directly, but fetch these so that pkgurl() and
37 # friends can propagate them correctly.
38 my $archive = ($param{'archive'} || 'no') eq 'yes';
39 my $repeatmerged = ($param{'repeatmerged'} || 'yes') eq 'yes';
40 set_option('archive', $archive);
41 set_option('repeatmerged', $repeatmerged);
43 my $buglog = buglog($ref);
45 if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
46 print "Content-Type: text/html\n";
47 my @stat = stat $buglog;
49 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
50 print "Last-Modified: $mtime\n";
56 sub display_entity ($$$$\$\@);
57 sub display_entity ($$$$\$\@) {
63 my $attachments = shift;
65 my $head = $entity->head;
66 my $disposition = $head->mime_attr('content-disposition');
67 $disposition = 'inline' if not defined $disposition or $disposition eq '';
68 my $type = $entity->effective_type;
69 my $filename = $entity->head->recommended_filename;
70 $filename = '' unless defined $filename;
73 $$this .= htmlsanit($entity->stringify_header) unless ($terse);
77 unless (($top and $type =~ m[^text(?:/plain)?(?:;|$)]) or
78 ($type =~ m[^multipart/])) {
79 push @$attachments, $entity;
80 my @dlargs = ($ref, "msg=$xmessage", "att=$#$attachments");
81 push @dlargs, "filename=$filename" if $filename ne '';
82 my $printname = $filename;
83 $printname = 'Message part ' . ($#$attachments + 1) if $filename eq '';
84 $$this .= '[<a href="' . dlurl(@dlargs) . qq{">$printname</a> } .
85 "($type, $disposition)]\n\n";
87 if ($msg and defined($att) and $att eq $#$attachments) {
88 my $head = $entity->head;
89 chomp(my $type = $entity->effective_type);
90 my $body = $entity->stringify_body;
91 print "Content-Type: $type";
92 print "; name=$filename" if $filename ne '';
94 my $decoder = new MIME::Decoder($head->mime_encoding);
95 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
100 return if $disposition eq 'attachment' and not defined($att);
101 return unless ($type =~ m[^text/?] and $type !~ m[^text/html(?:;|$)]) or
102 $type =~ m[^application/pgp(?:;|$)] or
105 if ($entity->is_multipart) {
106 my @parts = $entity->parts;
107 foreach my $part (@parts) {
108 display_entity($part, $ref, 0, $xmessage,
109 $$this, @$attachments);
112 } elsif ($entity->parts) {
113 # We must be dealing with a nested message.
114 $$this .= "<blockquote>\n";
115 my @parts = $entity->parts;
116 foreach my $part (@parts) {
117 display_entity($part, $ref, 1, $xmessage,
118 $$this, @$attachments);
121 $$this .= "</blockquote>\n";
123 $$this .= htmlsanit($entity->bodyhandle->as_string) unless ($terse);
127 my %maintainer = %{getmaintainers()};
128 my %pkgsrc = %{getpkgsrc()};
140 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
141 $tail_html = $debbugs::gHTMLTail;
142 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
144 my %status = %{getbugstatus($ref)};
147 Content-Type: text/html
149 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
151 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
153 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
154 <p>There is no record of $debbugs::gBug $short.
155 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
156 $tail_html</body></html>
163 $tpack = lc $status{'package'};
164 my @tpacks = splitpackages($tpack);
166 if ($status{severity} eq 'normal') {
168 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
169 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
171 $showseverity = "Severity: <em>$status{severity}</em>;\n";
174 $indexentry .= "<p>$showseverity";
175 $indexentry .= htmlpackagelinks($status{package}, 0);
177 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
178 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
180 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
181 $indexentry .= "Date: ".$dummy.";\n<br>";
185 push @descstates, "Tags: <strong>"
186 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
188 if length($status{tags});
190 my @merged= split(/ /,$status{mergedwith});
192 my $descmerged = 'merged with ';
194 for my $m (@merged) {
195 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
198 push @descstates, $descmerged;
201 if (length($status{done})) {
202 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
203 } elsif (length($status{forwarded})) {
204 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
207 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
209 $descriptivehead = $indexentry;
210 foreach my $pkg (@tpacks) {
211 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
212 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
214 $descriptivehead .= "Maintainer for $pkg is\n".
215 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
216 $descriptivehead .= ";\nSource for $pkg is\n".
217 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
218 $descriptivehead .= ".\n<br>";
221 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
222 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
223 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
229 my $suppressnext = 0;
238 my $normstate= 'kill-init';
242 while(my $line = <L>) {
244 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
247 my $statenum = ord($line);
249 $newstate = 'autocheck' if ($statenum == 1);
250 $newstate = 'recips' if ($statenum == 2);
251 $newstate = 'kill-end' if ($statenum == 3);
252 $newstate = 'go' if ($statenum == 5);
253 $newstate = 'html' if ($statenum == 6);
254 $newstate = 'incoming-recv' if ($statenum == 7);
256 # disallowed transitions:
257 $_ = "$normstate $newstate";
258 unless (m/^(go|go-nox|html) kill-end$/
259 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
260 || m/^kill-body go$/)
262 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
265 #$this .= "\n<br>states: $normstate $newstate<br>\n";
267 # if ($newstate eq 'go') {
268 # $this .= "<pre>\n";
270 if ($newstate eq 'html') {
274 if ($newstate eq 'kill-end') {
278 if ($suppressnext && $normstate ne 'html');
280 $show = ($xmessage == $msg) if ($msg);
282 push @mails, join( '', @mail ) if ( $mbox && @mail );
284 if (not $mime and @mail) {
285 $this .= htmlsanit(join '', @mail);
287 my $parser = new MIME::Parser;
288 $parser->tmp_to_core(1);
289 $parser->output_to_core(1);
290 # $parser->output_under("/tmp");
291 my $entity = $parser->parse( new IO::Lines \@mail );
292 # TODO: make local subdir, clean it ourselves
293 # the following does NOT delete the msg dirs in /tmp
294 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
295 my @attachments = ();
296 display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
298 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
299 if ($normstate ne 'html') {
300 $this = "<pre>\n$this</pre>\n";
302 if ($normstate eq 'html') {
303 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
305 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
307 my $delim = $terse ? "<p>" : "<hr>";
309 $log = "$this\n$delim$log";
311 $log .= "$this\n$delim\n";
315 $xmessage++ if ($normstate ne 'html');
317 $suppressnext = $normstate eq 'html';
321 $normstate = $newstate;
327 if ($normstate eq 'incoming-recv') {
330 m/^Received: \(at (\S+)\) by (\S+)\;/
331 || &quitcgi("bad line \`$pl' in state incoming-recv");
332 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
337 } elsif ($normstate eq 'html') {
339 } elsif ($normstate eq 'go') {
341 if (!$suppressnext && !$found_msgid &&
342 /^Message-ID: <(.*)>/i) {
345 if ($seen_msgid{$msgid}) {
348 $seen_msgid{$msgid} = 1;
354 $this .= htmlsanit($_);
356 } elsif ($normstate eq 'go-nox') {
358 if (!$suppressnext && !$found_msgid &&
359 /^Message-ID: <(.*)>/i) {
362 if ($seen_msgid{$msgid}) {
365 $seen_msgid{$msgid} = 1;
371 $this .= htmlsanit($_);
373 } elsif ($normstate eq 'recips') {
375 $thisheader = "<h2>Message sent:</h2>\n";
378 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
381 $normstate= 'kill-body';
382 } elsif ($normstate eq 'autocheck') {
383 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
384 $normstate= 'autowait';
385 $thisheader = "<h2>Message received at $2:</h2>\n";
388 } elsif ($normstate eq 'autowait') {
390 $normstate= 'go-nox';
392 &quitcgi("$ref state $normstate line \`$_'");
395 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
399 print "Content-Type: text/plain\n\n";
401 my @lines = split( "\n", $_, -1 );
402 if ( $lines[ 1 ] =~ m/^From / ) {
403 my $tmp = $lines[ 0 ];
404 $lines[ 0 ] = $lines[ 1 ];
407 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
408 my $date = strftime "%a %b %d %T %Y", localtime;
409 unshift @lines, "From unknown $date";
411 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
412 $_ = join( "\n", @lines ) . "\n";
414 print join("", @mails );
417 print "Content-Type: text/html\n\n";
419 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
420 print "<HTML><HEAD>\n" .
421 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
423 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
425 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
426 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
428 print "$descriptivehead\n";
429 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
434 print "</BODY></HTML>\n";