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 my %param = readparse();
23 my %maintainer = %{getmaintainers()};
24 my %pkgsrc = %{getpkgsrc()};
26 my $ref = $param{'bug'} || quit("No bug number");
27 $ref =~ /(\d+)/ or quit("Invalid bug number");
29 my $msg = $param{'msg'} || "";
30 my $att = $param{'att'};
31 my $boring = ($param{'boring'} || 'no') eq 'yes';
32 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
33 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
35 my %status = %{getbugstatus($ref)} or &quit("Couldn't get bug status: $!");
47 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
48 $tail_html = $debbugs::gHTMLTail;
49 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
53 $tpack = lc $status{'package'};
54 $tpack =~ s/[^-+._a-z0-9()].*$//;
56 if ($status{severity} eq 'normal') {
58 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
59 # $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
61 $showseverity = "Severity: <em>$status{severity}</em>;\n";
64 $indexentry .= "<p>$showseverity";
65 $indexentry .= "Package: <a href=\"" . pkgurl($status{package}) . "\">"
66 .htmlsanit($status{package})."</a>;\n";
68 $indexentry .= "Reported by: <a href=\"" . submitterurl($status{originator})
69 . "\">" . htmlsanit($status{originator}) . "</a>;\n";
71 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
72 $indexentry .= "Date: ".$dummy.";\n<br>";
76 push @descstates, "Tags: <strong>"
77 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
79 if length($status{tags});
81 my @merged= split(/ /,$status{mergedwith});
83 my $descmerged = 'merged with ';
86 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
89 push @descstates, $descmerged;
92 if (length($status{done})) {
93 push @descstates, "<strong>Done:</strong> ".htmlsanit($status{done});
94 } elsif (length($status{forwarded})) {
95 push @descstates, "<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
98 $indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
100 my ($short, $tmaint, $tsrc);
101 $short = $ref; $short =~ s/^\d+/#$&/;
102 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
103 $tsrc = defined($pkgsrc{$tpack}) ? $pkgsrc{$tpack} : '(unknown)';
104 $descriptivehead= $indexentry."Maintainer for $status{package} is\n".
105 '<a href="'.mainturl($tmaint).'">'.htmlsanit($tmaint).'</a>';
106 $descriptivehead.= ";\nSource for $status{package} is\n".
107 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
108 $descriptivehead.= ".</p>";
110 my $buglog = buglog($ref);
111 open L, "<$buglog" or &quit("open log for $ref: $!");
112 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
113 $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
119 my $suppressnext = 0;
126 my $normstate= 'kill-init';
130 while(my $line = <L>) {
132 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
135 my $statenum = ord($line);
137 $newstate = 'autocheck' if ($statenum == 1);
138 $newstate = 'recips' if ($statenum == 2);
139 $newstate = 'kill-end' if ($statenum == 3);
140 $newstate = 'go' if ($statenum == 5);
141 $newstate = 'html' if ($statenum == 6);
142 $newstate = 'incoming-recv' if ($statenum == 7);
144 # disallowed transitions:
145 $_ = "$normstate $newstate";
146 unless (m/^(go|go-nox|html) kill-end$/
147 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
148 || m/^kill-body go$/)
150 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
153 if ($newstate eq 'go') {
157 if ($newstate eq 'html') {
161 if ($newstate eq 'kill-end') {
165 if ($suppressnext && $normstate ne 'html');
167 $show = ($xmessage == $msg) if ($msg);
169 push @mails, $mail if ( $mbox && $mail );
171 my $downloadHtml = '';
173 my $parser = new MIME::Parser;
174 $parser->tmp_to_core(1);
175 $parser->output_to_core(1);
176 # $parser->output_under("/tmp");
177 my $entity = $parser->parse_data($mail);
178 # TODO: make local subdir, clean it outselves
179 # the following does NOT delete the msg dirs in /tmp
180 END { $entity->purge; $parser->filer->purge; }
181 my @attachments = ();
182 if ( $entity->is_multipart ) {
183 my @parts = $entity->parts_DFS;
184 # $this .= htmlsanit($entity->head->stringify);
188 # $head->mime_attr("content-transfer-encoding" => "8bit")
189 # if !$head->mime_attr("content-transfer-encoding");
190 my ($disposition,$type) = (
191 $head->mime_attr("content-disposition"),
192 lc $head->mime_attr("content-type")
195 #print STDERR "'$type' '$disposition'\n";
196 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
197 push @attachments, $_;
198 my $file = $_->head->recommended_filename;
199 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
200 if ($msg && defined($att) && $att eq $#attachments) {
203 chomp($type = $head->mime_attr("content-type"));
204 my $body = $_->stringify_body;
205 print "Content-Type: $type; name=$file\n\n";
206 my $decoder = new MIME::Decoder($head->mime_encoding);
207 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
210 if ($type eq 'text/plain') {
213 # $this .= htmlsanit($_->head->stringify);
215 # $this .= htmlsanit($_->head->stringify);
218 # $this .= "\n" . htmlsanit($_->stringify_body);
220 # $entity->parts(\@keep) if (!$msg);
222 $this .= htmlsanit($entity->stringify);
224 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
226 $this = "<pre>\n$this</pre>\n"
227 if $normstate eq 'go' || $normstate eq 'go-nox';
228 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
230 if ($normstate eq 'html') {
231 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
234 $log = "$this\n<hr>$log";
236 $log .= "$this\n<hr>\n";
240 $xmessage++ if ($normstate ne 'html');
242 $suppressnext = $normstate eq 'html';
245 $normstate = $newstate;
251 if ($normstate eq 'incoming-recv') {
254 m/^Received: \(at (\S+)\) by (\S+)\;/
255 || &quit("bad line \`$pl' in state incoming-recv");
256 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
261 } elsif ($normstate eq 'html') {
263 } elsif ($normstate eq 'go') {
268 $this .= htmlsanit($_);
270 } elsif ($normstate eq 'go-nox') {
275 $this .= htmlsanit($_);
277 } elsif ($normstate eq 'recips') {
279 $this = "<h2>Message sent:</h2>\n";
282 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
284 $normstate= 'kill-body';
285 } elsif ($normstate eq 'autocheck') {
286 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
287 $normstate= 'autowait';
288 $thisheader = "<h2>Message received at $2:</h2>\n";
291 } elsif ($normstate eq 'autowait') {
293 $normstate= 'go-nox';
295 &quit("$ref state $normstate line \`$_'");
298 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
302 print "Content-Type: text/plain\n\n";
304 my @lines = split( "\n", $_, -1 );
305 if ( $lines[ 1 ] =~ m/^From / ) {
306 my $tmp = $lines[ 0 ];
307 $lines[ 0 ] = $lines[ 1 ];
310 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
311 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
312 my $date = `date "+%a %b %d %T %Y"`;
314 unshift @lines, "From unknown $date";
316 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
317 $_ = join( "\n", @lines ) . "\n";
319 print join("", @mails );
322 print "Content-Type: text/html\n\n";
324 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
325 print "<HTML><HEAD>\n" .
326 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
328 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
330 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
331 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
333 print "$descriptivehead\n";
334 printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>", mboxurl($ref);
339 print "</BODY></HTML>\n";