--- Message.pm.4.31.6.orig	Tue Jul 27 12:52:35 2004
+++ Message.pm	Tue Jul 27 12:48:55 2004
@@ -878,10 +878,12 @@
 
   # Add the spam stars if they want that. Limit it to 60 characters to avoid
   # a potential denial-of-service attack.
-  my($stars,$starcount,$scoretext,$minstars);
+  my($stars,$starcount,$scoretext,$minstars,$scorefmt);
   $starcount = int($this->{sascore}) + 0;
   $starcount = 0 if $this->{spamwhitelisted}; # 0 stars if white-listed
-  $scoretext = $starcount;
+  $scorefmt = MailScanner::Config::Value('scoreformat', $this);
+  $scorefmt = '%d' if $scorefmt eq '';
+  $scoretext = sprintf($scorefmt, $this->{sascore}+0);
   $minstars = MailScanner::Config::Value('minstars', $this);
   $starcount = $minstars if $this->{isrblspam} && $minstars &&
                             $starcount<$minstars;
@@ -1365,6 +1367,7 @@
   my($zip, @members, $member, $name, $fh, $safename);
 
   #print STDERR "Unpacking $zipname\n";
+  return 1 if -s "$explodeinto/$zipname" == 4_237_4; # zip of death?
   return 1 unless $zip = Archive::Zip->new("$explodeinto/$zipname");
   return 1 unless @members = $zip->members();
 
@@ -1380,7 +1383,7 @@
     next if $onlycheckencryption;
 
     $name = $member->fileName();
-    $safename = $this->MakeNameSafe($name);
+    $safename = $this->MakeNameSafe($name, $explodeinto);
     $this->{file2parent}{$name} = $zipname;
     $this->{file2parent}{$safename} = $zipname;
     $this->{file2safefile}{$name} = $safename;
@@ -1397,7 +1400,7 @@
     unless ($zip->extractMemberWithoutPaths($member, $safename) == AZ_OK) {
       # Create a zero-length file if extraction failed
       # so the filename tests will still work.
-    #print STDERR "Done passworded extraction of $member to $safename\n";
+      #print STDERR "Done passworded extraction of $member to $safename\n";
       $fh->open(">$safename") && $fh->close();
     }
     #print STDERR "Done extraction of $member to $safename\n";
@@ -1407,7 +1410,7 @@
 
 # Is this filename evil?
 sub IsNameEvil {
-  my($this, $name) = @_;
+  my($this, $name, $dir) = @_;
 
   #print STDERR "Testing \"$name\" to see if it is evil\n";
   return 1 if (!defined($name) or ($name eq ''));   ### empty
@@ -1415,6 +1418,7 @@
   return 1 if ($name =~ m{^\.+\Z});         ### dots
   return 1 if ($name =~ tr{ \%\(\)\+\,\-\.0-9\=A-Z_a-z\{\}\x80-\xFF}{}c);
   return 1 if (length($name) > 50);
+  return 'exists' if (-e "$dir/$name");
 
   #print STDERR "It is okay\n";
   #$self->debug("it's ok");
@@ -1423,12 +1427,13 @@
 
 # Make this filename safe and return the safe version
 sub MakeNameSafe {
-  my($self, $fname) = @_;
+  my($self, $fname, $dir) = @_;
 
     ### Isolate to last path element:
     my $last = $fname; $last =~ s{^.*[/\\\[\]:]}{};
-    if ($last and !$self->IsNameEvil($last)) {
+    if ($last and !$self->IsNameEvil($last, $dir)) {
         #$self->debug("looks like I can use the last path element");
+        #print STDERR "MakeNameSafe: 1 $fname,$last\n";
         return $last;
     }
 
@@ -1437,7 +1442,8 @@
     $last =~ s/^\s+//;
     $last =~ s/\s+\Z//;
     $last =~ tr/ \%\(\)\+\,\-\.0-9\=A-Z_a-z\{\}\x80-\xFF//cd;
-    return $last unless $self->IsNameEvil($last);
+    #print STDERR "MakeNameSafe: 2 $fname,$last\n";
+    return $last unless $self->IsNameEvil($last, $dir);
 
     ### Break last element into root and extension, and truncate:
     my ($root, $ext) = (($last =~ /^(.*)\.([^\.]+)\Z/)
@@ -1450,12 +1456,24 @@
     $ext  = substr($ext,  0, ($self->{MPF_TrimExt}  ||  3));
     $ext =~ /^\w+$/ or $ext = "dat";
     my $trunc = $root . ($ext ? ".$ext" : '');
-    if (!$self->IsNameEvil($trunc)) {
+    if (!$self->IsNameEvil($trunc, $dir)) {
         #$self->debug("looks like I can use the truncated last path element");
+        #print STDERR "MakeNameSafe: 3 $fname,$trunc\n";
         return $trunc;
     }
 
+    # It is still evil, but probably just because it exists
+    if ($self->IsNameEvil($trunc, $dir) eq 'exists') {
+      my $counter = 0;
+      $trunc = $trunc . '0';
+      do {
+        $counter++;
+        $trunc = $root . $counter . ($ext ? ".$ext" : '');
+      } while $self->IsNameEvil($trunc, $dir) eq 'exists';
+      return $trunc;
+    }
     ### Hope that works:
+    #print STDERR "MakeNameSafe: 4 $fname,:-(\n";
     undef;
 }
 
@@ -2567,10 +2585,12 @@
 
   # Add the spam stars if they want that. Limit it to 60 characters to avoid
   # a potential denial-of-service attack.
-  my($stars,$starcount,$scoretext,$minstars);
+  my($stars,$starcount,$scoretext,$minstars,$scorefmt);
   $starcount = int($this->{sascore}) + 0;
   $starcount = 0 if $this->{spamwhitelisted}; # 0 stars if white-listed
-  $scoretext = $starcount;
+  $scorefmt = MailScanner::Config::Value('scoreformat', $this);
+  $scorefmt = '%d' if $scorefmt eq '';
+  $scoretext = sprintf($scorefmt, $this->{sascore}+0);
   $minstars = MailScanner::Config::Value('minstars', $this);
   $starcount = $minstars if $this->{isrblspam} && $minstars &&
                             $starcount<$minstars;
@@ -2713,10 +2733,12 @@
 
   # Add the spam stars if they want that. Limit it to 60 characters to avoid
   # a potential denial-of-service attack.
-  my($stars,$starcount,$scoretext,$minstars);
+  my($stars,$starcount,$scoretext,$minstars,$scorefmt);
   $starcount = int($this->{sascore}) + 0;
   $starcount = 0 if $this->{spamwhitelisted}; # 0 stars if white-listed
-  $scoretext = $starcount;
+  $scorefmt = MailScanner::Config::Value('scoreformat', $this);
+  $scorefmt = '%d' if $scorefmt eq '';
+  $scoretext = sprintf($scorefmt, $this->{sascore}+0);
   $minstars = MailScanner::Config::Value('minstars', $this);
   $starcount = $minstars if $this->{isrblspam} && $minstars &&
                             $starcount<$minstars;
@@ -3198,11 +3220,12 @@
                                  "file %s, %s", $textfile, $!);
   $output = "";
   my $line;
+  my $ea = qr/([\(\)\[\]\.\?\*\+\^"'@<>:])/;
   while(<$textfh>) {
     $line = chomp;
     #s#"#\\"#g; # Escape any " characters
     #s#@#\\@#g; # Escape any @ characters
-    $line =~ s/([\(\)\[\]\.\?\*\+\^"'@])/\\$1/g; # Escape any regex characters
+    $line =~ s/$ea/\\$1/g; # Escape any regex characters
     # Untainting joy...
     $line =~ /(.*)/;
     $result = eval "\"$1\"";
@@ -3717,7 +3740,9 @@
     if (exists $attr->{'width'}  && $attr->{'width'}<=2 &&
         exists $attr->{'height'} && $attr->{'height'}<=2) {
       print '<img src="MailScannerWebBug" width="' . $attr->{'width'} .
-            '" height="' . $attr->{'height'} . '" alt="Web Bug" />';
+            '" height="' . $attr->{'height'} . '" alt="';
+      print 'Web Bug from ' . $attr->{'src'} if $attr->{'src'};
+      print '" />';
     } else {
       print $text;
     }
