]> git.donarmstrong.com Git - debbugs.git/blobdiff - scripts/process
Handle RFC1522 escaped commas in structured headers (#1041638)
[debbugs.git] / scripts / process
index 3da8f983c4a13ea773fe808a6f8136018b918a9d..831099867c0dce57e5f60932c4c5b86c70500564 100755 (executable)
@@ -30,7 +30,7 @@ use Debbugs::Text qw(:templates);
 
 use Debbugs::Config qw(:globals :config);
 
-use Debbugs::Control qw(append_action_to_log);
+use Debbugs::Control qw(append_action_to_log valid_usertag);
 use Debbugs::Control::Service qw(valid_control control_line);
 use Debbugs::Recipients qw(determine_recipients);
 use Encode qw(encode_utf8 decode);
@@ -184,7 +184,7 @@ for my $hdr (@headerlines) {
                         mail-followup-to|
                         references):
                 |From\s|X-Debbugs-)/xi;
-    $fwd .= encode_utf8($hdr)."\n" if $ins;
+    $fwd .= $orig_hdr."\n" if $ins;
     # print {$debugfh} ">$_<\n";
     if (s/^(\S+):\s*//) {
        my $v = lc $1;
@@ -192,7 +192,13 @@ for my $hdr (@headerlines) {
            push @common_headers, 'X-Loop',$_;
        }
        print {$debugfh} ">$v=$_<\n";
-       $header{$v} = $_;
+       # Handle a comma which is escaped being passed through un-escaped. See
+       # https://bugs.debian.org/1041638
+       if ($_ =~ m/,/ and not $orig_hdr =~ m/,/) {
+           $header{$v} = handle_escaped_commas($_,$orig_hdr);
+       } else {
+           $header{$v} = $_;
+       }
     } else {
        print {$debugfh} "!>$_<\n";
     }
@@ -220,6 +226,7 @@ if (@bodylines and $bodylines[0] =~ /^-----BEGIN PGP SIGNED/) {
 #psuedoheaders
 my %pheader;
 my @control_bits;
+my @usertag_bits;
 # extract pseudo-headers
 for my $phline (@bodylines)
 {
@@ -233,15 +240,18 @@ for my $phline (@bodylines)
                         (\S.*)/x; # pseudoheader value
     my ($fn, $fv) = ($1, $2);
     $fv =~ s/\s*$//;
+    $fn = lc $fn;
     # pluralize tag/usertag
     $fn = $fn.'s' if $fn =~ /^(?:tag|usertag)$/;
     print {$debugfh} ">$fn|$fv|\n";
-    $fn = lc $fn;
     if ($fn =~ /^control$/) {
        push @control_bits,$fv;
+    } elsif ($fn =~ /^(?:user|usertags)$/) {
+       $fv = lc $fv;
+       push @usertag_bits, [$fn, $fv];
     } else {
        # Don't lc owner or forwarded
-       $fv = lc $fv unless $fn =~ /^(?:owner|forwarded|usertags|version|source-version)$/;
+       $fv = lc $fv unless $fn =~ /^(?:owner|forwarded|version|source-version|done)$/;
        $pheader{$fn} = $fv;
     }
     print {$debugfh} ">$fn~$fv<\n";
@@ -390,7 +400,7 @@ if ($codeletter eq 'D' || $codeletter eq 'F')
         }
         $receivedat= "done\@$gEmailDomain";
         $markaswhat= 'done';
-        $set_done= $header{'from'};
+        $set_done= $pheader{'done'} // $header{'from'};
        if ( length( $gListDomain ) > 0 && length( $gDoneList ) > 0 ) {
             $generalcc= "$gDoneList\@$gListDomain";
            push @generalcc, "$gDoneList\@$gListDomain";
@@ -696,32 +706,38 @@ if ($ref<0) { # new bug report
     $data->{msgid} = $header{'message-id'};
     writebug($ref, $data);
     # Deal with usertags
-    if (exists $pheader{usertags}) {
-        my $user = $replyto;
-        $user = $pheader{user} if exists $pheader{user};
-        $user =~ s/,.*//;
-        $user =~ s/^.*<(.*)>.*$/$1/;
-        $user =~ s/[(].*[)]//;
-        $user =~ s/^\s*(\S+)\s+.*$/$1/;
-        if ($user ne '' and Debbugs::User::is_valid_user($user)) {
-             $pheader{usertags} =~ s/(?:^\s+|\s+$)//g;
-             my %user_tags;
-             read_usertags(\%user_tags,$user);
-             for my $tag (split /[,\s]+/, $pheader{usertags}) {
-                  if ($tag =~ /^[a-zA-Z0-9.+\@-]+/) {
-                       my %bugs_with_tag; 
-                       @bugs_with_tag{@{$user_tags{$tag}||[]}} = (1) x @{$user_tags{$tag}||[]};
-                       $bugs_with_tag{$ref} = 1;
-                       $user_tags{$tag} = [keys %bugs_with_tag];
-                  }
-             }
-             write_usertags(\%user_tags,$user);
-        }
-        else {
-             $brokenness .= fill_template('mail/invalid_user',
-                                          {user => $user}
-                                         );
-        }
+    my $current_user;
+    unshift @usertag_bits, ['user', $replyto];
+    for my $field (@usertag_bits) {
+        my ($name, $value) = @$field;
+        if ($name eq 'user') {
+            my $user = $value;
+            $user =~ s/,.*//;
+            $user =~ s/^.*<(.*)>.*$/$1/;
+            $user =~ s/[(].*[)]//;
+            $user =~ s/^\s*(\S+)\s+.*$/$1/;
+            if ($user ne '' and Debbugs::User::is_valid_user($user)) {
+                $current_user = $user;
+            } else {
+                $brokenness .= fill_template('mail/invalid_user',
+                                             {user => $user}
+                                            );
+            }
+        }
+        if ($name eq 'usertags' and defined $current_user){
+            my %user_tags;
+            read_usertags(\%user_tags, $current_user);
+            $value =~ s/(?:^\s+|\s+$)//g;
+            for my $tag (split /[,\s]+/, $value) {
+                if (valid_usertag($tag)) {
+                    my %bugs_with_tag;
+                    @bugs_with_tag{@{$user_tags{$tag}||[]}} = (1) x @{$user_tags{$tag}||[]};
+                    $bugs_with_tag{$ref} = 1;
+                    $user_tags{$tag} = [keys %bugs_with_tag];
+                }
+            }
+            write_usertags(\%user_tags,$current_user);
+        }
     }
     overwritefile("db-h/$hash/$ref.report",
                  map {"$_\n"} @msg);