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 my $buglog = buglog($ref);
37 if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
38 print "Content-Type: text/html\n";
39 my @stat = stat $buglog;
41 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
42 print "Last-Modified: $mtime\n";
48 my %maintainer = %{getmaintainers()};
49 my %pkgsrc = %{getpkgsrc()};
61 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
62 $tail_html = $debbugs::gHTMLTail;
63 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
65 my %status = %{getbugstatus($ref)};
68 Content-Type: text/html
70 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
72 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
74 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
75 <p>There is no record of $debbugs::gBug $short.
76 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
77 $tail_html</body></html>
84 $tpack = lc $status{'package'};
85 my @tpacks = splitpackages($tpack);
87 if ($status{severity} eq 'normal') {
89 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
90 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
92 $showseverity = "Severity: <em>$status{severity}</em>;\n";
95 $indexentry .= "<p>$showseverity";
96 $indexentry .= htmlpackagelinks($status{package}, 0);
98 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
99 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
101 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
102 $indexentry .= "Date: ".$dummy.";\n<br>";
106 push @descstates, "Tags: <strong>"
107 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
109 if length($status{tags});
111 my @merged= split(/ /,$status{mergedwith});
113 my $descmerged = 'merged with ';
115 for my $m (@merged) {
116 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
119 push @descstates, $descmerged;
122 if (length($status{done})) {
123 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
124 } elsif (length($status{forwarded})) {
125 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
128 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
130 $descriptivehead = $indexentry;
131 foreach my $pkg (@tpacks) {
132 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
133 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
135 $descriptivehead .= "Maintainer for $pkg is\n".
136 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
137 $descriptivehead .= ";\nSource for $pkg is\n".
138 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
139 $descriptivehead .= ".\n<br>";
142 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
143 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
144 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
150 my $suppressnext = 0;
159 my $normstate= 'kill-init';
163 while(my $line = <L>) {
165 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
168 my $statenum = ord($line);
170 $newstate = 'autocheck' if ($statenum == 1);
171 $newstate = 'recips' if ($statenum == 2);
172 $newstate = 'kill-end' if ($statenum == 3);
173 $newstate = 'go' if ($statenum == 5);
174 $newstate = 'html' if ($statenum == 6);
175 $newstate = 'incoming-recv' if ($statenum == 7);
177 # disallowed transitions:
178 $_ = "$normstate $newstate";
179 unless (m/^(go|go-nox|html) kill-end$/
180 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
181 || m/^kill-body go$/)
183 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
186 #$this .= "\n<br>states: $normstate $newstate<br>\n";
188 # if ($newstate eq 'go') {
189 # $this .= "<pre>\n";
191 if ($newstate eq 'html') {
195 if ($newstate eq 'kill-end') {
199 if ($suppressnext && $normstate ne 'html');
201 $show = ($xmessage == $msg) if ($msg);
203 push @mails, join( '', @mail ) if ( $mbox && @mail );
205 my $downloadHtml = '';
207 my $parser = new MIME::Parser;
208 $parser->tmp_to_core(1);
209 $parser->output_to_core(1);
210 # $parser->output_under("/tmp");
211 my $entity = $parser->parse( new IO::Lines \@mail );
212 # TODO: make local subdir, clean it outselves
213 # the following does NOT delete the msg dirs in /tmp
214 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
215 my @attachments = ();
216 if ( $entity->is_multipart ) {
217 my @parts = $entity->parts_DFS;
218 # $this .= htmlsanit($entity->head->stringify);
222 # $head->mime_attr("content-transfer-encoding" => "8bit")
223 # if !$head->mime_attr("content-transfer-encoding");
224 my ($disposition,$type) = (
225 $head->mime_attr("content-disposition"),
226 lc $head->mime_attr("content-type")
229 #print STDERR "'$type' '$disposition'\n";
230 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
231 push @attachments, $_;
232 my $file = $_->head->recommended_filename;
233 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
234 if ($msg && defined($att) && $att eq $#attachments) {
237 chomp($type = $head->mime_attr("content-type"));
238 my $body = $_->stringify_body;
239 print "Content-Type: $type; name=$file\n\n";
240 my $decoder = new MIME::Decoder($head->mime_encoding);
241 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
244 if ($type eq 'text/plain') {
247 # $this .= htmlsanit($_->head->stringify);
249 # $this .= htmlsanit($_->head->stringify);
252 # $this .= "\n" . htmlsanit($_->stringify_body);
254 # $entity->parts(\@keep) if (!$msg);
256 $this .= htmlsanit($entity->stringify);
258 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
259 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
260 if ($normstate ne 'html') {
261 $this = "<pre>\n$this</pre>\n";
263 if ($normstate eq 'html') {
264 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
266 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
267 $this = "$downloadHtml" if ($terse && $normstate ne 'html');
270 my $delim = $terse ? "<p>" : "<hr>";
272 $log = "$this\n$delim$log";
274 $log .= "$this\n$delim\n";
278 $xmessage++ if ($normstate ne 'html');
280 $suppressnext = $normstate eq 'html';
284 $normstate = $newstate;
290 if ($normstate eq 'incoming-recv') {
293 m/^Received: \(at (\S+)\) by (\S+)\;/
294 || &quitcgi("bad line \`$pl' in state incoming-recv");
295 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
300 } elsif ($normstate eq 'html') {
302 } elsif ($normstate eq 'go') {
304 if (!$suppressnext && !$found_msgid &&
305 /^Message-ID: <(.*)>/i) {
308 if ($seen_msgid{$msgid}) {
311 $seen_msgid{$msgid} = 1;
317 $this .= htmlsanit($_);
319 } elsif ($normstate eq 'go-nox') {
321 if (!$suppressnext && !$found_msgid &&
322 /^Message-ID: <(.*)>/i) {
325 if ($seen_msgid{$msgid}) {
328 $seen_msgid{$msgid} = 1;
334 $this .= htmlsanit($_);
336 } elsif ($normstate eq 'recips') {
338 $thisheader = "<h2>Message sent:</h2>\n";
341 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
344 $normstate= 'kill-body';
345 } elsif ($normstate eq 'autocheck') {
346 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
347 $normstate= 'autowait';
348 $thisheader = "<h2>Message received at $2:</h2>\n";
351 } elsif ($normstate eq 'autowait') {
353 $normstate= 'go-nox';
355 &quitcgi("$ref state $normstate line \`$_'");
358 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
362 print "Content-Type: text/plain\n\n";
364 my @lines = split( "\n", $_, -1 );
365 if ( $lines[ 1 ] =~ m/^From / ) {
366 my $tmp = $lines[ 0 ];
367 $lines[ 0 ] = $lines[ 1 ];
370 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
371 my $date = strftime "%a %b %d %T %Y", localtime;
372 unshift @lines, "From unknown $date";
374 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
375 $_ = join( "\n", @lines ) . "\n";
377 print join("", @mails );
380 print "Content-Type: text/html\n\n";
382 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
383 print "<HTML><HEAD>\n" .
384 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
386 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
388 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
389 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
391 print "$descriptivehead\n";
392 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
397 print "</BODY></HTML>\n";