*** Message.pm  Tue Mar 16 07:09:51 2004
--- Message.pm.new      Tue Mar 16 15:17:49 2004
***************
*** 1123,1131 ****
      #print STDERR "Level = $level\n";
      foreach $part (@parts) {
        next if $part eq '.' || $part eq '..';
        # Skip the entire loop if it's not what we are looking for
!       next unless $part =~ /(^msg.*txt$)|(\.(tar\.g?z|taz|tgz|tz|zip)$)/i;

        $size = -s "$explodeinto/$part";
        #print STDERR "Checking $part $size bytes\n";
        next if $seenbefore{$part} &&
--- 1123,1131 ----
      #print STDERR "Level = $level\n";
      foreach $part (@parts) {
        next if $part eq '.' || $part eq '..';
        # Skip the entire loop if it's not what we are looking for
!       next unless $part =~ /(^msg.*txt$)|(\.(tar\.g?z|taz|tgz|tz|zip|rar)$)/i;

        $size = -s "$explodeinto/$part";
        #print STDERR "Checking $part $size bytes\n";
        next if $seenbefore{$part} &&
***************
*** 1225,1240 ****
        next if !$maxlevels && $allowpasswords;

        $level++;
        next if $level > $maxlevels;
!       next unless $part =~ /\.(tar\.g?z|taz|tgz|tz|zip)$/i;
        $foundnewfiles = 1;

        # Is it a zip file, in which case unpack the zip
        $ziperror = "";
        $ziperror = $this->UnpackZip($part, $explodeinto, $allowpasswords,
                                     $onlycheckencryption);
!       # If unpacking as a zip failed, try it as a tar
        $tarerror = "";
        $tarerror = 0 # $this->UnpackTar($part, $explodeinto, $allowpasswords)
          if $ziperror || $part =~ /(tar\.g?z|tgz)$/i;
        #print STDERR "In inner: \"$part\"\n";
--- 1225,1246 ----
        next if !$maxlevels && $allowpasswords;

        $level++;
        next if $level > $maxlevels;
!       next unless $part =~ /\.(tar\.g?z|taz|tgz|tz|zip|rar)$/i;
        $foundnewfiles = 1;

        # Is it a zip file, in which case unpack the zip
        $ziperror = "";
        $ziperror = $this->UnpackZip($part, $explodeinto, $allowpasswords,
                                     $onlycheckencryption);
!       # If it wasn't a zip try it as a rar with the same conventions
!         if($ziperror or $part =~ /rar/i){
!             $ziperror = $this->UnpackRar($part, $explodeinto, $allowpasswords,
!                                      $onlycheckencryption);
!        }
!
!       # If unpacking as a rar failed, try it as a tar
        $tarerror = "";
        $tarerror = 0 # $this->UnpackTar($part, $explodeinto, $allowpasswords)
          if $ziperror || $part =~ /(tar\.g?z|tgz)$/i;
        #print STDERR "In inner: \"$part\"\n";
***************
*** 1315,1322 ****
--- 1321,1387 ----
    }
    return 0;
  }

+ # Unpack a rar file into the named directory.
+ # Return 1 if an error occurred, else 0.
+ # Return 0 on success.
+ # Return "password" if a member was password-protected.
+ sub UnpackRar {
+   my($this, $zipname, $explodeinto, $allowpasswords, $onlycheckencryption) = @_;
+
+   my($zip, @members, $member, $name, $fh, $safename, $memb, $check, $junk);
+
+ #  print STDERR "Unpacking $zipname\n";
+   $junk = `unrar`;
+   return 1 unless "$?" == "0";
+
+   $memb = `unrar lb $explodeinto/$zipname 2>&1`;
+   return 1 unless "$?" == "0";
+
+   @members = split /\n/, $memb;
+   $fh = new FileHandle;
+
+   foreach $member (@members) {
+ #    print STDERR "Checking member " . $member . "\n";
+       $check = `unrar  t -p-  $explodeinto/$zipname $member 2>&1`;
+       if ($check =~ /Encrypted/i){
+ #             print STDERR "Password Protected RAR Found\n";
+               return "password";
+       }
+
+
+     # If they don't want to extract, but only check for encryption,
+     # then skip the rest of this as we don't actually want the files.
+     next if $onlycheckencryption;
+
+     $name = $member;
+     $safename = $this->MakeNameSafe($name);
+     $this->{file2parent}{$name} = $zipname;
+     $this->{file2parent}{$safename} = $zipname;
+     $this->{file2safefile}{$name} = $safename;
+     $this->{safefile2file}{$safename} = $name;
+ #    print STDERR "Archive member \"$name\" is now \"$safename\"\n";
+
+     #$this->{file2entity}{$name} = $this->{entity};
+     $this->{file2safefile}{$name} = $zipname;
+     #$this->{safefile2file}{$safename} = $zipname;
+
+     $safename = "$explodeinto/$safename";
+
+ #   print STDERR "About to extract $member to $safename\n";
+       system("unrar e -p- $safename 2>&1");
+     unless ("$?" == 0) {
+       # Create a zero-length file if extraction failed
+       # so the filename tests will still work.
+       $fh->open(">$safename") && $fh->close();
+     }
+   }
+   return 0;
+ }
+
+
+
  # Is this filename evil?
  sub IsNameEvil {
    my($this, $name) = @_;

