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));
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");
34 my $msg = $param{'msg'} || "";
35 my $att = $param{'att'};
36 my $boring = ($param{'boring'} || 'no') eq 'yes';
37 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
38 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
40 my %status = %{getbugstatus($ref)} or &quit("Couldn't get bug status: $!");
52 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
53 $tail_html = $debbugs::gHTMLTail;
54 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
58 $tpack = lc $status{'package'};
59 $tpack =~ s/[^-+._a-z0-9()].*$//;
61 if ($status{severity} eq 'normal') {
63 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
64 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
66 $showseverity = "Severity: <em>$status{severity}</em>;\n";
69 $indexentry .= "<p>$showseverity";
70 $indexentry .= "Package: <a href=\"" . pkgurl($status{package}) . "\">"
71 .htmlsanit($status{package})."</a>;\n";
73 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
74 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
76 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
77 $indexentry .= "Date: ".$dummy.";\n<br>";
81 push @descstates, "Tags: <strong>"
82 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
84 if length($status{tags});
86 my @merged= split(/ /,$status{mergedwith});
88 my $descmerged = 'merged with ';
91 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
94 push @descstates, $descmerged;
97 if (length($status{done})) {
98 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
99 } elsif (length($status{forwarded})) {
100 push @descstates, "<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
103 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
105 my ($short, $tmaint, $tsrc);
106 $short = $ref; $short =~ s/^\d+/#$&/;
107 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
108 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
109 $descriptivehead= $indexentry."Maintainer for $status{package} is\n".
110 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
111 $descriptivehead.= ";\nSource for $status{package} is\n".
112 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
113 $descriptivehead.= ".</p>";
115 my $buglog = buglog($ref);
116 open L, "<$buglog" or &quit("open log for $ref: $!");
117 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
118 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
124 my $suppressnext = 0;
131 my $normstate= 'kill-init';
135 while(my $line = <L>) {
137 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
140 my $statenum = ord($line);
142 $newstate = 'autocheck' if ($statenum == 1);
143 $newstate = 'recips' if ($statenum == 2);
144 $newstate = 'kill-end' if ($statenum == 3);
145 $newstate = 'go' if ($statenum == 5);
146 $newstate = 'html' if ($statenum == 6);
147 $newstate = 'incoming-recv' if ($statenum == 7);
149 # disallowed transitions:
150 $_ = "$normstate $newstate";
151 unless (m/^(go|go-nox|html) kill-end$/
152 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
153 || m/^kill-body go$/)
155 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
158 if ($newstate eq 'go') {
162 if ($newstate eq 'html') {
166 if ($newstate eq 'kill-end') {
170 if ($suppressnext && $normstate ne 'html');
172 $show = ($xmessage == $msg) if ($msg);
174 push @mails, $mail if ( $mbox && $mail );
176 my $downloadHtml = '';
178 my $parser = new MIME::Parser;
179 $parser->tmp_to_core(1);
180 $parser->output_to_core(1);
181 # $parser->output_under("/tmp");
182 my $entity = $parser->parse_data($mail);
183 # TODO: make local subdir, clean it outselves
184 # the following does NOT delete the msg dirs in /tmp
185 END { $entity->purge; $parser->filer->purge; }
186 my @attachments = ();
187 if ( $entity->is_multipart ) {
188 my @parts = $entity->parts_DFS;
189 # $this .= htmlsanit($entity->head->stringify);
193 # $head->mime_attr("content-transfer-encoding" => "8bit")
194 # if !$head->mime_attr("content-transfer-encoding");
195 my ($disposition,$type) = (
196 $head->mime_attr("content-disposition"),
197 lc $head->mime_attr("content-type")
200 #print STDERR "'$type' '$disposition'\n";
201 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
202 push @attachments, $_;
203 my $file = $_->head->recommended_filename;
204 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
205 if ($msg && defined($att) && $att eq $#attachments) {
208 chomp($type = $head->mime_attr("content-type"));
209 my $body = $_->stringify_body;
210 print "Content-Type: $type; name=$file\n\n";
211 my $decoder = new MIME::Decoder($head->mime_encoding);
212 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
215 if ($type eq 'text/plain') {
218 # $this .= htmlsanit($_->head->stringify);
220 # $this .= htmlsanit($_->head->stringify);
223 # $this .= "\n" . htmlsanit($_->stringify_body);
225 # $entity->parts(\@keep) if (!$msg);
227 $this .= htmlsanit($entity->stringify);
229 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
231 $this = "<pre>\n$this</pre>\n"
232 if $normstate eq 'go' || $normstate eq 'go-nox';
233 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
235 if ($normstate eq 'html') {
236 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
239 $log = "$this\n<hr>$log";
241 $log .= "$this\n<hr>\n";
245 $xmessage++ if ($normstate ne 'html');
247 $suppressnext = $normstate eq 'html';
250 $normstate = $newstate;
256 if ($normstate eq 'incoming-recv') {
259 m/^Received: \(at (\S+)\) by (\S+)\;/
260 || &quit("bad line \`$pl' in state incoming-recv");
261 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
266 } elsif ($normstate eq 'html') {
268 } elsif ($normstate eq 'go') {
273 $this .= htmlsanit($_);
275 } elsif ($normstate eq 'go-nox') {
280 $this .= htmlsanit($_);
282 } elsif ($normstate eq 'recips') {
284 $this = "<h2>Message sent:</h2>\n";
287 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
289 $normstate= 'kill-body';
290 } elsif ($normstate eq 'autocheck') {
291 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
292 $normstate= 'autowait';
293 $thisheader = "<h2>Message received at $2:</h2>\n";
296 } elsif ($normstate eq 'autowait') {
298 $normstate= 'go-nox';
300 &quit("$ref state $normstate line \`$_'");
303 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
307 print "Content-Type: text/plain\n\n";
309 my @lines = split( "\n", $_, -1 );
310 if ( $lines[ 1 ] =~ m/^From / ) {
311 my $tmp = $lines[ 0 ];
312 $lines[ 0 ] = $lines[ 1 ];
315 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
316 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
317 my $date = `date "+%a %b %d %T %Y"`;
319 unshift @lines, "From unknown $date";
321 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
322 $_ = join( "\n", @lines ) . "\n";
324 print join("", @mails );
327 print "Content-Type: text/html\n\n";
329 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
330 print "<HTML><HEAD>\n" .
331 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
333 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
335 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
336 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
338 print "$descriptivehead\n";
339 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
344 print "</BODY></HTML>\n";