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 if ($ENV{REQUEST_METHOD} eq 'HEAD') {
20 print "Content-Type: text/html\n\n";
24 my %param = readparse();
28 my %maintainer = %{getmaintainers()};
29 my %pkgsrc = %{getpkgsrc()};
31 my $ref = $param{'bug'} || quit("No bug number");
32 $ref =~ /(\d+)/ or quit("Invalid bug number");
35 my $msg = $param{'msg'} || "";
36 my $att = $param{'att'};
37 my $boring = ($param{'boring'} || 'no') eq 'yes';
38 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
39 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
51 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
52 $tail_html = $debbugs::gHTMLTail;
53 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
55 my %status = %{getbugstatus($ref)};
58 Content-Type: text/html
60 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
62 <head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
64 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
65 <p>There is no record of $debbugs::gBug $short.
66 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
67 $tail_html</body></html>
74 $tpack = lc $status{'package'};
75 $tpack =~ s/[^-+._a-z0-9()].*$//;
77 if ($status{severity} eq 'normal') {
79 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
80 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
82 $showseverity = "Severity: <em>$status{severity}</em>;\n";
85 $indexentry .= "<p>$showseverity";
86 $indexentry .= "Package: <a href=\"" . pkgurl($status{package}) . "\">"
87 .htmlsanit($status{package})."</a>;\n";
89 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
90 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
92 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
93 $indexentry .= "Date: ".$dummy.";\n<br>";
97 push @descstates, "Tags: <strong>"
98 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
100 if length($status{tags});
102 my @merged= split(/ /,$status{mergedwith});
104 my $descmerged = 'merged with ';
106 for my $m (@merged) {
107 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
110 push @descstates, $descmerged;
113 if (length($status{done})) {
114 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
115 } elsif (length($status{forwarded})) {
116 push @descstates, "<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
119 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
122 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
123 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
124 $descriptivehead= $indexentry."Maintainer for $status{package} is\n".
125 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
126 $descriptivehead.= ";\nSource for $status{package} is\n".
127 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
128 $descriptivehead.= ".</p>";
130 my $buglog = buglog($ref);
131 open L, "<$buglog" or &quit("open log for $ref: $!");
132 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
133 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
139 my $suppressnext = 0;
146 my $normstate= 'kill-init';
150 while(my $line = <L>) {
152 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
155 my $statenum = ord($line);
157 $newstate = 'autocheck' if ($statenum == 1);
158 $newstate = 'recips' if ($statenum == 2);
159 $newstate = 'kill-end' if ($statenum == 3);
160 $newstate = 'go' if ($statenum == 5);
161 $newstate = 'html' if ($statenum == 6);
162 $newstate = 'incoming-recv' if ($statenum == 7);
164 # disallowed transitions:
165 $_ = "$normstate $newstate";
166 unless (m/^(go|go-nox|html) kill-end$/
167 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
168 || m/^kill-body go$/)
170 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
173 if ($newstate eq 'go') {
177 if ($newstate eq 'html') {
181 if ($newstate eq 'kill-end') {
185 if ($suppressnext && $normstate ne 'html');
187 $show = ($xmessage == $msg) if ($msg);
189 push @mails, $mail if ( $mbox && $mail );
191 my $downloadHtml = '';
193 my $parser = new MIME::Parser;
194 $parser->tmp_to_core(1);
195 $parser->output_to_core(1);
196 # $parser->output_under("/tmp");
197 my $entity = $parser->parse_data($mail);
198 # TODO: make local subdir, clean it outselves
199 # the following does NOT delete the msg dirs in /tmp
200 END { $entity->purge; $parser->filer->purge; }
201 my @attachments = ();
202 if ( $entity->is_multipart ) {
203 my @parts = $entity->parts_DFS;
204 # $this .= htmlsanit($entity->head->stringify);
208 # $head->mime_attr("content-transfer-encoding" => "8bit")
209 # if !$head->mime_attr("content-transfer-encoding");
210 my ($disposition,$type) = (
211 $head->mime_attr("content-disposition"),
212 lc $head->mime_attr("content-type")
215 #print STDERR "'$type' '$disposition'\n";
216 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
217 push @attachments, $_;
218 my $file = $_->head->recommended_filename;
219 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
220 if ($msg && defined($att) && $att eq $#attachments) {
223 chomp($type = $head->mime_attr("content-type"));
224 my $body = $_->stringify_body;
225 print "Content-Type: $type; name=$file\n\n";
226 my $decoder = new MIME::Decoder($head->mime_encoding);
227 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
230 if ($type eq 'text/plain') {
233 # $this .= htmlsanit($_->head->stringify);
235 # $this .= htmlsanit($_->head->stringify);
238 # $this .= "\n" . htmlsanit($_->stringify_body);
240 # $entity->parts(\@keep) if (!$msg);
242 $this .= htmlsanit($entity->stringify);
244 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
246 $this = "<pre>\n$this</pre>\n"
247 if $normstate eq 'go' || $normstate eq 'go-nox';
248 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
250 if ($normstate eq 'html') {
251 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
254 $log = "$this\n<hr>$log";
256 $log .= "$this\n<hr>\n";
260 $xmessage++ if ($normstate ne 'html');
262 $suppressnext = $normstate eq 'html';
265 $normstate = $newstate;
271 if ($normstate eq 'incoming-recv') {
274 m/^Received: \(at (\S+)\) by (\S+)\;/
275 || &quit("bad line \`$pl' in state incoming-recv");
276 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
281 } elsif ($normstate eq 'html') {
283 } elsif ($normstate eq 'go') {
288 $this .= htmlsanit($_);
290 } elsif ($normstate eq 'go-nox') {
295 $this .= htmlsanit($_);
297 } elsif ($normstate eq 'recips') {
299 $this = "<h2>Message sent:</h2>\n";
302 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
304 $normstate= 'kill-body';
305 } elsif ($normstate eq 'autocheck') {
306 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
307 $normstate= 'autowait';
308 $thisheader = "<h2>Message received at $2:</h2>\n";
311 } elsif ($normstate eq 'autowait') {
313 $normstate= 'go-nox';
315 &quit("$ref state $normstate line \`$_'");
318 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
322 print "Content-Type: text/plain\n\n";
324 my @lines = split( "\n", $_, -1 );
325 if ( $lines[ 1 ] =~ m/^From / ) {
326 my $tmp = $lines[ 0 ];
327 $lines[ 0 ] = $lines[ 1 ];
330 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
331 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
332 my $date = `date "+%a %b %d %T %Y"`;
334 unshift @lines, "From unknown $date";
336 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
337 $_ = join( "\n", @lines ) . "\n";
339 print join("", @mails );
342 print "Content-Type: text/html\n\n";
344 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
345 print "<HTML><HEAD>\n" .
346 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
348 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
350 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
351 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
353 print "$descriptivehead\n";
354 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
359 print "</BODY></HTML>\n";