]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/bugreport.cgi
* Add close: linkage; ditch useless output cleanup in MIME::Parser
[debbugs.git] / cgi / bugreport.cgi
index fff927196debf25254b2560af08c0d0078ea5d51..5746b4f6187a21b2f9739a3860e199d0e1ef22b5 100755 (executable)
@@ -7,7 +7,6 @@ use POSIX qw(strftime tzset);
 use MIME::Parser;
 use MIME::Decoder;
 use IO::Scalar;
-use IO::Lines;
 use IO::File;
 
 #require '/usr/lib/debbugs/errorlib';
@@ -51,7 +50,7 @@ set_option('repeatmerged', $repeatmerged);
 
 my $buglog = buglog($ref);
 
-if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
+if (defined $ENV{REQUEST_METHOD} and $ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
     print "Content-Type: text/html; charset=utf-8\n";
     my @stat = stat $buglog;
     if (@stat) {
@@ -79,22 +78,21 @@ sub display_entity ($$$$\$\@) {
     $filename = '' unless defined $filename;
     $filename = decode_rfc1522($filename);
 
-    if ($top) {
+    if ($top and not $terse) {
         my $header = $entity->head;
-        if ($trim_headers and not $terse) {
+        $$this .= "<pre class=\"headers\">\n";
+        if ($trim_headers) {
              my @headers;
-             foreach (qw(From To Subject Date Cc)) {
+             foreach (qw(From To Cc Subject Date)) {
                   my $head_field = $head->get($_);
                   next unless defined $head_field and $head_field ne '';
-                  push @headers, qq($_: ) . htmlsanit(decode_rfc1522($head_field));
+                  push @headers, qq(<b>$_:</b> ) . htmlsanit(decode_rfc1522($head_field));
              }
              $$this .= join(qq(), @headers) unless $terse;
-             $$this .= qq(\n);
-        }
-        elsif (not $terse) {
+        } else {
              $$this .= htmlsanit(decode_rfc1522($entity->head->stringify));
-             $$this .= qq(\n);
         }
+        $$this .= "</pre>\n";
     }
 
     unless (($top and $type =~ m[^text(?:/plain)?(?:;|$)]) or
@@ -104,19 +102,22 @@ sub display_entity ($$$$\$\@) {
        push @dlargs, "filename=$filename" if $filename ne '';
        my $printname = $filename;
        $printname = 'Message part ' . ($#$attachments + 1) if $filename eq '';
-       $$this .= '[<a href="' . dlurl(@dlargs) . qq{">$printname</a> } .
-                 "($type, $disposition)]\n\n";
+       $$this .= '<pre class="mime">[<a href="' . bugurl(@dlargs) . qq{">$printname</a> } .
+                 "($type, $disposition)]</pre>\n";
 
        if ($msg and defined($att) and $att eq $#$attachments) {
            my $head = $entity->head;
            chomp(my $type = $entity->effective_type);
            my $body = $entity->stringify_body;
-           print "Content-Type: $type\n";
+           print "Content-Type: $type";
+           my ($charset) = $head->get('Content-Type:') =~ m/charset\s*=\s*\"?([\w-]+)\"?/i;
+           print qq(; charset="$charset") if defined $charset;
+           print "\n";
            if ($filename ne '') {
                my $qf = $filename;
                $qf =~ s/"/\\"/g;
                $qf =~ s[.*/][];
-               print qq{Content-Disposition: attachment; filename="$qf"\n};
+               print qq{Content-Disposition: inline; filename="$qf"\n};
            }
            print "\n";
            my $decoder = new MIME::Decoder($head->mime_encoding);
@@ -150,11 +151,21 @@ sub display_entity ($$$$\$\@) {
        $$this .= "</blockquote>\n";
     } else {
         if (not $terse) {
-             my $content_type = $entity->head->get('Content-Type:');
+             my $content_type = $entity->head->get('Content-Type:') || "text/html";
              my ($charset) = $content_type =~ m/charset\s*=\s*\"?([\w-]+)\"?/i;
              my $body = $entity->bodyhandle->as_string;
              $body = convert_to_utf8($body,$charset) if defined $charset;
-             $$this .= htmlsanit($body);
+             $body = htmlsanit($body);
+             $body =~ s,((ftp|http|https)://[\S~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go;
+             # The basic idea here is that we take every subpart of
+             # this regex; if it's a digit, it's a bug number, so link
+             # it; otherwise it's some other part, so kick it back
+             # out.
+             our @bugs;
+             $body =~ s[(?:(closes:\s*(?:bug)?\#?\s?)(?{ push @bugs, $^N })) #This sticks the recently closed parenthetical into @bugs
+                        (?:(\d+)(?{ push @bugs, $^N }))(?:(?:(,?\s*(?:bug)?\#?\s?)(?{push @bugs, $^N }))(?:(\d+)(?{ push @bugs, $^N })))*
+                       ][join('',map {/^\d+$/?(q(<a href=").bugurl($_).qq(">$_</a>)):$_} splice @bugs)]gxie;
+             $$this .= qq(<pre class="message">$body</pre>\n);
         }
     }
 }
@@ -163,7 +174,6 @@ my %maintainer = %{getmaintainers()};
 my %pkgsrc = %{getpkgsrc()};
 
 my $indexentry;
-my $descriptivehead;
 my $showseverity;
 
 my $tpack;
@@ -183,7 +193,7 @@ Content-Type: text/html; charset=utf-8
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
-<head><title>$debbugs::gProject $debbugs::gBug report logs - $short</title></head>
+<head><title>$short - $debbugs::gProject $debbugs::gBug report logs</title></head>
 <body>
 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
 <p>There is no record of $debbugs::gBug $short.
@@ -200,34 +210,50 @@ my @tpacks = splitpackages($tpack);
 
 if  ($status{severity} eq 'normal') {
        $showseverity = '';
-#} elsif (isstrongseverity($status{severity})) {
-#      $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
+} elsif (isstrongseverity($status{severity})) {
+       $showseverity = "Severity: <em class=\"severity\">$status{severity}</em>;\n";
 } else {
-       $showseverity = "Severity: <em>$status{severity}</em>;\n";
+       $showseverity = "Severity: $status{severity};\n";
 }
 
-$indexentry .= "<p>$showseverity";
+$indexentry .= "<div class=\"msgreceived\">\n";
 $indexentry .= htmlpackagelinks($status{package}, 0) . ";\n";
 
+foreach my $pkg (@tpacks) {
+    my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
+    my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
+
+    $indexentry .=
+            htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
+                                            : "Maintainers for $pkg are\n" },
+                           $tmaint);
+    $indexentry .= ";\nSource for $pkg is\n".
+            '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
+    $indexentry .= ".\n";
+}
+
+$indexentry .= "<br>";
 $indexentry .= htmladdresslinks("Reported by: ", \&submitterurl,
                                 $status{originator}) . ";\n";
+$indexentry .= sprintf "Date: %s.\n",
+               (strftime "%a, %e %b %Y %T UTC", localtime($status{date}));
 
-$indexentry .= "Owned by: " . htmlsanit($status{owner}) . ";\n"
+$indexentry .= "<br>Owned by: " . htmlsanit($status{owner}) . ".\n"
               if length $status{owner};
 
-my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
-$indexentry .= "Date: ".$dummy.";\n<br>";
+$indexentry .= "</div>\n";
 
 my @descstates;
 
-push @descstates, "Tags: <strong>"
-               . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
-               . "</strong>"
+$indexentry .= "<h3>$showseverity";
+$indexentry .= sprintf "Tags: %s;\n", 
+               htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
                        if length($status{tags});
+$indexentry .= "<br>" if (length($showseverity) or length($status{tags}));
 
 my @merged= split(/ /,$status{mergedwith});
 if (@merged) {
-       my $descmerged = 'merged with ';
+       my $descmerged = 'Merged with ';
        my $mseparator = '';
        for my $m (@merged) {
                $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
@@ -252,27 +278,39 @@ if (@{$status{fixed_versions}}) {
     }
     push @descstates, $fixedtext;
 } elsif (length($status{done})) {
-       push @descstates, "<strong>Done:</strong> ".htmlsanit(decode_rfc1522($status{done}));
+    push @descstates, "<strong>Done:</strong> ".htmlsanit(decode_rfc1522($status{done}));
 } elsif (length($status{forwarded})) {
-       push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
+    push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
 }
 
-$indexentry .= join(";\n", @descstates) . ";\n<br>" if @descstates;
 
-$descriptivehead = $indexentry;
-foreach my $pkg (@tpacks) {
-    my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
-    my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
+my @blockedby= split(/ /, $status{blockedby});
+if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
+    for my $b (@blockedby) {
+        my %s = %{getbugstatus($b)};
+        next if $s{"pending"} eq 'fixed' || length $s{done};
+        push @descstates, "Fix blocked by <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
+    }
+}
 
-    $descriptivehead .=
-            htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
-                                            : "Maintainers for $pkg are\n" },
-                           $tmaint);
-    $descriptivehead .= ";\nSource for $pkg is\n".
-            '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
-    $descriptivehead .= ".\n<br>";
+my @blocks= split(/ /, $status{blocks});
+if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) {
+    for my $b (@blocks) {
+        my %s = %{getbugstatus($b)};
+        next if $s{"pending"} eq 'fixed' || length $s{done};
+        push @descstates, "Blocking fix for <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
+    }
 }
 
+if ($buglog !~ m#^\Q$gSpoolDir/db#) {
+    push @descstates, "Bug is archived. No further changes may be made";
+}
+
+$indexentry .= join(";\n<br>", @descstates) . ".\n" if @descstates;
+$indexentry .= "</h3>\n";
+
+my $descriptivehead = $indexentry;
+
 my $buglogfh;
 if ($buglog =~ m/\.gz$/) {
     my $oldpath = $ENV{'PATH'};
@@ -282,12 +320,15 @@ if ($buglog =~ m/\.gz$/) {
 } else {
     $buglogfh = new IO::File "<$buglog" or &quitcgi("open log for $ref: $!");
 }
-if ($buglog !~ m#^\Q$gSpoolDir/db#) {
-    $descriptivehead .= "\n<p>Bug is <strong>archived</strong>. No further changes may be made.</p>";
-}
 
 
-my @records = read_log_records($buglogfh);
+my @records;
+eval{
+     @records = read_log_records($buglogfh);
+};
+if ($@) {
+     quitcgi("Bad bug log for $debbugs::gBug $ref. Unable to read records: $@");
+}
 undef $buglogfh;
 
 =head2 handle_email_message
@@ -308,19 +349,41 @@ sub handle_email_message{
 
      my $output = '';
      my $parser = new MIME::Parser;
+     # Because we are using memory, not tempfiles, there's no need to
+     # clean up here like in Debbugs::MIME
      $parser->tmp_to_core(1);
      $parser->output_to_core(1);
-     # $parser->output_under("/tmp");
      my $entity = $parser->parse_data( $email);
-     # TODO: make local subdir, clean it ourselves
-     # the following does NOT delete the msg dirs in /tmp
-     END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
      my @attachments = ();
      display_entity($entity, $options{ref}, 1, $options{msg_number}, $output, @attachments);
      return $output;
 
 }
 
+=head2 bug_links
+
+     bug_links($one_bug);
+     bug_links($starting_bug,$stoping_bugs,);
+
+Creates a set of links to bugs, starting with bug number
+$starting_bug, and finishing with $stoping_bug; if only one bug is
+passed, makes a link to only a single bug.
+
+The content of the link is the bug number.
+
+=cut
+
+sub bug_links{
+     my ($start,$stop,$query_arguments) = @_;
+     $stop = $stop || $start;
+     $query_arguments ||= '';
+     my @output;
+     for my $bug ($start..$stop) {
+         push @output,'<a href="'.bugurl($bug,'').qq(">$bug</a>);
+     }
+     return join(', ',@output);
+}
+
 =head2 handle_record
 
      push @log, handle_record($record,$ref,$msg_num);
@@ -338,8 +401,17 @@ sub handle_record{
      local $_ = $record->{type};
      if (/html/) {
          $output .= decode_rfc1522($record->{text});
+         # Link to forwarded http:// urls in the midst of the report
+         # (even though these links already exist at the top)
+         $output =~ s,((?:ftp|http|https)://[\S~-]+?/?)([\)\'\:\.\,]?(?:\s|\.<|$)),<a href=\"$1\">$1</a>$2,go;
+         # Add links to the cloned bugs
+         $output =~ s{(Bug )(\d+)( cloned as bugs? )(\d+)(?:\-(\d+)|)}{$1.bug_links($2).$3.bug_links($4,$5)}eo;
+         # Add links to merged bugs
+         $output =~ s{(?<=Merged )([\d\s]+)(?=\.)}{join(' ',map {bug_links($_)} (split /\s+/, $1))}eo;
          $output .= '<a href="' . bugurl($ref, 'msg='.($msg_number+1)) . '">Full text</a> and <a href="' .
-              bugurl($ref, 'msg='.($msg_number+1)) . '&mbox=yes">rfc822 format</a> available.</em>';
+              bugurl($ref, 'msg='.($msg_number+1), 'mbox') . '">rfc822 format</a> available.';
+
+         $output = "<div class=\"msgreceived\">\n" . $output . "</div>\n";
      }
      elsif (/recips/) {
          my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
@@ -349,12 +421,11 @@ sub handle_record{
          elsif (defined $msg_id) {
               $$seen_msg_ids{$msg_id} = 1;
          }
-         $output .= 'View this message in <a href="' . bugurl($ref, "msg=$msg_number") . '&mbox=yes">rfc822 format</a></em>';
-         $output .= '<pre class="message">' .
-              handle_email_message($record->{text},
+         $output .= 'View this message in <a href="' . bugurl($ref, "msg=$msg_number", "mbox") . '">rfc822 format</a>';
+         $output .= handle_email_message($record->{text},
                                    ref        => $bug_number,
                                    msg_number => $msg_number,
-                                  ) . '</pre>';
+                                  );
      }
      elsif (/autocheck/) {
          # Do nothing
@@ -369,13 +440,12 @@ sub handle_record{
          }
          # Incomming Mail Message
          my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/;
-         $output .= qq|<h2><a name="msg$msg_number">Message received at |.
-              htmlsanit("$received\@$hostname") . q| (<a href="| . bugurl($ref, "msg=$msg_number") . '">full text</a>'.q|, <a href="| . bugurl($ref, "msg=$msg_number") . '&mbox=yes">mbox</a>)'.":</a></h2>\n";
-         $output .= '<pre class="message">' .
-              handle_email_message($record->{text},
+         $output .= qq|<p class="msgreceived"><a name="msg$msg_number">Message received</a> at |.
+              htmlsanit("$received\@$hostname") . q| (<a href="| . bugurl($ref, "msg=$msg_number") . '">full text</a>'.q|, <a href="| . bugurl($ref, "msg=$msg_number") . ';mbox=yes">mbox</a>)'.":</p>\n";
+         $output .= handle_email_message($record->{text},
                                    ref        => $bug_number,
                                    msg_number => $msg_number,
-                                  ) . '</pre>';
+                                  );
      }
      else {
          die "Unknown record type $_";
@@ -397,12 +467,13 @@ if ( $mbox ) {
          print "Content-Type: text/plain\n\n";
      }
      else {
+         $msg_num++;
          print qq(Content-Disposition: attachment; filename="bug_${ref}_message_${msg_num}.mbox"\n);
          print "Content-Type: message/rfc822\n\n";
      }
      for my $record (@records) {
          next if $record->{type} !~ /^(?:recips|incoming-recv)$/;
-         next if not $boring and $record->{type} eq 'recips';
+         next if not $boring and $record->{type} eq 'recips' and @records > 1;
          my @lines = split( "\n", $record->{text}, -1 );
          if ( $lines[ 1 ] =~ m/^From / ) {
               my $tmp = $lines[ 0 ];
@@ -440,10 +511,13 @@ print "Content-Type: text/html; charset=utf-8\n\n";
 
 my $title = htmlsanit($status{subject});
 
+my $dummy2 = $debbugs::gWebHostBugDir;
+
 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 print "<HTML><HEAD>\n" . 
-    "<TITLE>$debbugs::gProject $debbugs::gBug report logs - $short - $title</TITLE>\n" .
-#    "<link rel=\"stylesheet\" href=\"$debbugs::gWebHostBugDir/bugs.css\" type=\"text/css\">" .
+    "<TITLE>$short - $title - $debbugs::gProject $debbugs::gBug report logs</TITLE>\n" .
+     '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'.
+     "<link rel=\"stylesheet\" href=\"$debbugs::gWebHostBugDir/css/bugs.css\" type=\"text/css\">" .
     "</HEAD>\n" .
     '<BODY>' .
     "\n";
@@ -451,9 +525,11 @@ print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto
       "<BR>" . $title . "</H1>\n";
 
 print "$descriptivehead\n";
-printf "<p>View this report as an <a href=\"%s\">mbox folder</a>.</p>\n", mboxurl($ref);
+printf "<div class=\"msgreceived\"><p>View this report as an <a href=\"%s\">mbox folder</a>.</p></div>\n", bugurl($ref, "mbox");
 print "<HR>";
 print "$log";
+print "<HR>";
+print "<p class=\"msgreceived\">Send a report that <a href=\"/cgi-bin/bugspam.cgi?bug=$ref\">this bug log contains spam</a>.</p>\n<HR>\n";
 print $tail_html;
 
 print "</BODY></HTML>\n";