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($gHTMLTail $gSpoolDir $gWebDomain));
19 my %param = readparse();
23 my %maintainer = %{getmaintainers()};
24 my %pkgsrc = %{getpkgsrc()};
26 my $ref = $param{'bug'} || quit("No 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 %status = %{getbugstatus($ref)} or &quit("Couldn't get bug status: $!");
45 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
46 $tail_html = $debbugs::gHTMLTail;
47 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
51 $tpack = lc $status{'package'};
52 $tpack =~ s/[^-+._a-z0-9()].*$//;
54 if ($status{severity} eq 'normal') {
56 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
57 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
59 $showseverity = "Severity: <em>$status{severity}</em>;\n";
62 $indexentry .= "<p>$showseverity";
63 $indexentry .= "Package: <a href=\"" . pkgurl($status{package}) . "\">"
64 .htmlsanit($status{package})."</a>;\n";
66 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
67 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
69 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
70 $indexentry .= "Date: ".$dummy.";\n<br>";
74 push @descstates, "Tags: <strong>"
75 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
77 if length($status{tags});
79 my @merged= split(/ /,$status{mergedwith});
81 my $descmerged = 'merged with ';
84 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
87 push @descstates, $descmerged;
90 if (length($status{done})) {
91 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
92 } elsif (length($status{forwarded})) {
93 push @descstates, "<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
96 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
98 my ($short, $tmaint, $tsrc);
99 $short = $ref; $short =~ s/^\d+/#$&/;
100 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
101 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
102 $descriptivehead= $indexentry."Maintainer for $status{package} is\n".
103 '<a href="http://'.$debbugs::gWebDomain.'/db/ma/l'.&maintencoded($tmaint).'.html">'.htmlsanit($tmaint).'</a>';
104 $descriptivehead.= ";\nSource for $status{package} is\n".
105 '<a href="'.srcurl($tsrc)."\">$tsrc</a>";
106 $descriptivehead.= ".</p>";
108 my $buglog = buglog($ref);
109 open L, "<$buglog" or &quit("open log for $ref: $!");
110 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
111 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
117 my $suppressnext = 0;
124 my $normstate= 'kill-init';
128 while(my $line = <L>) {
130 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
133 my $statenum = ord($line);
135 $newstate = 'autocheck' if ($statenum == 1);
136 $newstate = 'recips' if ($statenum == 2);
137 $newstate = 'kill-end' if ($statenum == 3);
138 $newstate = 'go' if ($statenum == 5);
139 $newstate = 'html' if ($statenum == 6);
140 $newstate = 'incoming-recv' if ($statenum == 7);
142 # disallowed transitions:
143 $_ = "$normstate $newstate";
144 unless (m/^(go|go-nox|html) kill-end$/
145 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
146 || m/^kill-body go$/)
148 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
151 if ($newstate eq 'go') {
155 if ($newstate eq 'html') {
159 if ($newstate eq 'kill-end') {
163 if ($suppressnext && $normstate ne 'html');
165 $show = ($xmessage == $msg) if ($msg);
167 push @mails, $mail if ( $mbox && $mail );
169 my $downloadHtml = '';
171 my $parser = new MIME::Parser;
172 $parser->tmp_to_core(1);
173 $parser->output_to_core(1);
174 # $parser->output_under("/tmp");
175 my $entity = $parser->parse_data($mail);
176 # TODO: make local subdir, clean it outselves
177 # the following does NOT delete the msg dirs in /tmp
178 END { $entity->purge; $parser->filer->purge; }
179 my @attachments = ();
180 if ( $entity->is_multipart ) {
181 my @parts = $entity->parts_DFS;
182 # $this .= htmlsanit($entity->head->stringify);
186 # $head->mime_attr("content-transfer-encoding" => "8bit")
187 # if !$head->mime_attr("content-transfer-encoding");
188 my ($disposition,$type) = (
189 $head->mime_attr("content-disposition"),
190 lc $head->mime_attr("content-type")
193 #print STDERR "'$type' '$disposition'\n";
194 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
195 push @attachments, $_;
196 my $file = $_->head->recommended_filename;
197 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
198 if ($msg && defined($att) && $att eq $#attachments) {
201 chomp($type = $head->mime_attr("content-type"));
202 my $body = $_->stringify_body;
203 print "Content-Type: $type; name=$file\n\n";
204 my $decoder = new MIME::Decoder($head->mime_encoding);
205 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
208 if ($type eq 'text/plain') {
211 # $this .= htmlsanit($_->head->stringify);
213 # $this .= htmlsanit($_->head->stringify);
216 # $this .= "\n" . htmlsanit($_->stringify_body);
218 # $entity->parts(\@keep) if (!$msg);
220 $this .= htmlsanit($entity->stringify);
222 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
224 $this = "<pre>\n$this</pre>\n"
225 if $normstate eq 'go' || $normstate eq 'go-nox';
226 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
228 if ($normstate eq 'html') {
229 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
232 $log = "$this\n<hr>$log";
234 $log .= "$this\n<hr>\n";
238 $xmessage++ if ($normstate ne 'html');
240 $suppressnext = $normstate eq 'html';
243 $normstate = $newstate;
249 if ($normstate eq 'incoming-recv') {
252 m/^Received: \(at (\S+)\) by (\S+)\;/
253 || &quit("bad line \`$pl' in state incoming-recv");
254 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
259 } elsif ($normstate eq 'html') {
261 } elsif ($normstate eq 'go') {
266 $this .= htmlsanit($_);
268 } elsif ($normstate eq 'go-nox') {
273 $this .= htmlsanit($_);
275 } elsif ($normstate eq 'recips') {
277 $this = "<h2>Message sent:</h2>\n";
280 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
282 $normstate= 'kill-body';
283 } elsif ($normstate eq 'autocheck') {
284 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
285 $normstate= 'autowait';
286 $thisheader = "<h2>Message received at $2:</h2>\n";
289 } elsif ($normstate eq 'autowait') {
291 $normstate= 'go-nox';
293 &quit("$ref state $normstate line \`$_'");
296 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
300 print "Content-Type: text/plain\n\n";
302 my @lines = split( "\n", $_, -1 );
303 if ( $lines[ 1 ] =~ m/^From / ) {
304 my $tmp = $lines[ 0 ];
305 $lines[ 0 ] = $lines[ 1 ];
308 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
309 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
310 my $date = `date "+%a %b %d %T %Y"`;
312 unshift @lines, "From unknown $date";
314 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
315 $_ = join( "\n", @lines ) . "\n";
317 print join("", @mails );
320 print "Content-Type: text/html\n\n";
322 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
323 print "<HTML><HEAD>\n" .
324 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
326 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
328 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@bugs.debian.org\">$short</A>" .
329 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
331 print "$descriptivehead\n";
332 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
337 print "</BODY></HTML>\n";