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);
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
103 $entity->is_multipart;
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);
113 $$this .= htmlsanit($entity->bodyhandle->as_string);
117 my %maintainer = %{getmaintainers()};
118 my %pkgsrc = %{getpkgsrc()};
130 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
131 $tail_html = $debbugs::gHTMLTail;
132 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
134 my %status = %{getbugstatus($ref)};
137 Content-Type: text/html
139 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
141 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
143 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
144 <p>There is no record of $debbugs::gBug $short.
145 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
146 $tail_html</body></html>
153 $tpack = lc $status{'package'};
154 my @tpacks = splitpackages($tpack);
156 if ($status{severity} eq 'normal') {
158 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
159 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
161 $showseverity = "Severity: <em>$status{severity}</em>;\n";
164 $indexentry .= "<p>$showseverity";
165 $indexentry .= htmlpackagelinks($status{package}, 0);
167 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
168 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
170 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
171 $indexentry .= "Date: ".$dummy.";\n<br>";
175 push @descstates, "Tags: <strong>"
176 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
178 if length($status{tags});
180 my @merged= split(/ /,$status{mergedwith});
182 my $descmerged = 'merged with ';
184 for my $m (@merged) {
185 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
188 push @descstates, $descmerged;
191 if (length($status{done})) {
192 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
193 } elsif (length($status{forwarded})) {
194 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
197 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
199 $descriptivehead = $indexentry;
200 foreach my $pkg (@tpacks) {
201 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
202 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
204 $descriptivehead .= "Maintainer for $pkg is\n".
205 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
206 $descriptivehead .= ";\nSource for $pkg is\n".
207 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
208 $descriptivehead .= ".\n<br>";
211 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
212 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
213 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
219 my $suppressnext = 0;
228 my $normstate= 'kill-init';
232 while(my $line = <L>) {
234 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
237 my $statenum = ord($line);
239 $newstate = 'autocheck' if ($statenum == 1);
240 $newstate = 'recips' if ($statenum == 2);
241 $newstate = 'kill-end' if ($statenum == 3);
242 $newstate = 'go' if ($statenum == 5);
243 $newstate = 'html' if ($statenum == 6);
244 $newstate = 'incoming-recv' if ($statenum == 7);
246 # disallowed transitions:
247 $_ = "$normstate $newstate";
248 unless (m/^(go|go-nox|html) kill-end$/
249 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
250 || m/^kill-body go$/)
252 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
255 #$this .= "\n<br>states: $normstate $newstate<br>\n";
257 # if ($newstate eq 'go') {
258 # $this .= "<pre>\n";
260 if ($newstate eq 'html') {
264 if ($newstate eq 'kill-end') {
268 if ($suppressnext && $normstate ne 'html');
270 $show = ($xmessage == $msg) if ($msg);
272 push @mails, join( '', @mail ) if ( $mbox && @mail );
274 if (not $mime and @mail) {
275 $this .= htmlsanit(join '', @mail);
277 my $parser = new MIME::Parser;
278 $parser->tmp_to_core(1);
279 $parser->output_to_core(1);
280 # $parser->output_under("/tmp");
281 my $entity = $parser->parse( new IO::Lines \@mail );
282 # TODO: make local subdir, clean it ourselves
283 # the following does NOT delete the msg dirs in /tmp
284 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
285 my @attachments = ();
286 display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
288 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
289 if ($normstate ne 'html') {
290 $this = "<pre>\n$this</pre>\n";
292 if ($normstate eq 'html') {
293 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
295 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
297 my $delim = $terse ? "<p>" : "<hr>";
299 $log = "$this\n$delim$log";
301 $log .= "$this\n$delim\n";
305 $xmessage++ if ($normstate ne 'html');
307 $suppressnext = $normstate eq 'html';
311 $normstate = $newstate;
317 if ($normstate eq 'incoming-recv') {
320 m/^Received: \(at (\S+)\) by (\S+)\;/
321 || &quitcgi("bad line \`$pl' in state incoming-recv");
322 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
327 } elsif ($normstate eq 'html') {
329 } elsif ($normstate eq 'go') {
331 if (!$suppressnext && !$found_msgid &&
332 /^Message-ID: <(.*)>/i) {
335 if ($seen_msgid{$msgid}) {
338 $seen_msgid{$msgid} = 1;
344 $this .= htmlsanit($_);
346 } elsif ($normstate eq 'go-nox') {
348 if (!$suppressnext && !$found_msgid &&
349 /^Message-ID: <(.*)>/i) {
352 if ($seen_msgid{$msgid}) {
355 $seen_msgid{$msgid} = 1;
361 $this .= htmlsanit($_);
363 } elsif ($normstate eq 'recips') {
365 $thisheader = "<h2>Message sent:</h2>\n";
368 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
371 $normstate= 'kill-body';
372 } elsif ($normstate eq 'autocheck') {
373 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
374 $normstate= 'autowait';
375 $thisheader = "<h2>Message received at $2:</h2>\n";
378 } elsif ($normstate eq 'autowait') {
380 $normstate= 'go-nox';
382 &quitcgi("$ref state $normstate line \`$_'");
385 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
389 print "Content-Type: text/plain\n\n";
391 my @lines = split( "\n", $_, -1 );
392 if ( $lines[ 1 ] =~ m/^From / ) {
393 my $tmp = $lines[ 0 ];
394 $lines[ 0 ] = $lines[ 1 ];
397 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
398 my $date = strftime "%a %b %d %T %Y", localtime;
399 unshift @lines, "From unknown $date";
401 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
402 $_ = join( "\n", @lines ) . "\n";
404 print join("", @mails );
407 print "Content-Type: text/html\n\n";
409 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
410 print "<HTML><HEAD>\n" .
411 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
413 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
415 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
416 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
418 print "$descriptivehead\n";
419 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
424 print "</BODY></HTML>\n";