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 not $top and $disposition eq 'attachment' and not defined($att);
101 return unless ($type =~ m[^text/?] and
102 $type !~ m[^text/(?:html|enriched)(?:;|$)]) or
103 $type =~ m[^application/pgp(?:;|$)] or
106 if ($entity->is_multipart) {
107 my @parts = $entity->parts;
108 foreach my $part (@parts) {
109 display_entity($part, $ref, 0, $xmessage,
110 $$this, @$attachments);
113 } elsif ($entity->parts) {
114 # We must be dealing with a nested message.
115 $$this .= "<blockquote>\n";
116 my @parts = $entity->parts;
117 foreach my $part (@parts) {
118 display_entity($part, $ref, 1, $xmessage,
119 $$this, @$attachments);
122 $$this .= "</blockquote>\n";
124 $$this .= htmlsanit($entity->bodyhandle->as_string) unless ($terse);
128 my %maintainer = %{getmaintainers()};
129 my %pkgsrc = %{getpkgsrc()};
141 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
142 $tail_html = $debbugs::gHTMLTail;
143 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
145 my %status = %{getbugstatus($ref)};
148 Content-Type: text/html
150 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
152 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
154 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
155 <p>There is no record of $debbugs::gBug $short.
156 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
157 $tail_html</body></html>
164 $tpack = lc $status{'package'};
165 my @tpacks = splitpackages($tpack);
167 if ($status{severity} eq 'normal') {
169 #} elsif (isstrongseverity($status{severity})) {
170 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
172 $showseverity = "Severity: <em>$status{severity}</em>;\n";
175 $indexentry .= "<p>$showseverity";
176 $indexentry .= htmlpackagelinks($status{package}, 0);
178 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
179 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
181 $indexentry .= "Owned by: " . htmlsanit($status{owner}) . ";\n"
182 if length $status{owner};
184 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
185 $indexentry .= "Date: ".$dummy.";\n<br>";
189 push @descstates, "Tags: <strong>"
190 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
192 if length($status{tags});
194 my @merged= split(/ /,$status{mergedwith});
196 my $descmerged = 'merged with ';
198 for my $m (@merged) {
199 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
202 push @descstates, $descmerged;
205 if (@{$status{found_versions}}) {
206 my $foundtext = 'Found in ';
207 $foundtext .= (@{$status{found_versions}} == 1) ? 'version ' : 'versions ';
208 $foundtext .= join ', ', map htmlsanit($_), @{$status{found_versions}};
209 push @descstates, $foundtext;
212 if (@{$status{fixed_versions}}) {
213 my $fixedtext = '<strong>Fixed</strong> in ';
214 $fixedtext .= (@{$status{fixed_versions}} == 1) ? 'version ' : 'versions ';
215 $fixedtext .= join ', ', map htmlsanit($_), @{$status{fixed_versions}};
216 if (length($status{done})) {
217 $fixedtext .= ' by ' . htmlsanit($status{done});
219 push @descstates, $fixedtext;
220 } elsif (length($status{done})) {
221 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
222 } elsif (length($status{forwarded})) {
223 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
226 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
228 $descriptivehead = $indexentry;
229 foreach my $pkg (@tpacks) {
230 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
231 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
234 htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
235 : "Maintainers for $pkg are\n" },
237 $descriptivehead .= ";\nSource for $pkg is\n".
238 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
239 $descriptivehead .= ".\n<br>";
242 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
243 if ($buglog !~ m#^\Q$gSpoolDir/db#) {
244 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
250 my $suppressnext = 0;
259 my $normstate= 'kill-init';
263 while(my $line = <L>) {
265 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
268 my $statenum = ord($line);
270 $newstate = 'autocheck' if ($statenum == 1);
271 $newstate = 'recips' if ($statenum == 2);
272 $newstate = 'kill-end' if ($statenum == 3);
273 $newstate = 'go' if ($statenum == 5);
274 $newstate = 'html' if ($statenum == 6);
275 $newstate = 'incoming-recv' if ($statenum == 7);
277 # disallowed transitions:
278 $_ = "$normstate $newstate";
279 unless (m/^(go|go-nox|html) kill-end$/
280 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
281 || m/^kill-body go$/)
283 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
286 #$this .= "\n<br>states: $normstate $newstate<br>\n";
288 # if ($newstate eq 'go') {
289 # $this .= "<pre>\n";
291 if ($newstate eq 'html') {
295 if ($newstate eq 'kill-end') {
299 if ($suppressnext && $normstate ne 'html');
301 $show = ($xmessage == $msg) if ($msg);
303 push @mails, join( '', @mail ) if ( $mbox && @mail );
305 if (not $mime and @mail) {
306 $this .= htmlsanit(join '', @mail);
308 my $parser = new MIME::Parser;
309 $parser->tmp_to_core(1);
310 $parser->output_to_core(1);
311 # $parser->output_under("/tmp");
312 my $entity = $parser->parse( new IO::Lines \@mail );
313 # TODO: make local subdir, clean it ourselves
314 # the following does NOT delete the msg dirs in /tmp
315 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
316 my @attachments = ();
317 display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
319 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
320 if ($normstate ne 'html') {
321 $this = "<pre>\n$this</pre>\n";
323 if ($normstate eq 'html') {
324 $this = "<a name=\"msg$xmessage\">$this <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em></a>";
326 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
328 my $delim = $terse ? "<p>" : "<hr>";
330 $log = "$this\n$delim$log";
332 $log .= "$this\n$delim\n";
336 $xmessage++ if ($normstate ne 'html');
338 $suppressnext = $normstate eq 'html';
342 $normstate = $newstate;
348 if ($normstate eq 'incoming-recv') {
351 m/^Received: \(at (\S+)\) by (\S+)\;/
352 || &quitcgi("bad line \`$pl' in state incoming-recv");
353 $thisheader = "<h2><a name=\"msg$xmessage\">"
354 . "Message received at ".htmlsanit("$1\@$2")
359 } elsif ($normstate eq 'html') {
361 } elsif ($normstate eq 'go') {
363 if (!$suppressnext && !$found_msgid &&
364 /^Message-ID: <(.*)>/i) {
367 if ($seen_msgid{$msgid}) {
370 $seen_msgid{$msgid} = 1;
376 $this .= htmlsanit($_);
378 } elsif ($normstate eq 'go-nox') {
380 if (!$suppressnext && !$found_msgid &&
381 /^Message-ID: <(.*)>/i) {
384 if ($seen_msgid{$msgid}) {
387 $seen_msgid{$msgid} = 1;
393 $this .= htmlsanit($_);
395 } elsif ($normstate eq 'recips') {
397 $thisheader = "<h2>Message sent:</h2>\n";
400 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
403 $normstate= 'kill-body';
404 } elsif ($normstate eq 'autocheck') {
405 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
406 $normstate= 'autowait';
407 $thisheader = "<h2>Message received at $2:</h2>\n";
410 } elsif ($normstate eq 'autowait') {
412 $normstate= 'go-nox';
414 &quitcgi("$ref state $normstate line \`$_'");
417 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
421 print "Content-Type: text/plain\n\n";
423 my @lines = split( "\n", $_, -1 );
424 if ( $lines[ 1 ] =~ m/^From / ) {
425 my $tmp = $lines[ 0 ];
426 $lines[ 0 ] = $lines[ 1 ];
429 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
430 my $date = strftime "%a %b %d %T %Y", localtime;
431 unshift @lines, "From unknown $date";
433 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
434 $_ = join( "\n", @lines ) . "\n";
436 print join("", @mails );
439 print "Content-Type: text/html\n\n";
441 my $title = htmlsanit($status{subject});
443 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
444 print "<HTML><HEAD>\n" .
445 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short - $title</TITLE>\n" .
447 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
449 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
450 "<BR>" . $title . "</H1>\n";
452 print "$descriptivehead\n";
453 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
458 print "</BODY></HTML>\n";