From: cjwatson <> Date: Sat, 9 Apr 2005 23:21:02 +0000 (-0800) Subject: [project @ 2005-04-09 16:21:02 by cjwatson] X-Git-Tag: release/2.6.0~730 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=65ca02a0e5a986b9d101b311005867e34d42ac0e;p=debbugs.git [project @ 2005-04-09 16:21:02 by cjwatson] Decode RFC1522 mail headers for display in the web interface. bugreport.cgi and pkgreport.cgi now output UTF-8. This introduces .summary format version 3, in which all metadata is stored in UTF-8. Due to a lack of testing and no migration script, this is not yet the default. When reading/writing earlier format versions, RFC1522 metadata is automatically decoded/encoded. --- diff --git a/cgi/bugreport.cgi b/cgi/bugreport.cgi index 324b4a1..166d2d8 100755 --- a/cgi/bugreport.cgi +++ b/cgi/bugreport.cgi @@ -43,7 +43,7 @@ set_option('repeatmerged', $repeatmerged); my $buglog = buglog($ref); if ($ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) { - print "Content-Type: text/html\n"; + print "Content-Type: text/html; charset=utf-8\n"; my @stat = stat $buglog; if (@stat) { my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]); @@ -70,7 +70,8 @@ sub display_entity ($$$$\$\@) { $filename = '' unless defined $filename; if ($top) { - $$this .= htmlsanit($entity->stringify_header) unless ($terse); + $$this .= htmlsanit(decode_rfc1522($entity->stringify_header)) + unless ($terse); $$this .= "\n"; } @@ -150,7 +151,7 @@ $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/; my %status = %{getbugstatus($ref)}; unless (%status) { print < @@ -448,7 +449,7 @@ if ( $mbox ) { print join("", @mails ); exit 0; } -print "Content-Type: text/html\n\n"; +print "Content-Type: text/html; charset=utf-8\n\n"; my $title = htmlsanit($status{subject}); diff --git a/cgi/common.pl b/cgi/common.pl index 18b60cd..2c0bf94 100644 --- a/cgi/common.pl +++ b/cgi/common.pl @@ -11,6 +11,7 @@ $lib_path = '/usr/lib/debbugs'; require "$lib_path/errorlib"; use Debbugs::Versions; +use Debbugs::MIME qw(decode_rfc1522); $MLDBM::RemoveTaint = 1; diff --git a/cgi/pkgreport.cgi b/cgi/pkgreport.cgi index 0b98106..1955c4f 100755 --- a/cgi/pkgreport.cgi +++ b/cgi/pkgreport.cgi @@ -14,7 +14,7 @@ require '/etc/debbugs/text'; use vars qw($gPackagePages $gWebDomain); if (defined $ENV{REQUEST_METHOD} and $ENV{REQUEST_METHOD} eq 'HEAD') { - print "Content-Type: text/html\n\n"; + print "Content-Type: text/html; charset=utf-8\n\n"; exit 0; } @@ -234,7 +234,7 @@ if (defined $pkg) { my $result = htmlizebugs(\@bugs); -print "Content-Type: text/html\n\n"; +print "Content-Type: text/html; charset=utf-8\n\n"; print "\n"; print "\n" . diff --git a/debian/changelog b/debian/changelog index 2182a15..e1b25e4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -23,6 +23,8 @@ debbugs (2.4.2) UNRELEASED; urgency=low - Add X-$gProject-PR-Message: headers to all mails sent by service. - debbugsconfig creates required directories in $gSpoolDir (closes: #222077). + - Decode RFC1522 mail headers for display in the web interface. + bugreport.cgi and pkgreport.cgi now output UTF-8. * Adam Heath: - Rewrite filtering in cgi's common.pl, to make it completely generic. diff --git a/scripts/errorlib.in b/scripts/errorlib.in index 63fa332..cdf1855 100755 --- a/scripts/errorlib.in +++ b/scripts/errorlib.in @@ -1,7 +1,8 @@ # -*- perl -*- -# $Id: errorlib.in,v 1.41 2004/02/15 16:12:00 cjwatson Exp $ +# $Id: errorlib.in,v 1.42 2005/04/09 16:21:02 cjwatson Exp $ use Mail::Address; +use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522); sub F_SETLK { 6; } sub F_WRLCK{ 1; } $flockstruct= 'sslll'; # And there ought to be something for this too. @@ -86,6 +87,9 @@ my %fields = (originator => 'submitter', owner => 'owner', ); +# Fields which need to be RFC1522-decoded in format versions earlier than 3. +my @rfc1522_fields = qw(originator subject done forwarded owner); + sub readbug { my ($lref, $location) = @_; my $status = getbugcomponent($lref, 'summary', $location); @@ -103,8 +107,8 @@ sub readbug { $version = $1 if /^Format-Version: ([0-9]+)/i; } - # Version 2 is the latest format version currently supported. - return undef if $version > 2; + # Version 3 is the latest format version currently supported. + return undef if $version > 3; my %namemap = reverse %fields; for my $line (@lines) { @@ -121,6 +125,12 @@ sub readbug { $data{severity} = 'normal' if $data{severity} eq ''; + if ($version < 3) { + for my $field (@rfc1522_fields) { + $data{$field} = decode_rfc1522($data{$field}); + } + } + return \%data; } @@ -139,24 +149,31 @@ sub makestatus { my $contents = ''; + my %newdata = %$data; + if ($version < 3) { + for my $field (@rfc1522_fields) { + $newdata{$field} = encode_rfc1522($newdata{$field}); + } + } + if ($version == 1) { for my $field (@v1fieldorder) { - if (exists $data->{$field}) { - $contents .= "$data->{$field}\n"; + if (exists $newdata{$field}) { + $contents .= "$newdata{$field}\n"; } else { $contents .= "\n"; } } - } elsif ($version == 2) { - # Version 2. Add a file format version number for the sake of + } elsif ($version == 2 or $version == 3) { + # Version 2 or 3. Add a file format version number for the sake of # further extensibility in the future. - $contents .= "Format-Version: 2\n"; + $contents .= "Format-Version: $version\n"; for my $field (keys %fields) { - if (exists $data->{$field} and $data->{$field} ne '') { + if (exists $newdata{$field} and $newdata{$field} ne '') { # Output field names in proper case, e.g. 'Merged-With'. my $properfield = $fields{$field}; $properfield =~ s/(?:^|(?<=-))([a-z])/\u$1/g; - $contents .= "$properfield: $data->{$field}\n"; + $contents .= "$properfield: $newdata{$field}\n"; } } } diff --git a/scripts/process.in b/scripts/process.in index d4bf806..a5cdf4d 100755 --- a/scripts/process.in +++ b/scripts/process.in @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: process.in,v 1.88 2005/01/02 19:08:12 cjwatson Exp $ +# $Id: process.in,v 1.89 2005/04/09 16:21:02 cjwatson Exp $ # # Usage: process nn # Temps: incoming/Pnn @@ -9,6 +9,7 @@ $ENV{"TZ"} = 'UTC'; tzset(); use MIME::Parser; +use Debbugs::MIME qw(decode_rfc1522); $config_path = '/etc/debbugs'; $lib_path = '/usr/lib/debbugs'; @@ -108,7 +109,7 @@ for my $hdr (@headerlines) { if (s/^(\S+):\s*//) { my $v = lc $1; print DEBUG ">$v=$_<\n"; - $header{$v} = $_; + $header{$v} = decode_rfc1522($_); } else { print DEBUG "!>$_<\n"; } diff --git a/scripts/service.in b/scripts/service.in index 24e9d99..8361b9f 100755 --- a/scripts/service.in +++ b/scripts/service.in @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: service.in,v 1.98 2005/03/15 21:40:41 cjwatson Exp $ +# $Id: service.in,v 1.99 2005/04/09 16:21:02 cjwatson Exp $ # # Usage: service .nn # Temps: incoming/P.nn use File::Copy; use MIME::Parser; +use Debbugs::MIME qw(decode_rfc1522); $config_path = '/etc/debbugs'; $lib_path = '/usr/lib/debbugs'; @@ -76,7 +77,7 @@ for (@headerlines) { if (s/^(\S+):\s*//) { my $v = lc $1; print ">$v=$_<\n" if $debug; - $header{$v} = $_; + $header{$v} = decode_rfc1522($_); } else { print "!>$_<\n" if $debug; }