]> git.donarmstrong.com Git - debbugs.git/blobdiff - Debbugs/CGI/Bugreport.pm
also use a filesystem in handle_email_message to avoid running out of memory
[debbugs.git] / Debbugs / CGI / Bugreport.pm
index 4793cd6ff41060c7f2e0eebc3d3fb63ac8bd5016..64211884e1ac47d1e41961d267361801be82d9eb 100644 (file)
@@ -41,8 +41,9 @@ use Debbugs::UTF8;
 use Debbugs::Config qw(:config);
 use POSIX qw(strftime);
 use Encode qw(decode_utf8 encode_utf8);
-use URI::Escape qw(uri_escape);
+use URI::Escape qw(uri_escape_utf8);
 use Scalar::Util qw(blessed);
+use File::Temp;
 
 BEGIN{
      ($VERSION) = q$Revision: 494 $ =~ /^Revision:\s+([^\s+])/;
@@ -271,7 +272,7 @@ sub display_entity {
         # We don't html escape here because we escape above;
         # wierd terminators are because of that
         $body =~ s{((?:ftp|http|https|svn|ftps|rsync)://[\S~-]+?/?) # Url
-                   ((?:\&gt\;)?[)]?(?:'|\&\#39\;)?[:.\,]?(?:\s|$)) # terminators
+                   ((?:\&gt\;)?[)]?(?:'|\&\#39\;|\&quot\;)?[:.\,]?(?:\s|$)) # terminators
              }{<a href=\"$1\">$1</a>$2}gox;
         # Add links to bug closures
         $body =~ s[((?:closes|see):\s* # start of closed/referenced bugs
@@ -321,8 +322,9 @@ sub handle_email_message{
          my $parser = MIME::Parser->new();
          # 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);
+         # this will be cleaned up once it goes out of scope
+         my $tempdir = File::Temp->newdir();
+         $parser->output_under($tempdir->dirname());
          $entity = $parser->parse_data( $email);
      } else {
          $entity = $email
@@ -369,7 +371,8 @@ sub handle_record{
          $output .= $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~-]+?/?)((?:[\)\'\:\.\,]|\&\#39;)?(?:\s|\.<|$)),<a href=\"$1\">$1</a>$2,go;
+         $output =~ s,((?:ftp|http|https)://[\S~-]+?/?)((?:[\)\'\:\.\,]|\&\#39;|\&quot\;)?
+                           (?:\s|\.<|$)),<a href=\"$1\">$1</a>$2,gxo;
          # Add links to the cloned bugs
          $output =~ s{(Bug )(\d+)( cloned as bugs? )(\d+)(?:\-(\d+)|)}{$1.bug_links(bug=>$2).$3.bug_links(bug=>(defined $5)?[$4..$5]:$4)}eo;
          # Add links to merged bugs
@@ -386,8 +389,10 @@ sub handle_record{
                      {$1.$2.(bug_links(bug=>$3)).$4.
                           english_join([map {bug_links(bug=>$_)} (split /\,?\s+(?:and\s+)?/, $5)])}eo;
          # Add links to reassigned packages
-         $output =~ s{(Bug reassigned from package (?:[\`']|\&\#39;))([^']+?)((?:'|\&\#39;) to (?:[\`']|\&\#39;))([^']+?)((?:'|\&\#39;))}
-         {$1.q(<a href=").html_escape(package_links(package=>$2)).qq(">$2</a>).$3.q(<a href=").html_escape(package_links(package=>$4)).qq(">$4</a>).$5}eo;
+         $output =~ s{(Bug\sreassigned\sfrom\spackage\s(?:[\`']|\&\#39;))([^']+?)((?:'|\&\#39;|\&quot\;)
+                               \sto\s(?:[\`']|\&\#39;|\&quot\;))([^']+?)((?:'|\&\#39;|\&quot\;))}
+         {$1.q(<a href=").html_escape(package_links(package=>$2)).qq(">$2</a>).$3.
+               q(<a href=").html_escape(package_links(package=>$4)).qq(">$4</a>).$5}exo;
          if (defined $time) {
               $output .= ' ('.strftime('%a, %d %b %Y %T GMT',gmtime($time)).') ';
          }
@@ -444,15 +449,15 @@ sub handle_record{
                                                               )
                                                     ) .'">mbox</a>, ';
           my $parser = MIME::Parser->new();
-          # 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);
+
+          # this will be cleaned up once it goes out of scope
+          my $tempdir = File::Temp->newdir();
+          $parser->output_under($tempdir->dirname());
           my $entity = $parser->parse_data($record->{text});
           my $r_l = reply_headers($entity);
           $output .= q(<a href=").
               html_escape('mailto:'.$bug_number.'@'.$config{email_domain}.'?'.
-                          join('&',map {defined $r_l->{$_}?$_.'='.uri_escape($r_l->{$_}):()} keys %{$r_l})).
+                          join('&',map {defined $r_l->{$_}?$_.'='.uri_escape_utf8($r_l->{$_}):()} keys %{$r_l})).
                               qq(">reply</a>);
 
           $output .= ')'.":</p>\n";
@@ -474,8 +479,8 @@ sub __libravatar_url {
     if (not defined $config{libravatar_uri} or not length $config{libravatar_uri}) {
         return undef;
     }
-    ($email) = get_addresses($email);
-    return $config{libravatar_uri}.uri_escape($email.($config{libravatar_uri_options}//''));
+    ($email) = grep {/\@/} get_addresses($email);
+    return $config{libravatar_uri}.uri_escape_utf8($email.($config{libravatar_uri_options}//''));
 }