--- Postfix.pm	2003-11-29 11:47:31.000000000 +0000
+++ Postfix.pm.new	2003-12-22 09:56:07.000000000 +0000
@@ -384,9 +384,11 @@
 
     # We are now in the metadata after the message.
     #print STDERR "Reading post data\n";
+    my $FoundEndRecord = 0;
     while(($rectype, $recdata) = ReadRecord($RQf)) {
       if ($rectype eq 'E') {
         push @{$message->{metadata}}, "$rectype$recdata";
+        $FoundEndRecord = 1; # Mark the fact the whole message was there
         last;
       }
       if ($rectype eq 'R') {
@@ -429,6 +431,14 @@
     #print STDERR "Found IP\n"   if $IPFound;
     #print STDERR "Successfully ReadQf!\n" if $FROMFound && $TOFound && $IPFound;
 
+    # If we didn't find the end-of-message E record, then the body hasn't
+    # been fully written, so skip this message
+    unless ($FoundEndRecord) {
+      MailScanner::Log::WarnLog("Batch: Found incomplete queue file for " .
+                                "message %s", $message->{id});
+      return 0;
+    }
+
     # If we didn't find an IP address, then put in 0.0.0.0 so that at least
     # we have something there
     $message->{clientip} = '0.0.0.0' unless $IPFound;