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: $!");
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: $!");
104 if ($buglog !~ m#^\Q$gSpoolDir/db-h/#) {
105 $descriptivehead .= "\n<br>Bug is <strong>archived</strong>. No further changes may be made.";
111 my $suppressnext = 0;
118 my $normstate= 'kill-init';
122 while(my $line = <L>) {
124 if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
127 my $statenum = ord($line);
129 $newstate = 'autocheck' if ($statenum == 1);
130 $newstate = 'recips' if ($statenum == 2);
131 $newstate = 'kill-end' if ($statenum == 3);
132 $newstate = 'go' if ($statenum == 5);
133 $newstate = 'html' if ($statenum == 6);
134 $newstate = 'incoming-recv' if ($statenum == 7);
136 # disallowed transitions:
137 $_ = "$normstate $newstate";
138 unless (m/^(go|go-nox|html) kill-end$/
139 || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
140 || m/^kill-body go$/)
142 &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
145 if ($newstate eq 'go') {
149 if ($newstate eq 'html') {
153 if ($newstate eq 'kill-end') {
157 if ($suppressnext && $normstate ne 'html');
159 $show = ($xmessage == $msg) if ($msg);
161 push @mails, $mail if ( $mbox && $mail );
163 my $downloadHtml = '';
165 my $parser = new MIME::Parser;
166 $parser->tmp_to_core(1);
167 $parser->output_to_core(1);
168 # $parser->output_under("/tmp");
169 my $entity = $parser->parse_data($mail);
170 # TODO: make local subdir, clean it outselves
171 # the following does NOT delete the msg dirs in /tmp
172 END { $entity->purge; $parser->filer->purge; }
173 my @attachments = ();
174 if ( $entity->is_multipart ) {
175 my @parts = $entity->parts_DFS;
176 # $this .= htmlsanit($entity->head->stringify);
180 # $head->mime_attr("content-transfer-encoding" => "8bit")
181 # if !$head->mime_attr("content-transfer-encoding");
182 my ($disposition,$type) = (
183 $head->mime_attr("content-disposition"),
184 lc $head->mime_attr("content-type")
187 #print STDERR "'$type' '$disposition'\n";
188 if ($disposition && ( $disposition eq "attachment" || $disposition eq "inline" ) && $_->head->recommended_filename ) {
189 push @attachments, $_;
190 my $file = $_->head->recommended_filename;
191 $downloadHtml .= "View Attachment: <a href=\"".dlurl($ref,"msg=$xmessage","att=$#attachments","filename=$file")."\">$file</a>\n";
192 if ($msg && defined($att) && $att eq $#attachments) {
195 chomp($type = $head->mime_attr("content-type"));
196 my $body = $_->stringify_body;
197 print "Content-Type: $type; name=$file\n\n";
198 my $decoder = new MIME::Decoder($head->mime_encoding);
199 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
202 if ($type eq 'text/plain') {
205 # $this .= htmlsanit($_->head->stringify);
207 # $this .= htmlsanit($_->head->stringify);
210 # $this .= "\n" . htmlsanit($_->stringify_body);
212 # $entity->parts(\@keep) if (!$msg);
214 $this .= htmlsanit($entity->stringify);
216 $this = "$downloadHtml\n$this$downloadHtml" if $downloadHtml;
218 $this = "<pre>\n$this</pre>\n"
219 if $normstate eq 'go' || $normstate eq 'go-nox';
220 $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
222 if ($normstate eq 'html') {
223 $this .= " <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
226 $log = "$this\n<hr>$log";
228 $log .= "$this\n<hr>\n";
232 $xmessage++ if ($normstate ne 'html');
234 $suppressnext = $normstate eq 'html';
237 $normstate = $newstate;
243 if ($normstate eq 'incoming-recv') {
246 m/^Received: \(at (\S+)\) by (\S+)\;/
247 || &quit("bad line \`$pl' in state incoming-recv");
248 $thisheader = "<h2>Message received at ".htmlsanit("$1\@$2")
253 } elsif ($normstate eq 'html') {
255 } elsif ($normstate eq 'go') {
259 $this .= htmlsanit($_);
261 } elsif ($normstate eq 'go-nox') {
266 $this .= htmlsanit($_);
268 } elsif ($normstate eq 'recips') {
270 $this = "<h2>Message sent:</h2>\n";
273 $this = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
275 $normstate= 'kill-body';
276 } elsif ($normstate eq 'autocheck') {
277 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
278 $normstate= 'autowait';
279 $thisheader = "<h2>Message received at $2:</h2>\n";
282 } elsif ($normstate eq 'autowait') {
284 $normstate= 'go-nox';
286 &quit("$ref state $normstate line \`$_'");
289 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
293 print "Content-Type: text/plain\n\n";
295 my @lines = split( "\n", $_, -1 );
296 if ( $lines[ 1 ] =~ m/^From / ) {
297 my $tmp = $lines[ 0 ];
298 $lines[ 0 ] = $lines[ 1 ];
300 $_ = join( "\n", @lines ) . "\n";
302 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
303 $ENV{ PATH } = "/bin:/usr/bin:/usr/local/bin";
304 my $date = `date "+%a %b %d %T %Y"`;
306 $_ = "From unknown $date\n" . $_;
309 print join("", @mails );
312 print "Content-Type: text/html\n\n";
314 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
315 print "<HTML><HEAD>\n" .
316 "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short</TITLE>\n" .
318 '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
320 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@bugs.debian.org\">$short</A>" .
321 "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
323 print "$descriptivehead\n";
324 printf "<p><a href=\"%s\">View</a> this report as an mbox folder.</p>", mboxurl($ref);
329 print "</BODY></HTML>\n";