]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/bugreport.cgi
show version graph link on bugreport.cgi
[debbugs.git] / cgi / bugreport.cgi
index c8ded557fab557d4ad2d23e1a9b9768ed87d5961..7dd91d4431d02b83ac3fba17587c4ba753a5d640 100755 (executable)
@@ -2,6 +2,7 @@
 
 package debbugs;
 
+use warnings;
 use strict;
 use POSIX qw(strftime tzset);
 use MIME::Parser;
@@ -9,17 +10,16 @@ use MIME::Decoder;
 use IO::Scalar;
 use IO::File;
 
+use Debbugs::Config qw(:globals);
 #require '/usr/lib/debbugs/errorlib';
 require './common.pl';
 
-require '/etc/debbugs/config';
 require '/etc/debbugs/text';
 
-use vars(qw($gEmailDomain $gHTMLTail $gSpoolDir $gWebDomain));
-
 # for read_log_records
 use Debbugs::Log;
-use Debbugs::MIME qw(convert_to_utf8 decode_rfc1522);
+use Debbugs::MIME qw(convert_to_utf8 decode_rfc1522 create_mime_message);
+use Debbugs::CGI qw(:url :html version_url);
 
 use Scalar::Util qw(looks_like_number);
 
@@ -41,6 +41,11 @@ my $mime = ($param{'mime'} || 'yes') eq 'yes';
 
 my $trim_headers = ($param{trim} || ($msg?'no':'yes')) eq 'yes';
 
+my $mbox_status_message = ($param{mboxstat}||'no') eq 'yes';
+my $mbox_maint = ($param{mboxmaint}||'no') eq 'yes';
+$mbox = 1 if $mbox_status_message or $mbox_maint;
+
+
 # Not used by this script directly, but fetch these so that pkgurl() and
 # friends can propagate them correctly.
 my $archive = ($param{'archive'} || 'no') eq 'yes';
@@ -109,12 +114,15 @@ sub display_entity ($$$$\$\@) {
            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);
@@ -153,10 +161,12 @@ sub display_entity ($$$$\$\@) {
              my $body = $entity->bodyhandle->as_string;
              $body = convert_to_utf8($body,$charset) if defined $charset;
              $body = htmlsanit($body);
+             # Add links to URLs
              $body =~ s,((ftp|http|https)://[\S~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go;
-             $$this .= "<pre class=\"message\">";
-             $$this .= $body;
-             $$this .= "</pre>\n";
+             # Add links to bug closures
+             $body =~ s[(closes:\s*(?:bug)?\#?\s?\d+(?:,?\s*(?:bug)?\#?\s?\d+)*)
+                       ][my $temp = $1; $temp =~ s{(\d+)}{qq(<a href=").bugurl($1).qq(">$1</a>)}ge; $temp;]gxie;
+             $$this .= qq(<pre class="message">$body</pre>\n);
         }
     }
 }
@@ -170,10 +180,7 @@ my $showseverity;
 my $tpack;
 my $tmain;
 
-$ENV{"TZ"} = 'UTC';
-tzset();
-
-my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
+my $dtime = strftime "%a, %e %b %Y %T UTC", gmtime;
 $tail_html = $debbugs::gHTMLTail;
 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
 
@@ -268,6 +275,12 @@ if (@{$status{fixed_versions}}) {
        $fixedtext .= ' by ' . htmlsanit(decode_rfc1522($status{done}));
     }
     push @descstates, $fixedtext;
+    push @descstates, '<a href="'.
+        version_url($status{package},
+                    $status{found_versions},
+                    $status{fixed_versions},
+                   ).qq{">Version Graph</a>};
+
 } elsif (length($status{done})) {
     push @descstates, "<strong>Done:</strong> ".htmlsanit(decode_rfc1522($status{done}));
 } elsif (length($status{forwarded})) {
@@ -340,43 +353,17 @@ 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);
@@ -393,16 +380,26 @@ sub handle_record{
      my $output = '';
      local $_ = $record->{type};
      if (/html/) {
+         my $class = $record->{text} =~ /^<strong>(?:Acknowledgement|Reply|Information|Report|Notification)/ ? 'infmessage':'msgreceived';
          $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;
+         # Add links to blocked bugs
+         $output =~ s{(?<=Blocking bugs)(?:(of )(\d+))?( (?:added|set to|removed):\s+)([\d\s\,]+)}
+                     {(defined $2?$1.bug_links($2):'').$3.
+                           join(' ',map {bug_links($_)} (split /\,?\s+/, $4))}eo;
+         # Add links to reassigned packages
+         $output =~ s{(Bug reassigned from package \`)([^\']+)(' to \`)([^\']+)(')}
+         {$1.q(<a href=").pkgurl($2).qq(">$2</a>).$3.q(<a href=").pkgurl($4).qq(">$4</a>).$5}eo;
          $output .= '<a href="' . bugurl($ref, 'msg='.($msg_number+1)) . '">Full text</a> and <a href="' .
-              bugurl($ref, 'msg='.($msg_number+1), 'mbox') . '">rfc822 format</a> available.</em>';
+              bugurl($ref, 'msg='.($msg_number+1), 'mbox') . '">rfc822 format</a> available.';
 
-         $output = "<div class=\"msgreceived\">\n" . $output . "</div>\n";
+         $output = qq(<div class="$class"><hr>\n<a name="$msg_number">\n) . $output . "</div>\n";
      }
      elsif (/recips/) {
          my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
@@ -412,7 +409,8 @@ 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") . '">rfc822 format</a></em>';
+         $output .= qq(<hr><a name="$msg_number">\n);
+         $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,
@@ -431,8 +429,8 @@ sub handle_record{
          }
          # Incomming Mail Message
          my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/;
-         $output .= qq|<p class="msgreceived"><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></p>\n";
+         $output .= qq|<hr><p class="msgreceived"><a name="$msg_number"><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,
@@ -453,6 +451,7 @@ if (looks_like_number($msg) and ($msg-1) <= $#records) {
 }
 my @log;
 if ( $mbox ) {
+     my $date = strftime "%a %b %d %T %Y", localtime;
      if (@records > 1) {
          print qq(Content-Disposition: attachment; filename="bug_${ref}.mbox"\n);
          print "Content-Type: text/plain\n\n";
@@ -462,9 +461,49 @@ if ( $mbox ) {
          print qq(Content-Disposition: attachment; filename="bug_${ref}_message_${msg_num}.mbox"\n);
          print "Content-Type: message/rfc822\n\n";
      }
+     if ($mbox_status_message and @records > 1) {
+         my $status_message='';
+         my @status_fields = (retitle   => 'subject',
+                              package   => 'package',
+                              submitter => 'originator',
+                              severity  => 'severity',
+                              tag       => 'tags',
+                              owner     => 'owner',
+                              blocks    => 'blocks',
+                              forward   => 'forward',
+                             );
+         my ($key,$value);
+         while (($key,$value) = splice(@status_fields,0,2)) {
+              if (defined $status{$value} and length $status{$value}) {
+                   $status_message .= qq($key $ref $status{$value}\n);
+              }
+         }
+         print STDOUT qq(From unknown $date\n),
+              create_mime_message([From       => "$debbugs::gBug#$ref <$ref\@$debbugs::gEmailDomain>",
+                                   To         => "$debbugs::gBug#$ref <$ref\@$debbugs::gEmailDomain>",
+                                   Subject    => "Status: $status{subject}",
+                                   "Reply-To" => "$debbugs::gBug#$ref <$ref\@$debbugs::gEmailDomain>",
+                                  ],
+                                  <<END,);
+$status_message
+thanks
+
+
+END
+     }
+     my $message_number=0;
+     my %seen_message_ids;
      for my $record (@records) {
          next if $record->{type} !~ /^(?:recips|incoming-recv)$/;
-         next if not $boring and $record->{type} eq 'recips' and @records > 1;
+         my $wanted_type = $mbox_maint?'recips':'incoming-recv';
+         # we want to include control messages anyway
+         my $record_wanted_anyway = 0;
+         my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
+         next if exists $seen_message_ids{$msg_id};
+         $seen_message_ids{$msg_id} = 1;
+         next if $msg_id =~/handler\..+\.ack(?:info)?\@/;
+         $record_wanted_anyway = 1 if $record->{text} =~ /^Received: \(at control\)/;
+         next if not $boring and $record->{type} ne $wanted_type and not $record_wanted_anyway and @records > 1;
          my @lines = split( "\n", $record->{text}, -1 );
          if ( $lines[ 1 ] =~ m/^From / ) {
               my $tmp = $lines[ 0 ];
@@ -472,7 +511,6 @@ if ( $mbox ) {
               $lines[ 1 ] = $tmp;
          }
          if ( !( $lines[ 0 ] =~ m/^From / ) ) {
-              my $date = strftime "%a %b %d %T %Y", localtime;
               unshift @lines, "From unknown $date";
          }
          map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
@@ -495,7 +533,7 @@ else {
 }
 
 @log = reverse @log if $reverse;
-$log = join('<hr>',@log);
+$log = join("\n",@log);
 
 
 print "Content-Type: text/html; charset=utf-8\n\n";
@@ -505,19 +543,46 @@ 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>$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";
+print <<END;
+<HTML><HEAD>
+<TITLE>$short - $title - $debbugs::gProject $debbugs::gBug report logs</TITLE>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+<link rel="stylesheet" href="$debbugs::gWebHostBugDir/css/bugs.css" type="text/css">
+<script type="text/javascript">
+<!--
+function toggle_infmessages(){
+       var styles = document.styleSheets;
+       var deleted = 0
+       for (var i = 0; i < styles.length; i++) {
+          for (var j = 0; j < styles[i].cssRules.length; j++) {
+            if (styles[i].cssRules[j].cssText == ".infmessage { display: none; }") {
+                 styles[i].deleteRule(j);
+                 deleted = 1;
+            }
+          }
+       }
+       if (!deleted) {
+            styles[0].insertRule(".infmessage { display: none; }",0);
+       }
+}
+-->
+</script>
+</HEAD>
+<BODY">
+END
 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
       "<BR>" . $title . "</H1>\n";
 
 print "$descriptivehead\n";
-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 qq(<p><a href="mailto:$ref\@$debbugs::gEmailDomain">Reply</a> ),
+     qq(or <a href="mailto:$ref-subscribe\@$debbugs::gEmailDomain">subscribe</a> ),
+     qq(to this bug.</p>\n);
+print qq(<p><a href="javascript:toggle_infmessages();">Show useless messages</a></p>);
+printf qq(<div class="msgreceived"><p>View this report as an <a href="%s">mbox folder</a>, ).
+     qq(<a href="%s">status mbox</a>, <a href="%s">maintainer mbox</a></p></div>\n),
+     html_escape(bug_url($ref, mbox=>'yes')),
+     html_escape(bug_url($ref, mbox=>'yes',mboxstatus=>'yes')),
+     html_escape(bug_url($ref, mbox=>'yes',mboxmaint=>'yes'));
 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";