*** SpamAssassin.pm.dist	Thu Oct 10 00:41:35 2002
--- SpamAssassin.pm	Thu Oct 10 00:48:57 2002
***************
*** 750,756 ****
  }
  
  sub create_dotsa_dir_if_needed {
!   my ($self,$userdir) = @_;
  
    # user state directory
    my $fname = $self->{userstate_dir};
--- 750,756 ----
  }
  
  sub create_dotsa_dir_if_needed {
!   my ($self,$userdir,$user) = @_;
  
    # user state directory
    my $fname = $self->{userstate_dir};
***************
*** 768,773 ****
--- 768,780 ----
      if (!-d $fname) {
        # not being able to create the *dir* is not worth a warning at all times
        mkpath ($fname, 0, 0700) or dbg ("mkdir $fname failed: $!\n");
+ 
+       if ( $< == 0 && $> == 0 && defined $user) {
+ 			# chown it
+ 			my ($uid,$gid) = (getpwnam($user))[2,3];
+ 			unless (chown $uid, $gid, $fname) {
+ 	   		warn "Couldn't chown $fname to $uid:$gid for $user: $!\n"; }
+ 		};
      }
    }
  }
***************
*** 791,797 ****
      # Pass on the value of $userdir for virtual users in vpopmail
      # otherwise it is empty and the user's normal homedir is used
      #
!     $self->create_dotsa_dir_if_needed($userdir);
  
      # copy in the default one for later editing
      my $defprefs = $self->first_existing_path
--- 798,804 ----
      # Pass on the value of $userdir for virtual users in vpopmail
      # otherwise it is empty and the user's normal homedir is used
      #
!     $self->create_dotsa_dir_if_needed($userdir, $user);
  
      # copy in the default one for later editing
      my $defprefs = $self->first_existing_path
