--- OldMailAudit.pm	Sun Feb  3 15:55:50 2002
+++ NoMailAudit.pm	Sun Feb  3 16:28:12 2002
@@ -19,7 +19,7 @@
 use Fcntl qw(:DEFAULT :flock);
 
 @Mail::SpamAssassin::NoMailAudit::ISA = (
-  	'Mail::SpamAssassin::Message'
+        'Mail::SpamAssassin::Message'
 );
 
 # ---------------------------------------------------------------------------
@@ -89,16 +89,16 @@
 
     if (/^\s/) {
       if (defined $prevhdr) {
-	$hdr = $prevhdr; $val = $_;
-	$entry = $self->{headers}->{$hdr};
-	$entry->{$entry->{count} - 1} .= $val;
-	next;
+        $hdr = $prevhdr; $val = $_;
+        $entry = $self->{headers}->{$hdr};
+        $entry->{$entry->{count} - 1} .= $val;
+        next;
 
       } else {
-	$hdr = "X-Mail-Format-Warning";
-	$val = "No previous line for continuation: $_";
-	$entry = $self->_get_or_create_header_object ($hdr);
-	$entry->{added} = 1;
+        $hdr = "X-Mail-Format-Warning";
+        $val = "No previous line for continuation: $_";
+        $entry = $self->_get_or_create_header_object ($hdr);
+        $entry->{added} = 1;
       }
 
     } elsif (/^From /) {
@@ -125,9 +125,8 @@
 sub _add_header_to_entry {
   my ($self, $entry, $hdr, $line) = @_;
 
-  if ($line !~ /\n$/) {
-    $line .= "\n";	# ensure we have line endings
-  }
+  # ensure we have line endings
+  $line .= "\n" unless $line =~ /\n$/;
 
   $entry->{$entry->{count}} = $line;
   push (@{$self->{header_order}}, $hdr.":".$entry->{count});
@@ -139,9 +138,9 @@
 
   if (!defined $self->{headers}->{$hdr}) {
     $self->{headers}->{$hdr} = {
-	      'count' => 0,
-	      'added' => 0,
-	      'original' => 0
+              'count' => 0,
+              'added' => 0,
+              'original' => 0
     };
   }
   return $self->{headers}->{$hdr};
@@ -252,7 +251,7 @@
 sub as_string {
   my ($self) = @_;
   return join ('', $self->get_all_headers()) . "\n" .
-  		join ('', @{$self->get_body()});
+                join ('', @{$self->get_body()});
 }
 
 # ---------------------------------------------------------------------------
@@ -288,8 +287,18 @@
   my $self = shift;
   my $file = shift;
 
+  # determine location of mailspool
+  if ($ENV{'MAIL'}) {
+    $file = $ENV{'MAIL'};
+  } elsif (-d "/var/spool/mail/") {
+    $file = "/var/spool/mail/" . getpwuid($>);
+  } elsif (-d "/var/mail/") {
+    $file = "/var/mail/" . getpwuid($>);
+  } else {
+    die('Could not determine mailspool location for your system.  Try setting $MAIL in the environment.');
+  }
+
   # some bits of code from Mail::Audit here:
-  $file ||= $ENV{'MAIL'} || "/var/spool/mail/".getpwuid($>);
 
   if (exists $self->{accept}) {
     return $self->{accept}->();
@@ -308,7 +317,7 @@
 
     if (!defined $gotlock) {
       # dot-locking not supported here (probably due to file permissions
-      # on the /var/spool/mail dir).  just use flock().
+      # on the mailspool dir).  just use flock().
       $nodotlocking = 1;
     }
 
@@ -317,7 +326,7 @@
 
     if ($gotlock || $nodotlocking) {
       if (!open (MBOX, ">>$file")) {
-	die "Couldn't open $file: $!";
+        die "Couldn't open $file: $!";
       }
 
       flock(MBOX, LOCK_EX) or warn "failed to lock $file: $!";
@@ -326,7 +335,7 @@
       close MBOX;
 
       if (!$nodotlocking) {
-	$self->dotlock_unlock ();
+        $self->dotlock_unlock ();
       }
 
       if (!$self->{noexit}) { exit 0; }
@@ -434,7 +443,7 @@
 
   if ($@) {
     warn "spamassassin: $method() failed, Mail::Audit ".
-    		"module could not be loaded: $@";
+            "module could not be loaded: $@";
     return undef;
   }
 
