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; charset=utf-8\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;
71 $filename = decode_rfc1522($filename);
74 $$this .= htmlsanit(decode_rfc1522($entity->stringify_header))
79 unless (($top and $type =~ m[^text(?:/plain)?(?:;|$)]) or
80 ($type =~ m[^multipart/])) {
81 push @$attachments, $entity;
82 my @dlargs = ($ref, "msg=$xmessage", "att=$#$attachments");
83 push @dlargs, "filename=$filename" if $filename ne '';
84 my $printname = $filename;
85 $printname = 'Message part ' . ($#$attachments + 1) if $filename eq '';
86 $$this .= '[<a href="' . dlurl(@dlargs) . qq{">$printname</a> } .
87 "($type, $disposition)]\n\n";
89 if ($msg and defined($att) and $att eq $#$attachments) {
90 my $head = $entity->head;
91 chomp(my $type = $entity->effective_type);
92 my $body = $entity->stringify_body;
93 print "Content-Type: $type\n";
94 if ($filename ne '') {
98 print qq{Content-Disposition: attachment; filename="$qf"\n};
101 my $decoder = new MIME::Decoder($head->mime_encoding);
102 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
107 return if not $top and $disposition eq 'attachment' and not defined($att);
108 return unless ($type =~ m[^text/?] and
109 $type !~ m[^text/(?:html|enriched)(?:;|$)]) or
110 $type =~ m[^application/pgp(?:;|$)] or
113 if ($entity->is_multipart) {
114 my @parts = $entity->parts;
115 foreach my $part (@parts) {
116 display_entity($part, $ref, 0, $xmessage,
117 $$this, @$attachments);
120 } elsif ($entity->parts) {
121 # We must be dealing with a nested message.
122 $$this .= "<blockquote>\n";
123 my @parts = $entity->parts;
124 foreach my $part (@parts) {
125 display_entity($part, $ref, 1, $xmessage,
126 $$this, @$attachments);
129 $$this .= "</blockquote>\n";
131 $$this .= htmlsanit($entity->bodyhandle->as_string) unless ($terse);
135 my %maintainer = %{getmaintainers()};
136 my %pkgsrc = %{getpkgsrc()};
148 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
149 $tail_html = $debbugs::gHTMLTail;
150 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
152 my %status = %{getbugstatus($ref)};
155 Content-Type: text/html; charset=utf-8
157 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
159 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
161 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
162 <p>There is no record of $debbugs::gBug $short.
163 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
164 $tail_html</body></html>
171 $tpack = lc $status{'package'};
172 my @tpacks = splitpackages($tpack);
174 if ($status{severity} eq 'normal') {
176 #} elsif (isstrongseverity($status{severity})) {
177 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
179 $showseverity = "Severity: <em>$status{severity}</em>;\n";
182 $indexentry .= "<p>$showseverity";
183 $indexentry .= htmlpackagelinks($status{package}, 0) . ";\n";
185 $indexentry .= htmladdresslinks("Reported by: ", \&submitterurl,
186 $status{originator}) . ";\n";
188 $indexentry .= "Owned by: " . htmlsanit($status{owner}) . ";\n"
189 if length $status{owner};
191 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
192 $indexentry .= "Date: ".$dummy.";\n<br>";
196 push @descstates, "Tags: <strong>"
197 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
199 if length($status{tags});
201 my @merged= split(/ /,$status{mergedwith});
203 my $descmerged = 'merged with ';
205 for my $m (@merged) {
206 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
209 push @descstates, $descmerged;
212 if (@{$status{found_versions}}) {
213 my $foundtext = 'Found in ';
214 $foundtext .= (@{$status{found_versions}} == 1) ? 'version ' : 'versions ';
215 $foundtext .= join ', ', map htmlsanit($_), @{$status{found_versions}};
216 push @descstates, $foundtext;
219 if (@{$status{fixed_versions}}) {
220 my $fixedtext = '<strong>Fixed</strong> in ';
221 $fixedtext .= (@{$status{fixed_versions}} == 1) ? 'version ' : 'versions ';
222 $fixedtext .= join ', ', map htmlsanit($_), @{$status{fixed_versions}};
223 if (length($status{done})) {
224 $fixedtext .= ' by ' . htmlsanit($status{done});
226 push @descstates, $fixedtext;
227 } elsif (length($status{done})) {
228 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
229 } elsif (length($status{forwarded})) {
230 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
233 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
235 $descriptivehead = $indexentry;
236 foreach my $pkg (@tpacks) {
237 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
238 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
241 htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
242 : "Maintainers for $pkg are\n" },
244 $descriptivehead .= ";\nSource for $pkg is\n".
245 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
246 $descriptivehead .= ".\n<br>";
249 if ($buglog =~ m/\.gz$/) {
250 my $oldpath = $ENV{'PATH'};
251 $ENV{'PATH'} = '/bin:/usr/bin';
252 open L, "zcat $buglog |" or &quitcgi("open log for $ref: $!");
253 $ENV{'PATH'} = $oldpath;
255 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
257 if ($buglog !~ m#^\Q$gSpoolDir/db#) {
258 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
264 my $suppressnext = 0;
273 my $normstate= 'kill-init';
277 while(my $line = <L>) {
279 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
282 my $statenum = ord($line);
284 $newstate = 'autocheck' if ($statenum == 1);
285 $newstate = 'recips' if ($statenum == 2);
286 $newstate = 'kill-end' if ($statenum == 3);
287 $newstate = 'go' if ($statenum == 5);
288 $newstate = 'html' if ($statenum == 6);
289 $newstate = 'incoming-recv' if ($statenum == 7);
291 # disallowed transitions:
292 $_ = "$normstate $newstate";
293 unless (m/^(go|go-nox|html) kill-end$/
294 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
295 || m/^kill-body go$/)
297 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
300 #$this .= "\n<br>states: $normstate $newstate<br>\n";
302 # if ($newstate eq 'go') {
303 # $this .= "<pre>\n";
305 if ($newstate eq 'html') {
309 if ($newstate eq 'kill-end') {
313 if ($suppressnext && $normstate ne 'html');
315 $show = ($xmessage == $msg) if ($msg);
317 push @mails, join( '', @mail ) if ( $mbox && @mail );
319 if (not $mime and @mail) {
320 $this .= htmlsanit(join '', @mail);
322 my $parser = new MIME::Parser;
323 $parser->tmp_to_core(1);
324 $parser->output_to_core(1);
325 # $parser->output_under("/tmp");
326 my $entity = $parser->parse( new IO::Lines \@mail );
327 # TODO: make local subdir, clean it ourselves
328 # the following does NOT delete the msg dirs in /tmp
329 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
330 my @attachments = ();
331 display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
333 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
334 if ($normstate ne 'html') {
335 $this = "<pre>\n$this</pre>\n";
337 if ($normstate eq 'html') {
338 $this = "<a name=\"msg$xmessage\">$this <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em></a>";
340 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
342 my $delim = $terse ? "<p>" : "<hr>";
344 $log = "$this\n$delim$log";
346 $log .= "$this\n$delim\n";
350 $xmessage++ if ($normstate ne 'html');
352 $suppressnext = $normstate eq 'html';
356 $normstate = $newstate;
362 if ($normstate eq 'incoming-recv') {
365 m/^Received: \(at (\S+)\) by (\S+)\;/
366 || &quitcgi("bad line \`$pl' in state incoming-recv");
367 $thisheader = "<h2><a name=\"msg$xmessage\">"
368 . "Message received at ".htmlsanit("$1\@$2")
373 } elsif ($normstate eq 'html') {
375 } elsif ($normstate eq 'go') {
377 if (!$suppressnext && !$found_msgid &&
378 /^Message-ID: <(.*)>/i) {
381 if ($seen_msgid{$msgid}) {
384 $seen_msgid{$msgid} = 1;
390 $this .= htmlsanit($_);
392 } elsif ($normstate eq 'go-nox') {
394 if (!$suppressnext && !$found_msgid &&
395 /^Message-ID: <(.*)>/i) {
398 if ($seen_msgid{$msgid}) {
401 $seen_msgid{$msgid} = 1;
407 $this .= htmlsanit($_);
409 } elsif ($normstate eq 'recips') {
411 $thisheader = "<h2>Message sent:</h2>\n";
414 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
417 $normstate= 'kill-body';
418 } elsif ($normstate eq 'autocheck') {
419 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
420 $normstate= 'autowait';
421 $thisheader = "<h2>Message received at $2:</h2>\n";
424 } elsif ($normstate eq 'autowait') {
426 $normstate= 'go-nox';
428 &quitcgi("$ref state $normstate line \`$_'");
431 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
435 print "Content-Type: text/plain\n\n";
437 my @lines = split( "\n", $_, -1 );
438 if ( $lines[ 1 ] =~ m/^From / ) {
439 my $tmp = $lines[ 0 ];
440 $lines[ 0 ] = $lines[ 1 ];
443 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
444 my $date = strftime "%a %b %d %T %Y", localtime;
445 unshift @lines, "From unknown $date";
447 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
448 $_ = join( "\n", @lines ) . "\n";
450 print join("", @mails );
453 print "Content-Type: text/html; charset=utf-8\n\n";
455 my $title = htmlsanit($status{subject});
457 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
458 print "<HTML><HEAD>\n" .
459 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short - $title</TITLE>\n" .
461 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
463 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
464 "<BR>" . $title . "</H1>\n";
466 print "$descriptivehead\n";
467 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
472 print "</BODY></HTML>\n";