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 # Not used by this script directly, but fetch these so that pkgurl() and
36 # friends can propagate them correctly.
37 my $archive = ($param{'archive'} || 'no') eq 'yes';
38 my $repeatmerged = ($param{'repeatmerged'} || 'yes') eq 'yes';
39 set_option('archive', $archive);
40 set_option('repeatmerged', $repeatmerged);
42 my $buglog = buglog($ref);
44 if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
45 print "Content-Type: text/html\n";
46 my @stat = stat $buglog;
48 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
49 print "Last-Modified: $mtime\n";
55 my %maintainer = %{getmaintainers()};
56 my %pkgsrc = %{getpkgsrc()};
68 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
69 $tail_html = $debbugs::gHTMLTail;
70 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
72 my %status = %{getbugstatus($ref)};
75 Content-Type: text/html
77 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
79 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
81 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
82 <p>There is no record of $debbugs::gBug $short.
83 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
84 $tail_html</body></html>
91 $tpack = lc $status{'package'};
92 my @tpacks = splitpackages($tpack);
94 if ($status{severity} eq 'normal') {
96 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
97 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
99 $showseverity = "Severity: <em>$status{severity}</em>;\n";
102 $indexentry .= "<p>$showseverity";
103 $indexentry .= htmlpackagelinks($status{package}, 0);
105 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
106 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
108 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
109 $indexentry .= "Date: ".$dummy.";\n<br>";
113 push @descstates, "Tags: <strong>"
114 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
116 if length($status{tags});
118 my @merged= split(/ /,$status{mergedwith});
120 my $descmerged = 'merged with ';
122 for my $m (@merged) {
123 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
126 push @descstates, $descmerged;
129 if (length($status{done})) {
130 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
131 } elsif (length($status{forwarded})) {
132 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
135 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
137 $descriptivehead = $indexentry;
138 foreach my $pkg (@tpacks) {
139 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
140 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
142 $descriptivehead .= "Maintainer for $pkg is\n".
143 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
144 $descriptivehead .= ";\nSource for $pkg is\n".
145 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
146 $descriptivehead .= ".\n<br>";
149 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
150 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
151 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
157 my $suppressnext = 0;
166 my $normstate= 'kill-init';
170 while(my $line = <L>) {
172 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
175 my $statenum = ord($line);
177 $newstate = 'autocheck' if ($statenum == 1);
178 $newstate = 'recips' if ($statenum == 2);
179 $newstate = 'kill-end' if ($statenum == 3);
180 $newstate = 'go' if ($statenum == 5);
181 $newstate = 'html' if ($statenum == 6);
182 $newstate = 'incoming-recv' if ($statenum == 7);
184 # disallowed transitions:
185 $_ = "$normstate $newstate";
186 unless (m/^(go|go-nox|html) kill-end$/
187 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
188 || m/^kill-body go$/)
190 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
193 #$this .= "\n<br>states: $normstate $newstate<br>\n";
195 # if ($newstate eq 'go') {
196 # $this .= "<pre>\n";
198 if ($newstate eq 'html') {
202 if ($newstate eq 'kill-end') {
206 if ($suppressnext && $normstate ne 'html');
208 $show = ($xmessage == $msg) if ($msg);
210 push @mails, join( '', @mail ) if ( $mbox && @mail );
212 my $downloadHtml = '';
214 my $parser = new MIME::Parser;
215 $parser->tmp_to_core(1);
216 $parser->output_to_core(1);
217 # $parser->output_under("/tmp");
218 my $entity = $parser->parse( new IO::Lines \@mail );
219 # TODO: make local subdir, clean it outselves
220 # the following does NOT delete the msg dirs in /tmp
221 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
222 my @attachments = ();
223 if ( $entity->is_multipart ) {
224 my @parts = $entity->parts_DFS;
225 # $this .= htmlsanit($entity->head->stringify);
229 # $head->mime_attr("content-transfer-encoding" => "8bit")
230 # if !$head->mime_attr("content-transfer-encoding");
231 my ($disposition,$type) = (
232 $head->mime_attr("content-disposition"),
233 lc $head->mime_attr("content-type")
236 #print STDERR "'$type' '$disposition'\n";
237 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
238 push @attachments, $_;
239 my $file = $_->head->recommended_filename;
240 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
241 if ($msg && defined($att) && $att eq $#attachments) {
244 chomp($type = $head->mime_attr("content-type"));
245 my $body = $_->stringify_body;
246 print "Content-Type: $type; name=$file\n\n";
247 my $decoder = new MIME::Decoder($head->mime_encoding);
248 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
251 if ($type eq 'text/plain') {
254 # $this .= htmlsanit($_->head->stringify);
256 # $this .= htmlsanit($_->head->stringify);
259 # $this .= "\n" . htmlsanit($_->stringify_body);
261 # $entity->parts(\@keep) if (!$msg);
263 $this .= htmlsanit($entity->stringify);
265 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
266 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
267 if ($normstate ne 'html') {
268 $this = "<pre>\n$this</pre>\n";
270 if ($normstate eq 'html') {
271 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
273 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
274 $this = "$downloadHtml" if ($terse && $normstate ne 'html');
277 my $delim = $terse ? "<p>" : "<hr>";
279 $log = "$this\n$delim$log";
281 $log .= "$this\n$delim\n";
285 $xmessage++ if ($normstate ne 'html');
287 $suppressnext = $normstate eq 'html';
291 $normstate = $newstate;
297 if ($normstate eq 'incoming-recv') {
300 m/^Received: \(at (\S+)\) by (\S+)\;/
301 || &quitcgi("bad line \`$pl' in state incoming-recv");
302 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
307 } elsif ($normstate eq 'html') {
309 } elsif ($normstate eq 'go') {
311 if (!$suppressnext && !$found_msgid &&
312 /^Message-ID: <(.*)>/i) {
315 if ($seen_msgid{$msgid}) {
318 $seen_msgid{$msgid} = 1;
324 $this .= htmlsanit($_);
326 } elsif ($normstate eq 'go-nox') {
328 if (!$suppressnext && !$found_msgid &&
329 /^Message-ID: <(.*)>/i) {
332 if ($seen_msgid{$msgid}) {
335 $seen_msgid{$msgid} = 1;
341 $this .= htmlsanit($_);
343 } elsif ($normstate eq 'recips') {
345 $thisheader = "<h2>Message sent:</h2>\n";
348 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
351 $normstate= 'kill-body';
352 } elsif ($normstate eq 'autocheck') {
353 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
354 $normstate= 'autowait';
355 $thisheader = "<h2>Message received at $2:</h2>\n";
358 } elsif ($normstate eq 'autowait') {
360 $normstate= 'go-nox';
362 &quitcgi("$ref state $normstate line \`$_'");
365 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
369 print "Content-Type: text/plain\n\n";
371 my @lines = split( "\n", $_, -1 );
372 if ( $lines[ 1 ] =~ m/^From / ) {
373 my $tmp = $lines[ 0 ];
374 $lines[ 0 ] = $lines[ 1 ];
377 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
378 my $date = strftime "%a %b %d %T %Y", localtime;
379 unshift @lines, "From unknown $date";
381 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
382 $_ = join( "\n", @lines ) . "\n";
384 print join("", @mails );
387 print "Content-Type: text/html\n\n";
389 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
390 print "<HTML><HEAD>\n" .
391 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
393 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
395 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
396 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
398 print "$descriptivehead\n";
399 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
404 print "</BODY></HTML>\n";