6 use POSIX qw(strftime tzset);
11 #require '/usr/lib/debbugs/errorlib';
12 require './common.pl';
14 require '/etc/debbugs/config';
15 require '/etc/debbugs/text';
17 use vars(qw($gEmailDomain $gHTMLTail $gSpoolDir $gWebDomain));
19 my %param = readparse();
23 my $ref = $param{'bug'} || quit("No bug number");
24 $ref =~ /(\d+)/ or quit("Invalid bug number");
27 my $msg = $param{'msg'} || "";
28 my $att = $param{'att'};
29 my $boring = ($param{'boring'} || 'no') eq 'yes';
30 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
31 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
33 my $buglog = buglog($ref);
35 if ($ENV{REQUEST_METHOD} eq 'HEAD') {
36 print "Content-Type: text/html\n";
37 my @stat = stat $buglog;
39 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
40 print "Last-Modified: $mtime\n";
46 my %maintainer = %{getmaintainers()};
47 my %pkgsrc = %{getpkgsrc()};
59 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
60 $tail_html = $debbugs::gHTMLTail;
61 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
63 my %status = %{getbugstatus($ref)};
66 Content-Type: text/html
68 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
70 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
72 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
73 <p>There is no record of $debbugs::gBug $short.
74 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
75 $tail_html</body></html>
82 $tpack = lc $status{'package'};
83 $tpack =~ s/[^-+._a-z0-9()].*$//;
85 if ($status{severity} eq 'normal') {
87 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
88 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
90 $showseverity = "Severity: <em>$status{severity}</em>;\n";
93 $indexentry .= "<p>$showseverity";
94 $indexentry .= "Package: <a href=\"" . pkgurl($status{package}) . "\">"
95 .htmlsanit($status{package})."</a>;\n";
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;
130 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
131 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
132 $descriptivehead= $indexentry."Maintainer for $status{package} is\n".
133 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
134 $descriptivehead.= ";\nSource for $status{package} is\n".
135 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
136 $descriptivehead.= ".</p>";
138 open L, "<$buglog" or &quit("open log for $ref: $!");
139 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
140 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
146 my $suppressnext = 0;
153 my $normstate= 'kill-init';
157 while(my $line = <L>) {
159 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
162 my $statenum = ord($line);
164 $newstate = 'autocheck' if ($statenum == 1);
165 $newstate = 'recips' if ($statenum == 2);
166 $newstate = 'kill-end' if ($statenum == 3);
167 $newstate = 'go' if ($statenum == 5);
168 $newstate = 'html' if ($statenum == 6);
169 $newstate = 'incoming-recv' if ($statenum == 7);
171 # disallowed transitions:
172 $_ = "$normstate $newstate";
173 unless (m/^(go|go-nox|html) kill-end$/
174 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
175 || m/^kill-body go$/)
177 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
180 if ($newstate eq 'go') {
184 if ($newstate eq 'html') {
188 if ($newstate eq 'kill-end') {
192 if ($suppressnext && $normstate ne 'html');
194 $show = ($xmessage == $msg) if ($msg);
196 push @mails, $mail if ( $mbox && $mail );
198 my $downloadHtml = '';
200 my $parser = new MIME::Parser;
201 $parser->tmp_to_core(1);
202 $parser->output_to_core(1);
203 # $parser->output_under("/tmp");
204 my $entity = $parser->parse_data($mail);
205 # TODO: make local subdir, clean it outselves
206 # the following does NOT delete the msg dirs in /tmp
207 END { $entity->purge; $parser->filer->purge; }
208 my @attachments = ();
209 if ( $entity->is_multipart ) {
210 my @parts = $entity->parts_DFS;
211 # $this .= htmlsanit($entity->head->stringify);
215 # $head->mime_attr("content-transfer-encoding" => "8bit")
216 # if !$head->mime_attr("content-transfer-encoding");
217 my ($disposition,$type) = (
218 $head->mime_attr("content-disposition"),
219 lc $head->mime_attr("content-type")
222 #print STDERR "'$type' '$disposition'\n";
223 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
224 push @attachments, $_;
225 my $file = $_->head->recommended_filename;
226 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
227 if ($msg && defined($att) && $att eq $#attachments) {
230 chomp($type = $head->mime_attr("content-type"));
231 my $body = $_->stringify_body;
232 print "Content-Type: $type; name=$file\n\n";
233 my $decoder = new MIME::Decoder($head->mime_encoding);
234 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
237 if ($type eq 'text/plain') {
240 # $this .= htmlsanit($_->head->stringify);
242 # $this .= htmlsanit($_->head->stringify);
245 # $this .= "\n" . htmlsanit($_->stringify_body);
247 # $entity->parts(\@keep) if (!$msg);
249 $this .= htmlsanit($entity->stringify);
251 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
253 $this = "<pre>\n$this</pre>\n"
254 if $normstate eq 'go' || $normstate eq 'go-nox';
255 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
257 if ($normstate eq 'html') {
258 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
261 $log = "$this\n<hr>$log";
263 $log .= "$this\n<hr>\n";
267 $xmessage++ if ($normstate ne 'html');
269 $suppressnext = $normstate eq 'html';
272 $normstate = $newstate;
278 if ($normstate eq 'incoming-recv') {
281 m/^Received: \(at (\S+)\) by (\S+)\;/
282 || &quit("bad line \`$pl' in state incoming-recv");
283 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
288 } elsif ($normstate eq 'html') {
290 } elsif ($normstate eq 'go') {
295 $this .= htmlsanit($_);
297 } elsif ($normstate eq 'go-nox') {
302 $this .= htmlsanit($_);
304 } elsif ($normstate eq 'recips') {
306 $this = "<h2>Message sent:</h2>\n";
309 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
311 $normstate= 'kill-body';
312 } elsif ($normstate eq 'autocheck') {
313 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
314 $normstate= 'autowait';
315 $thisheader = "<h2>Message received at $2:</h2>\n";
318 } elsif ($normstate eq 'autowait') {
320 $normstate= 'go-nox';
322 &quit("$ref state $normstate line \`$_'");
325 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
329 print "Content-Type: text/plain\n\n";
331 my @lines = split( "\n", $_, -1 );
332 if ( $lines[ 1 ] =~ m/^From / ) {
333 my $tmp = $lines[ 0 ];
334 $lines[ 0 ] = $lines[ 1 ];
337 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
338 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
339 my $date = `date "+%a %b %d %T %Y"`;
341 unshift @lines, "From unknown $date";
343 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
344 $_ = join( "\n", @lines ) . "\n";
346 print join("", @mails );
349 print "Content-Type: text/html\n\n";
351 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
352 print "<HTML><HEAD>\n" .
353 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
355 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
357 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
358 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
360 print "$descriptivehead\n";
361 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
366 print "</BODY></HTML>\n";