Index: src/java/org/apache/james/transport/matchers/HasAttachment.java
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/java/org/apache/james/transport/matchers/HasAttachment.java,v
retrieving revision 1.2.4.2
diff -u -r1.2.4.2 HasAttachment.java
--- src/java/org/apache/james/transport/matchers/HasAttachment.java	8 Mar 2003 21:54:09 -0000	1.2.4.2
+++ src/java/org/apache/james/transport/matchers/HasAttachment.java	8 Jun 2003 23:10:01 -0000
@@ -62,24 +62,54 @@
 import org.apache.mailet.Mail;
 
 import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Part;
 import javax.mail.internet.MimeMessage;
 import java.util.Collection;
 
 /**
  * Checks whether this message has an attachment
  *
- * @author  Serge Knystautas <sergek@lokitech.com>
+ * <P>CVS $Id$</P>
+ * @version 2.2.0
  */
 public class HasAttachment extends GenericMatcher {
 
     public Collection match(Mail mail) throws MessagingException {
-        MimeMessage message = mail.getMessage();
-
-        if (message.getContentType() != null &&
-                message.getContentType().startsWith("multipart/mixed")) {
-            return mail.getRecipients();
-        } else {
-            return null;
+        try {
+            MimeMessage message = mail.getMessage();
+            Object content;
+            
+            /**
+             * if there is an attachment and no inline text,
+             * the content type can be anything
+             */
+            if (message.getContentType() == null) {
+                return null;
+            }
+            
+            content = message.getContent();
+            if (content instanceof Multipart) {
+                Multipart multipart = (Multipart) content;
+                for (int i = 0; i < multipart.getCount(); i++) {
+                    try {
+                        Part part = multipart.getBodyPart(i);
+                        String fileName = part.getFileName();
+                        if (fileName != null) {
+                            return mail.getRecipients(); // file found
+                        }
+                    } catch (Throwable th) {} // ignore any Throwable and process next bodypart
+                }
+            } else {
+                String fileName = message.getFileName();
+                if (fileName != null) {
+                    return mail.getRecipients(); // file found
+                }
+            }
+        } catch (Throwable th) {
+            log("Exception caught: malformed message - will not match", th);
         }
+        
+        return null; // no attachment found
     }
 }
