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 $type !~ m[^text/html(?:;|$)]) or
102 $type =~ m[^application/pgp(?:;|$)] or
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);
112 } elsif ($entity->parts) {
113 # We must be dealing with a nested message.
114 $$this .= "<blockquote>\n";
115 my @parts = $entity->parts;
116 foreach my $part (@parts) {
117 display_entity($part, $ref, 1, $xmessage,
118 $$this, @$attachments);
121 $$this .= "</blockquote>\n";
123 $$this .= htmlsanit($entity->bodyhandle->as_string) unless ($terse);
127 my %maintainer = %{getmaintainers()};
128 my %pkgsrc = %{getpkgsrc()};
140 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
141 $tail_html = $debbugs::gHTMLTail;
142 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
144 my %status = %{getbugstatus($ref)};
147 Content-Type: text/html
149 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
151 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
153 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
154 <p>There is no record of $debbugs::gBug $short.
155 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
156 $tail_html</body></html>
163 $tpack = lc $status{'package'};
164 my @tpacks = splitpackages($tpack);
166 if ($status{severity} eq 'normal') {
168 #} elsif (isstrongseverity($status{severity})) {
169 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
171 $showseverity = "Severity: <em>$status{severity}</em>;\n";
174 $indexentry .= "<p>$showseverity";
175 $indexentry .= htmlpackagelinks($status{package}, 0);
177 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
178 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
180 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
181 $indexentry .= "Date: ".$dummy.";\n<br>";
185 push @descstates, "Tags: <strong>"
186 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
188 if length($status{tags});
190 my @merged= split(/ /,$status{mergedwith});
192 my $descmerged = 'merged with ';
194 for my $m (@merged) {
195 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
198 push @descstates, $descmerged;
201 if (@{$status{found_versions}}) {
202 my $foundtext = 'Found in ';
203 $foundtext .= (@{$status{found_versions}} == 1) ? 'version ' : 'versions ';
204 $foundtext .= join ', ', map htmlsanit($_), @{$status{found_versions}};
205 push @descstates, $foundtext;
208 if (@{$status{fixed_versions}}) {
209 my $fixedtext = '<strong>Fixed</strong> in ';
210 $fixedtext .= (@{$status{fixed_versions}} == 1) ? 'version ' : 'versions ';
211 $fixedtext .= join ', ', map htmlsanit($_), @{$status{fixed_versions}};
212 if (length($status{done})) {
213 $fixedtext .= ' by ' . htmlsanit($status{done});
215 push @descstates, $fixedtext;
216 } elsif (length($status{done})) {
217 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
218 } elsif (length($status{forwarded})) {
219 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
222 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
224 $descriptivehead = $indexentry;
225 foreach my $pkg (@tpacks) {
226 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
227 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
230 htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
231 : "Maintainers for $pkg are\n" },
233 $descriptivehead .= ";\nSource for $pkg is\n".
234 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
235 $descriptivehead .= ".\n<br>";
238 open L, "<$buglog" or &quitcgi("open log for $ref: $!");
239 if ($buglog !~ m#^\Q$gSpoolDir/db#) {
240 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
246 my $suppressnext = 0;
255 my $normstate= 'kill-init';
259 while(my $line = <L>) {
261 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
264 my $statenum = ord($line);
266 $newstate = 'autocheck' if ($statenum == 1);
267 $newstate = 'recips' if ($statenum == 2);
268 $newstate = 'kill-end' if ($statenum == 3);
269 $newstate = 'go' if ($statenum == 5);
270 $newstate = 'html' if ($statenum == 6);
271 $newstate = 'incoming-recv' if ($statenum == 7);
273 # disallowed transitions:
274 $_ = "$normstate $newstate";
275 unless (m/^(go|go-nox|html) kill-end$/
276 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
277 || m/^kill-body go$/)
279 &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
282 #$this .= "\n<br>states: $normstate $newstate<br>\n";
284 # if ($newstate eq 'go') {
285 # $this .= "<pre>\n";
287 if ($newstate eq 'html') {
291 if ($newstate eq 'kill-end') {
295 if ($suppressnext && $normstate ne 'html');
297 $show = ($xmessage == $msg) if ($msg);
299 push @mails, join( '', @mail ) if ( $mbox && @mail );
301 if (not $mime and @mail) {
302 $this .= htmlsanit(join '', @mail);
304 my $parser = new MIME::Parser;
305 $parser->tmp_to_core(1);
306 $parser->output_to_core(1);
307 # $parser->output_under("/tmp");
308 my $entity = $parser->parse( new IO::Lines \@mail );
309 # TODO: make local subdir, clean it ourselves
310 # the following does NOT delete the msg dirs in /tmp
311 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
312 my @attachments = ();
313 display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
315 # if ($normstate eq 'go' || $normstate eq 'go-nox') {
316 if ($normstate ne 'html') {
317 $this = "<pre>\n$this</pre>\n";
319 if ($normstate eq 'html') {
320 $this .= " <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em>";
322 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
324 my $delim = $terse ? "<p>" : "<hr>";
326 $log = "$this\n$delim$log";
328 $log .= "$this\n$delim\n";
332 $xmessage++ if ($normstate ne 'html');
334 $suppressnext = $normstate eq 'html';
338 $normstate = $newstate;
344 if ($normstate eq 'incoming-recv') {
347 m/^Received: \(at (\S+)\) by (\S+)\;/
348 || &quitcgi("bad line \`$pl' in state incoming-recv");
349 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
354 } elsif ($normstate eq 'html') {
356 } elsif ($normstate eq 'go') {
358 if (!$suppressnext && !$found_msgid &&
359 /^Message-ID: <(.*)>/i) {
362 if ($seen_msgid{$msgid}) {
365 $seen_msgid{$msgid} = 1;
371 $this .= htmlsanit($_);
373 } elsif ($normstate eq 'go-nox') {
375 if (!$suppressnext && !$found_msgid &&
376 /^Message-ID: <(.*)>/i) {
379 if ($seen_msgid{$msgid}) {
382 $seen_msgid{$msgid} = 1;
388 $this .= htmlsanit($_);
390 } elsif ($normstate eq 'recips') {
392 $thisheader = "<h2>Message sent:</h2>\n";
395 $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
398 $normstate= 'kill-body';
399 } elsif ($normstate eq 'autocheck') {
400 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
401 $normstate= 'autowait';
402 $thisheader = "<h2>Message received at $2:</h2>\n";
405 } elsif ($normstate eq 'autowait') {
407 $normstate= 'go-nox';
409 &quitcgi("$ref state $normstate line \`$_'");
412 &quitcgi("$ref state $normstate at end") unless $normstate eq 'kill-end';
416 print "Content-Type: text/plain\n\n";
418 my @lines = split( "\n", $_, -1 );
419 if ( $lines[ 1 ] =~ m/^From / ) {
420 my $tmp = $lines[ 0 ];
421 $lines[ 0 ] = $lines[ 1 ];
424 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
425 my $date = strftime "%a %b %d %T %Y", localtime;
426 unshift @lines, "From unknown $date";
428 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
429 $_ = join( "\n", @lines ) . "\n";
431 print join("", @mails );
434 print "Content-Type: text/html\n\n";
436 my $title = htmlsanit($status{subject});
438 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
439 print "<HTML><HEAD>\n" .
440 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short - $title</TITLE>\n" .
442 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
444 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
445 "<BR>" . $title . "</H1>\n";
447 print "$descriptivehead\n";
448 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
453 print "</BODY></HTML>\n";