X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=cgi%2Fbugreport.cgi;h=dcb6482345f984479a7e20499232cb6e0d60c239;hb=c768b2faebc3e56f8e519e6ea3661c79d954defe;hp=856a35be4e8c27c785a9ab0c55da7b433e9fa648;hpb=acf5b623e6379e7e8053cf9e795d8b4931f26c3b;p=debbugs.git diff --git a/cgi/bugreport.cgi b/cgi/bugreport.cgi index 856a35b..dcb6482 100755 --- a/cgi/bugreport.cgi +++ b/cgi/bugreport.cgi @@ -2,6 +2,7 @@ use warnings; use strict; + use POSIX qw(strftime tzset); use MIME::Parser; use MIME::Decoder; @@ -14,6 +15,7 @@ use Debbugs::Config qw(:globals :text); use Debbugs::Log qw(read_log_records); use Debbugs::MIME qw(convert_to_utf8 decode_rfc1522 create_mime_message); use Debbugs::CGI qw(:url :html :util); +use Debbugs::CGI::Bugreport qw(:all); use Debbugs::Common qw(buglog getmaintainers); use Debbugs::Packages qw(getpkgsrc); use Debbugs::Status qw(splitpackages get_bug_status isstrongseverity); @@ -81,117 +83,124 @@ if (defined $ENV{REQUEST_METHOD} and $ENV{REQUEST_METHOD} eq 'HEAD' and not defi exit 0; } -sub display_entity ($$$$\$\@); -sub display_entity ($$$$\$\@) { - my $entity = shift; - my $ref = shift; - my $top = shift; - my $xmessage = shift; - my $this = shift; - my $attachments = shift; - - my $head = $entity->head; - my $disposition = $head->mime_attr('content-disposition'); - $disposition = 'inline' if not defined $disposition or $disposition eq ''; - my $type = $entity->effective_type; - my $filename = $entity->head->recommended_filename; - $filename = '' unless defined $filename; - $filename = decode_rfc1522($filename); - - if ($top and not $terse) { - my $header = $entity->head; - $$this .= "
\n"; - if ($trim_headers) { - my @headers; - foreach (qw(From To Cc Subject Date)) { - my $head_field = $head->get($_); - next unless defined $head_field and $head_field ne ''; - push @headers, qq($_: ) . html_escape(decode_rfc1522($head_field)); - } - $$this .= join(qq(), @headers) unless $terse; - } else { - $$this .= html_escape(decode_rfc1522($entity->head->stringify)); - } - $$this .= "\n"; - } - unless (($top and $type =~ m[^text(?:/plain)?(?:;|$)]) or - ($type =~ m[^multipart/])) { - push @$attachments, $entity; - my @dlargs = ($ref, msg=>$xmessage, att=>$#$attachments); - push @dlargs, (filename=>$filename) if $filename ne ''; - my $printname = $filename; - $printname = 'Message part ' . ($#$attachments + 1) if $filename eq ''; - $$this .= '
[$printname } . - "($type, $disposition)]\n"; - - if ($msg and defined($att) and $att == $#$attachments) { - my $head = $entity->head; - chomp(my $type = $entity->effective_type); - my $body = $entity->stringify_body; - 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: inline; filename="$qf"\n}; - } - print "\n"; - my $decoder = new MIME::Decoder($head->mime_encoding); - $decoder->decode(new IO::Scalar(\$body), \*STDOUT); - exit(0); - } - } +my $buglogfh; +if ($buglog =~ m/\.gz$/) { + my $oldpath = $ENV{'PATH'}; + $ENV{'PATH'} = '/bin:/usr/bin'; + $buglogfh = new IO::File "zcat $buglog |" or &quitcgi("open log for $ref: $!"); + $ENV{'PATH'} = $oldpath; +} else { + $buglogfh = new IO::File "<$buglog" or &quitcgi("open log for $ref: $!"); +} - return if not $top and $disposition eq 'attachment' and not defined($att); - return unless ($type =~ m[^text/?] and - $type !~ m[^text/(?:html|enriched)(?:;|$)]) or - $type =~ m[^application/pgp(?:;|$)] or - $entity->parts; - - if ($entity->is_multipart) { - my @parts = $entity->parts; - foreach my $part (@parts) { - display_entity($part, $ref, 0, $xmessage, - $$this, @$attachments); - $$this .= "\n"; - } - } elsif ($entity->parts) { - # We must be dealing with a nested message. - $$this .= "
\n"; - my @parts = $entity->parts; - foreach my $part (@parts) { - display_entity($part, $ref, 1, $xmessage, - $$this, @$attachments); - $$this .= "\n"; - } - $$this .= "\n"; - } else { - if (not $terse) { - 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; - $body = html_escape($body); - # Attempt to deal with format=flowed - if ($content_type =~ m/format\s*=\s*\"?flowed\"?/i) { - $body =~ s{^\ }{}mgo; - # we ignore the other things that you can do with - # flowed e-mails cause they don't really matter. - } - # Add links to URLs - $body =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; - # Add links to bug closures - $body =~ s[(closes:\s*(?:bug)?\#?\s?\d+(?:,?\s*(?:bug)?\#?\s?\d+)*) - ][my $temp = $1; $temp =~ s{(\d+)}{qq($1)}ge; $temp;]gxie; - $$this .= qq( \n); - } - } + +my @records; +eval{ + @records = read_log_records($buglogfh); +}; +if ($@) { + quitcgi("Bad bug log for $gBug $ref. Unable to read records: $@"); +} +undef $buglogfh; + + +my $log=''; +my $msg_num = 0; +my $skip_next = 0; +if (looks_like_number($msg) and ($msg-1) <= $#records) { + @records = ($records[$msg-1]); + $msg_num = $msg - 1; +} +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"; + } + else { + $msg_num++; + 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 => "$gBug#$ref <$ref\@$gEmailDomain>", + To => "$gBug#$ref <$ref\@$gEmailDomain>", + Subject => "Status: $status{subject}", + "Reply-To" => "$gBug#$ref <$ref\@$gEmailDomain>", + ], + <
There is no record of $gBug $short. -Try the search page instead.
-$tail_html -EOF + print "Content-Type: text/html; charset=utf-8\n\n"; + print fill_in_template(template=>'cgi/no_such_bug', + variables => {modify_time => $dtime, + bug_num => $ref, + }, + ) exit 0; } @@ -237,17 +240,17 @@ if ($status{severity} eq 'normal') { if (@{$status{found_versions}} or @{$status{fixed_versions}}) { $indexentry.= q(}; + html_escape(version_url(package => $status{package}, + found => $status{found_versions}, + fixed => $status{fixed_versions}, + width => 2, + height => 2, + )).qq{">}; } @@ -263,7 +266,7 @@ foreach my $pkg (@tpacks) { : "Maintainers for $pkg are\n" }, $tmaint); $indexentry .= ";\nSource for $pkg is\n". - '$tsrc" if ($tsrc ne "(unknown)"); + '$tsrc" if ($tsrc ne "(unknown)"); $indexentry .= ".\n"; } @@ -291,7 +294,7 @@ if (@merged) { my $descmerged = 'Merged with '; my $mseparator = ''; for my $m (@merged) { - $descmerged .= $mseparator."#$m"; + $descmerged .= $mseparator."#$m"; $mseparator= ",\n"; } push @descstates, $descmerged; @@ -315,10 +318,10 @@ if (@{$status{fixed_versions}}) { if (@{$status{found_versions}} or @{$status{fixed_versions}}) { push @descstates, 'Version Graph}; + html_escape(version_url($status{package}, + $status{found_versions}, + $status{fixed_versions}, + )).qq{">Version Graph}; } if (length($status{done})) { @@ -326,8 +329,8 @@ if (length($status{done})) { } if (length($status{forwarded})) { - my $forward_link = $status{forwarded}; - $forward_link =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; + my $forward_link = html_escape($status{forwarded}); + $forward_link =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; push @descstates, "Forwarded to $forward_link"; } @@ -337,7 +340,7 @@ if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) { for my $b (@blockedby) { my %s = %{get_bug_status($b)}; next if $s{"pending"} eq 'fixed' || length $s{done}; - push @descstates, "Fix blocked by #$b: ".html_escape($s{subject}); + push @descstates, "Fix blocked by #$b: ".html_escape($s{subject}); } } @@ -346,7 +349,7 @@ if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) { for my $b (@blocks) { my %s = %{get_bug_status($b)}; next if $s{"pending"} eq 'fixed' || length $s{done}; - push @descstates, "Blocking fix for #$b: ".html_escape($s{subject}); + push @descstates, "Blocking fix for #$b: ".html_escape($s{subject}); } } @@ -359,234 +362,15 @@ $indexentry .= "\n"; my $descriptivehead = $indexentry; -my $buglogfh; -if ($buglog =~ m/\.gz$/) { - my $oldpath = $ENV{'PATH'}; - $ENV{'PATH'} = '/bin:/usr/bin'; - $buglogfh = new IO::File "zcat $buglog |" or &quitcgi("open log for $ref: $!"); - $ENV{'PATH'} = $oldpath; -} else { - $buglogfh = new IO::File "<$buglog" or &quitcgi("open log for $ref: $!"); -} - - -my @records; -eval{ - @records = read_log_records($buglogfh); -}; -if ($@) { - quitcgi("Bad bug log for $gBug $ref. Unable to read records: $@"); -} -undef $buglogfh; - -=head2 handle_email_message - - handle_email_message($record->{text}, - ref => $bug_number, - msg_number => $msg_number, - ); - -Returns a decoded e-mail message and displays entities/attachments as -appropriate. - - -=cut - -sub handle_email_message{ - my ($email,%options) = @_; - - 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); - my $entity = $parser->parse_data( $email); - my @attachments = (); - display_entity($entity, $options{ref}, 1, $options{msg_number}, $output, @attachments); - return $output; - -} - -=head2 handle_record - - push @log, handle_record($record,$ref,$msg_num); - -Deals with a record in a bug log as returned by -L\n); - $output .= 'View this message in rfc822 format
'; - $output .= handle_email_message($record->{text}, - ref => $bug_number, - msg_number => $msg_number, - ); - } - elsif (/autocheck/) { - # Do nothing - } - elsif (/incoming-recv/) { - my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im; - if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) { - return (); - } - elsif (defined $msg_id) { - $$seen_msg_ids{$msg_id} = 1; - } - # Incomming Mail Message - my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/; - $output .= qq|Message received at |. - html_escape("$received\@$hostname") . - q| (full text'. - q|, mbox)'.":
\n"; - $output .= handle_email_message($record->{text}, - ref => $bug_number, - msg_number => $msg_number, - ); - } - else { - die "Unknown record type $_"; - } - return $output; -} - -my $log=''; -my $msg_num = 0; -my $skip_next = 0; -if (looks_like_number($msg) and ($msg-1) <= $#records) { - @records = ($records[$msg-1]); - $msg_num = $msg - 1; -} -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"; - } - else { - $msg_num++; - 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 => "$gBug#$ref <$ref\@$gEmailDomain>", - To => "$gBug#$ref <$ref\@$gEmailDomain>", - Subject => "Status: $status{subject}", - "Reply-To" => "$gBug#$ref <$ref\@$gEmailDomain>", - ], - <