X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FCGI%2FBugreport.pm;h=888a1b37b11fd16bb27139b991d86c7eea8cee2f;hb=9ba3b5ba7379ac06399d7b296e7796b65fad6149;hp=d085ed4fb76681c4ca9f20a6ce1dabea01f177c8;hpb=305a309e2c038f2ebf4c2f603a00cea175eea3f0;p=debbugs.git diff --git a/Debbugs/CGI/Bugreport.pm b/Debbugs/CGI/Bugreport.pm index d085ed4..888a1b3 100644 --- a/Debbugs/CGI/Bugreport.pm +++ b/Debbugs/CGI/Bugreport.pm @@ -28,7 +28,7 @@ None known. use warnings; use strict; use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT); -use base qw(Exporter); +use Exporter qw(import); use IO::Scalar; use Params::Validate qw(validate_with :types); @@ -39,10 +39,12 @@ use Debbugs::CGI qw(:url :html :util); use Debbugs::Common qw(globify_scalar english_join); use Debbugs::UTF8; use Debbugs::Config qw(:config); +use Debbugs::Log qw(:read); use POSIX qw(strftime); use Encode qw(decode_utf8 encode_utf8); use URI::Escape qw(uri_escape_utf8); use Scalar::Util qw(blessed); +use File::Temp; BEGIN{ ($VERSION) = q$Revision: 494 $ =~ /^Revision:\s+([^\s+])/; @@ -124,7 +126,6 @@ sub display_entity { my $output = globify_scalar($param{output}); my $entity = $param{entity}; my $ref = $param{bug_num}; - my $top = $param{outer}; my $xmessage = $param{msg_num}; my $attachments = $param{attachments}; @@ -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 - ((?:\>\;)?[)]?(?:'|\&\#39\;)?[:.\,]?(?:\s|$)) # terminators + ((?:\>\;)?[)]?(?:'|\&\#39\;|\"\;)?[:.\,]?(?:\s|$)) # terminators }{$1$2}gox; # Add links to bug closures $body =~ s[((?:closes|see):\s* # start of closed/referenced bugs @@ -312,20 +313,26 @@ appropriate. =cut sub handle_email_message{ - my ($email,%param) = @_; + my ($record,%param) = @_; my $output; my $output_fh = globify_scalar(\$output); my $entity; - if (not blessed $email) { + my $tempdir; + if (not blessed $record) { 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); - $entity = $parser->parse_data( $email); + # this will be cleaned up once it goes out of scope + $tempdir = File::Temp->newdir(); + $parser->output_under($tempdir->dirname()); + if ($record->{inner_file}) { + $entity = $parser->parse($record->{fh}) or + die "Unable to parse entity"; + } else { + $entity = $parser->parse_data($record->{text}) or + die "Unable to parse entity"; + } } else { - $entity = $email + $entity = $record; } my @attachments = (); my $raw_output = @@ -363,13 +370,14 @@ sub handle_record{ local $_ = $record->{type}; if (/html/) { # $record->{text} is not in perl's internal encoding; convert it - my $text = decode_rfc1522(decode_utf8($record->{text})); + my $text = decode_rfc1522(decode_utf8(record_text($record))); my ($time) = $text =~ //; my $class = $text =~ /^(?:Acknowledgement|Reply|Information|Report|Notification)/m ? 'infmessage':'msgreceived'; $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|\.<|$)),$1$2,go; + $output =~ s,((?:ftp|http|https)://[\S~-]+?/?)((?:[\)\'\:\.\,]|\&\#39;|\"\;)? + (?:\s|\.<|$)),$1$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 +394,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($2).$3.q($4).$5}eo; + $output =~ s{($config{bug}\sreassigned\sfrom\spackage\s(?:[\`']|\&\#39;))([^']+?)((?:'|\&\#39;|\"\;) + \sto\s(?:[\`']|\&\#39;|\"\;))([^']+?)((?:'|\&\#39;|\"\;))} + {$1.package_links(package=>$2).$3. + package_links(package=>$4).$5}exo; if (defined $time) { $output .= ' ('.strftime('%a, %d %b %Y %T GMT',gmtime($time)).') '; } @@ -406,8 +416,8 @@ sub handle_record{ $output = qq(

\n\n) . $output . "
\n"; } elsif (/recips/) { - my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im; - if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) { + my ($msg_id) = record_regex($record,qr/^Message-Id:\s+<(.+)>/i); + if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) { return (); } elsif (defined $msg_id) { @@ -415,7 +425,7 @@ sub handle_record{ } $output .= qq(

\n); $output .= 'View this message in rfc822 format

'; - $output .= handle_email_message($record->{text}, + $output .= handle_email_message($record, ref => $bug_number, msg_num => $msg_number, %param, @@ -425,7 +435,7 @@ sub handle_record{ # Do nothing } elsif (/incoming-recv/) { - my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im; + my ($msg_id) = record_regex($record,qr/^Message-Id:\s+<(.+)>/i); if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) { return (); } @@ -433,7 +443,7 @@ sub handle_record{ $$seen_msg_ids{$msg_id} = 1; } # Incomming Mail Message - my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/; + my ($received,$hostname) = record_regex($record,qr/Received: \(at (\S+)\) by (\S+)\;/o); $output .= qq|

Message #$msg_number received at |. html_escape("$received\@$hostname") . q| (full text'. @@ -444,11 +454,16 @@ sub handle_record{ ) ) .'">mbox, '; 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); - my $entity = $parser->parse_data($record->{text}); + + # this will be cleaned up once it goes out of scope + my $tempdir = File::Temp->newdir(); + $parser->output_under($tempdir->dirname()); + my $entity; + if ($record->{inner_file}) { + $entity = $parser->parse($record->{fh}); + } else { + $entity = $parser->parse_data($record->{text}); + } my $r_l = reply_headers($entity); $output .= q(