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 $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'} || "0";
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: $!");
46 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
47 $tail_html = $debbugs::gHTMLTail;
48 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
52 $tpack = lc $status{'package'};
53 $tpack =~ s/[^-+._a-z0-9()].*$//;
55 if ($status{severity} eq 'normal') {
57 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
58 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
60 $showseverity = "Severity: <em>$status{severity}</em>;\n";
63 $indexentry .= $showseverity;
64 $indexentry .= "Package: <A HREF=\"" . pkgurl($status{package}) . "\">"
65 .htmlsanit($status{package})."</A>;\n";
67 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
68 . "\">" . htmlsanit($status{originator}) . "</a>";
69 $indexentry .= ";\nTags: <strong>"
70 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
72 if length($status{tags});
74 my @merged= split(/ /,$status{mergedwith});
76 my $mseparator= ";\nmerged with ";
78 $indexentry .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
83 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
84 $submitted = ";\ndated ".$dummy;
86 if (length($status{done})) {
87 $indexentry .= ";\n<strong>Done:</strong> ".htmlsanit($status{done});
88 } elsif (length($status{forwarded})) {
89 $indexentry .= ";\n<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
92 my ($short, $tmaint, $tsrc);
93 $short = $ref; $short =~ s/^\d+/#$&/;
94 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
95 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
96 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $status{package} is\n".
97 '<A href="http://'.$debbugs::gWebDomain.'/db/ma/l'.&maintencoded($tmaint).'.html">'.htmlsanit($tmaint).'</A>';
98 $descriptivehead.= ";\n<br>Source for $status{package} is\n".
99 '<A href="'.srcurl($tsrc)."\">$tsrc</A>";
100 $descriptivehead.= ".";
102 my $buglog = buglog($ref);
103 open L, "<$buglog" or &quit("open log for $ref: $!");
108 my $suppressnext = 0;
115 my $normstate= 'kill-init';
119 while(my $line = <L>) {
121 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
124 my $statenum = ord($line);
126 $newstate = 'autocheck' if ($statenum == 1);
127 $newstate = 'recips' if ($statenum == 2);
128 $newstate = 'kill-end' if ($statenum == 3);
129 $newstate = 'go' if ($statenum == 5);
130 $newstate = 'html' if ($statenum == 6);
131 $newstate = 'incoming-recv' if ($statenum == 7);
133 # disallowed transitions:
134 $_ = "$normstate $newstate";
135 unless (m/^(go|go-nox|html) kill-end$/
136 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
137 || m/^kill-body go$/)
139 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
142 if ($newstate eq 'go') {
146 if ($newstate eq 'html') {
150 if ($newstate eq 'kill-end') {
154 if ($suppressnext && $normstate ne 'html');
156 $show = ($xmessage == $msg) if ($msg);
158 push @mails, $mail if ( $mbox && $mail );
160 my $downloadHtml = '';
162 my $parser = new MIME::Parser;
163 $parser->tmp_to_core(1);
164 $parser->output_to_core(1);
165 # $parser->output_under("/tmp");
166 my $entity = $parser->parse_data($mail);
167 # TODO: make local subdir, clean it outselves
168 # the following does NOT delete the msg dirs in /tmp
169 END { $entity->purge; $parser->filer->purge; }
170 my @attachments = ();
171 if ( $entity->is_multipart ) {
172 my @parts = $entity->parts_DFS;
173 # $this .= htmlsanit($entity->head->stringify);
177 # $head->mime_attr("content-transfer-encoding" => "8bit")
178 # if !$head->mime_attr("content-transfer-encoding");
179 my ($disposition,$type) = (
180 $head->mime_attr("content-disposition"),
181 lc $head->mime_attr("content-type")
184 #print STDERR "'$type' '$disposition'\n";
185 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
186 push @attachments, $_;
187 my $file = $_->head->recommended_filename;
188 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
189 if ($msg && $att eq $#attachments) {
192 chomp($type = $head->mime_attr("content-type"));
193 my $body = $_->stringify_body;
194 print "Content-Type: $type; name=$file\n\n";
195 my $decoder = new MIME::Decoder($head->mime_encoding);
196 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
199 if ($type eq 'text/plain') {
202 # $this .= htmlsanit($_->head->stringify);
204 # $this .= htmlsanit($_->head->stringify);
207 # $this .= "\n" . htmlsanit($_->stringify_body);
209 # $entity->parts(\@keep) if (!$msg);
211 $this .= htmlsanit($entity->stringify);
213 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
215 $this = "<pre>\n$this</pre>\n"
216 if $normstate eq 'go' || $normstate eq 'go-nox';
217 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
219 if ($normstate eq 'html') {
220 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
223 $log = "$this\n<hr>$log";
225 $log .= "$this\n<hr>\n";
229 $xmessage++ if ($normstate ne 'html');
231 $suppressnext = $normstate eq 'html';
234 $normstate = $newstate;
240 if ($normstate eq 'incoming-recv') {
243 m/^Received: \(at (\S+)\) by (\S+)\;/
244 || &quit("bad line \`$pl' in state incoming-recv");
245 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
250 } elsif ($normstate eq 'html') {
252 } elsif ($normstate eq 'go') {
256 $this .= htmlsanit($_);
258 } elsif ($normstate eq 'go-nox') {
263 $this .= htmlsanit($_);
265 } elsif ($normstate eq 'recips') {
267 $this = "<h2>Message sent:</h2>\n";
270 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
272 $normstate= 'kill-body';
273 } elsif ($normstate eq 'autocheck') {
274 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
275 $normstate= 'autowait';
276 $thisheader = "<h2>Message received at $2:</h2>\n";
279 } elsif ($normstate eq 'autowait') {
281 $normstate= 'go-nox';
283 &quit("$ref state $normstate line \`$_'");
286 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
290 print "Content-Type: text/plain\n\n";
292 my @lines = split( "\n", $_, -1 );
293 if ( $lines[ 1 ] =~ m/^From / ) {
294 my $tmp = $lines[ 0 ];
295 $lines[ 0 ] = $lines[ 1 ];
297 $_ = join( "\n", @lines ) . "\n";
299 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
300 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
301 my $date = `date "+%a %b %d %T %Y"`;
303 $_ = "From unknown $date\n" . $_;
306 print join("", @mails );
309 print "Content-Type: text/html\n\n";
311 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
312 print "<HTML><HEAD>\n" .
313 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
315 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
317 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@bugs.debian.org\">$short</A>" .
318 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
320 print "$descriptivehead\n";
321 printf "<p><a href=\"%s\">View</a> this report as an mbox folder.</p>", mboxurl($ref);
326 print "</BODY></HTML>\n";