--- /root/unstable/mailscanner/mailscanner/bin/MailScanner/Message.pm	Sun Nov 24 12:06:15 2002
+++ Message.pm	Wed Dec  4 16:29:14 2002
@@ -1725,7 +1725,7 @@
 
   my($from,$to,$subject,$date,$allreports,$alltypes,$report,$type);
   my($entityreports, @everyreport, $entitytypes, @everytype);
-  my($emailmsg, $line, $messagefh, $filename, $localpostmaster, $id);
+  my($emailmsg, $line, $messagefh, $msgname, $localpostmaster, $id);
 
   $from = $this->{from};
 
@@ -1761,19 +1761,36 @@
   # Set the report filename dependent on what triggered MailScanner, be it
   # a virus, a filename trap, a Denial Of Service attack, or an parsing error.
   if ($type =~ /v/i) {
-    $filename = MailScanner::Config::Value('sendervirusreport', $this);
+    $msgname = MailScanner::Config::Value('sendervirusreport', $this);
   } elsif ($type =~ /f/i) {
-    $filename = MailScanner::Config::Value('senderfilenamereport', $this);
+    $msgname = MailScanner::Config::Value('senderfilenamereport', $this);
   } elsif ($type =~ /e/i) {
-    $filename = MailScanner::Config::Value('sendererrorreport', $this);
+    $msgname = MailScanner::Config::Value('sendererrorreport', $this);
   } else {
-    $filename = MailScanner::Config::Value('sendervirusreport', $this);
+    $msgname = MailScanner::Config::Value('sendervirusreport', $this);
+  }
+
+  # Work out the list of all the infected attachments, including
+  # reports applying to the whole message
+  my($attach, $text, %infected, $filename);
+  while (($attach, $text) = each %$allreports) {
+    if ($attach eq "") {
+      $infected{MailScanner::Config::LanguageValue($this, "theentiremessage")}
+        = 1;
+    } else {
+      $infected{"$attach"} = 1;
+    }
   }
+  # And don't forget the external bodies which are just entity reports
+  while (($attach, $text) = each %$entityreports) {
+    $infected{MailScanner::Config::LanguageValue($this, 'notnamed')} = 1;
+  }
+  $filename = join(', ', keys %infected);
 
   $messagefh = new FileHandle;
-  $messagefh->open($filename)
+  $messagefh->open($msgname)
     or MailScanner::Log::WarnLog("Cannot open message file %s, %s",
-                                 $filename, $!);
+                                 $msgname, $!);
   $emailmsg = "";
   while(<$messagefh>) {
     chomp;