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'} || quit("No bug number");
25 $ref =~ /(\d+)/ or quit("Invalid bug number");
28 my $msg = $param{'msg'} || "";
29 my $att = $param{'att'};
30 my $boring = ($param{'boring'} || 'no') eq 'yes';
31 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
32 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
34 my $buglog = buglog($ref);
36 if ($ENV{REQUEST_METHOD} eq 'HEAD') {
37 print "Content-Type: text/html\n";
38 my @stat = stat $buglog;
40 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
41 print "Last-Modified: $mtime\n";
47 my %maintainer = %{getmaintainers()};
48 my %pkgsrc = %{getpkgsrc()};
60 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
61 $tail_html = $debbugs::gHTMLTail;
62 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
64 my %status = %{getbugstatus($ref)};
67 Content-Type: text/html
69 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
71 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
73 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
74 <p>There is no record of $debbugs::gBug $short.
75 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
76 $tail_html</body></html>
83 $tpack = lc $status{'package'};
84 my @tpacks = splitpackages($tpack);
86 if ($status{severity} eq 'normal') {
88 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
89 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
91 $showseverity = "Severity: <em>$status{severity}</em>;\n";
94 $indexentry .= "<p>$showseverity";
95 $indexentry .= htmlpackagelinks($status{package});
97 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
98 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
100 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
101 $indexentry .= "Date: ".$dummy.";\n<br>";
105 push @descstates, "Tags: <strong>"
106 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
108 if length($status{tags});
110 my @merged= split(/ /,$status{mergedwith});
112 my $descmerged = 'merged with ';
114 for my $m (@merged) {
115 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
118 push @descstates, $descmerged;
121 if (length($status{done})) {
122 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
123 } elsif (length($status{forwarded})) {
124 push @descstates, "<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
127 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
129 $descriptivehead = $indexentry;
130 foreach my $pkg (@tpacks) {
131 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
132 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
134 $descriptivehead .= "Maintainer for $pkg is\n".
135 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
136 $descriptivehead .= ";\nSource for $pkg is\n".
137 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
138 $descriptivehead .= ".\n<br>";
141 open L, "<$buglog" or &quit("open log for $ref: $!");
142 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
143 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
149 my $suppressnext = 0;
156 my $normstate= 'kill-init';
160 while(my $line = <L>) {
162 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
165 my $statenum = ord($line);
167 $newstate = 'autocheck' if ($statenum == 1);
168 $newstate = 'recips' if ($statenum == 2);
169 $newstate = 'kill-end' if ($statenum == 3);
170 $newstate = 'go' if ($statenum == 5);
171 $newstate = 'html' if ($statenum == 6);
172 $newstate = 'incoming-recv' if ($statenum == 7);
174 # disallowed transitions:
175 $_ = "$normstate $newstate";
176 unless (m/^(go|go-nox|html) kill-end$/
177 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
178 || m/^kill-body go$/)
180 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
183 if ($newstate eq 'go') {
187 if ($newstate eq 'html') {
191 if ($newstate eq 'kill-end') {
195 if ($suppressnext && $normstate ne 'html');
197 $show = ($xmessage == $msg) if ($msg);
199 push @mails, join( '', @mail ) if ( $mbox && @mail );
201 my $downloadHtml = '';
203 my $parser = new MIME::Parser;
204 $parser->tmp_to_core(1);
205 $parser->output_to_core(1);
206 # $parser->output_under("/tmp");
207 my $entity = $parser->parse( new IO::Lines \@mail );
208 # TODO: make local subdir, clean it outselves
209 # the following does NOT delete the msg dirs in /tmp
210 END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
211 my @attachments = ();
212 if ( $entity->is_multipart ) {
213 my @parts = $entity->parts_DFS;
214 # $this .= htmlsanit($entity->head->stringify);
218 # $head->mime_attr("content-transfer-encoding" => "8bit")
219 # if !$head->mime_attr("content-transfer-encoding");
220 my ($disposition,$type) = (
221 $head->mime_attr("content-disposition"),
222 lc $head->mime_attr("content-type")
225 #print STDERR "'$type' '$disposition'\n";
226 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
227 push @attachments, $_;
228 my $file = $_->head->recommended_filename;
229 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
230 if ($msg && defined($att) && $att eq $#attachments) {
233 chomp($type = $head->mime_attr("content-type"));
234 my $body = $_->stringify_body;
235 print "Content-Type: $type; name=$file\n\n";
236 my $decoder = new MIME::Decoder($head->mime_encoding);
237 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
240 if ($type eq 'text/plain') {
243 # $this .= htmlsanit($_->head->stringify);
245 # $this .= htmlsanit($_->head->stringify);
248 # $this .= "\n" . htmlsanit($_->stringify_body);
250 # $entity->parts(\@keep) if (!$msg);
252 $this .= htmlsanit($entity->stringify);
254 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
256 $this = "<pre>\n$this</pre>\n"
257 if $normstate eq 'go' || $normstate eq 'go-nox';
258 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
260 if ($normstate eq 'html') {
261 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
264 $log = "$this\n<hr>$log";
266 $log .= "$this\n<hr>\n";
270 $xmessage++ if ($normstate ne 'html');
272 $suppressnext = $normstate eq 'html';
275 $normstate = $newstate;
281 if ($normstate eq 'incoming-recv') {
284 m/^Received: \(at (\S+)\) by (\S+)\;/
285 || &quit("bad line \`$pl' in state incoming-recv");
286 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
291 } elsif ($normstate eq 'html') {
293 } elsif ($normstate eq 'go') {
298 $this .= htmlsanit($_);
300 } elsif ($normstate eq 'go-nox') {
305 $this .= htmlsanit($_);
307 } elsif ($normstate eq 'recips') {
309 $this = "<h2>Message sent:</h2>\n";
312 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
314 $normstate= 'kill-body';
315 } elsif ($normstate eq 'autocheck') {
316 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
317 $normstate= 'autowait';
318 $thisheader = "<h2>Message received at $2:</h2>\n";
321 } elsif ($normstate eq 'autowait') {
323 $normstate= 'go-nox';
325 &quit("$ref state $normstate line \`$_'");
328 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
332 print "Content-Type: text/plain\n\n";
334 my @lines = split( "\n", $_, -1 );
335 if ( $lines[ 1 ] =~ m/^From / ) {
336 my $tmp = $lines[ 0 ];
337 $lines[ 0 ] = $lines[ 1 ];
340 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
341 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
342 my $date = `date "+%a %b %d %T %Y"`;
344 unshift @lines, "From unknown $date";
346 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
347 $_ = join( "\n", @lines ) . "\n";
349 print join("", @mails );
352 print "Content-Type: text/html\n\n";
354 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
355 print "<HTML><HEAD>\n" .
356 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
358 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
360 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
361 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
363 print "$descriptivehead\n";
364 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
369 print "</BODY></HTML>\n";