]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/bugreport.cgi
abstract out no_such_bug
[debbugs.git] / cgi / bugreport.cgi
index bf1db2d3ce3fa976945fdcbb6e9e4cdbf19c44e6..b68eac64b7f9ba7c92d38e0d151ce1431362d18f 100755 (executable)
@@ -73,6 +73,17 @@ my $mbox = $param{'mbox'} eq 'yes';
 my $mime = $param{'mime'} eq 'yes';
 my $avatars = $param{avatars} eq 'yes';
 
+my $trim_headers = ($param{trim} || ((defined $msg and $msg)?'no':'yes')) eq 'yes';
+
+my $mbox_status_message = $param{mboxstat} eq 'yes';
+my $mbox_maint = $param{mboxmaint} 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'} eq 'yes';
+my $repeatmerged = $param{'repeatmerged'} eq 'yes';
+
 my %bugusertags;
 my %ut;
 my %seen_users;
@@ -80,16 +91,24 @@ my %seen_users;
 my $buglog = buglog($ref);
 my $bug_status = bug_status($ref);
 if (not defined $buglog or not defined $bug_status) {
-     print $q->header(-status => "404 No such bug",
-                     -type => "text/html",
-                     -charset => 'utf-8',
-                    );
-     print fill_in_template(template=>'cgi/no_such_bug',
-                           variables => {modify_time => strftime('%a, %e %b %Y %T UTC', gmtime),
-                                         bug_num     => $ref,
-                                        },
-                          );
-     exit 0;
+    no_such_bug($q,$ref);
+}
+
+sub no_such_bug {
+    my ($q,$ref) = @_;
+    print $q->header(-status => 404,
+                    -content_type => "text/html",
+                    -charset => 'utf-8',
+                    -cache_control => 'public, max-age=600',
+                   );
+    print fill_in_template(template=>'cgi/no_such_bug',
+                          variables => {modify_time => strftime('%a, %e %b %Y %T UTC', gmtime),
+                                        bug_num     => $ref,
+                                       },
+                         );
+    exit 0;
+}
+
 }
 
 # the log should almost always be newer, but just in case
@@ -124,20 +143,6 @@ if (defined $param{usertag}) {
 }
 
 
-my $trim_headers = ($param{trim} || ((defined $msg and $msg)?'no':'yes')) eq 'yes';
-
-my $mbox_status_message = $param{mboxstat} eq 'yes';
-my $mbox_maint = $param{mboxmaint} 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'} eq 'yes';
-my $repeatmerged = $param{'repeatmerged'} eq 'yes';
-
-
-
 my $buglogfh;
 if ($buglog =~ m/\.gz$/) {
     my $oldpath = $ENV{'PATH'};
@@ -235,6 +240,8 @@ END
       if ($record->{inner_file}) {
           push @lines, $record->{fh}->getline;
           push @lines, $record->{fh}->getline;
+          chomp $lines[0];
+          chomp $lines[1];
       } else {
           @lines = split( "\n", $record->{text}, -1 );
       }
@@ -243,11 +250,12 @@ END
          }
          if ( !( $lines[ 0 ] =~ m/^From / ) ) {
               unshift @lines, "From unknown $date";
-         }
+       }
+      print $lines[0]."\n";
          print map { s/^(>*From )/>$1/; $_."\n" } @lines[ 1 .. $#lines ];
       if ($record->{inner_file}) {
           my $fh = $record->{fh};
-          print <$fh>;
+          print $_ while (<$fh>);
       }
      }
      exit 0;
@@ -300,16 +308,7 @@ my $tmain;
 my $dtime = strftime "%a, %e %b %Y %T UTC", gmtime;
 
 unless (%status) {
-    print $q->header(-type => "text/html",
-                    -charset => 'utf-8',
-                    (length $mtime)?(-last_modified => $mtime):(),
-                   );
-    print fill_in_template(template=>'cgi/no_such_bug',
-                          variables => {modify_time => $dtime,
-                                        bug_num     => $ref,
-                                       },
-                         );
-    exit 0;
+    no_such_bug($q,$ref);
 }
 
 #$|=1;