vincenzo 2003/06/20 04:55:47
Modified: src/java/org/apache/james/transport/matchers
AttachmentFileNameIs.java
Log:
An overall catch now rethrows a MessagingException, consistently with the new
"onException" control.
Revision Changes Path
1.4 +39 -29
jakarta-james/src/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java
Index: AttachmentFileNameIs.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AttachmentFileNameIs.java 6 Jun 2003 23:49:37 -0000 1.3
+++ AttachmentFileNameIs.java 20 Jun 2003 11:55:47 -0000 1.4
@@ -79,6 +79,8 @@
* <P>File name masks may start with a wildcard '*'.</P>
* <P>Multiple file name masks can be specified, e.g.: '*.scr,*.bat'.</P>
*
+ * @version CVS $Revision$ $Date$
+ * @since 2.2.0
*/
public class AttachmentFileNameIs extends GenericMatcher {
/**
@@ -118,45 +120,53 @@
masks = (Mask[])theMasks.toArray(new Mask[0]);
}
- /**
- * either every recipient is matching or neither of them
+ /**
+ * Either every recipient is matching or neither of them.
+ * @throws MessagingException if no matching attachment is found and at least
one exception was thrown
*/
public Collection match(Mail mail) throws MessagingException {
- 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;
- }
+ Exception anException = null;
try {
- content = message.getContent();
- } catch (java.io.IOException e) {
- throw new MessagingException(
- "Attachment file names cannot be determined", e);
- }
- 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 && matchFound(fileName)) {
- return mail.getRecipients(); // matching file found
- }
- } catch (Exception ex) {} // ignore any exception and process next
bodypart
+ 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;
}
- } else {
- try {
+
+ 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 && matchFound(fileName)) {
+ return mail.getRecipients(); // matching file found
+ }
+ } catch (MessagingException e) {
+ anException = e;
+ } // ignore any messaging exception and process next bodypart
+ }
+ } else {
String fileName = message.getFileName();
if (fileName != null && matchFound(fileName)) {
return mail.getRecipients(); // matching file found
}
- } catch (Exception ex) {} // ignore any exception
+ }
+ } catch (Exception e) {
+ anException = e;
+ }
+
+ // if no matching attachment was found and at least one exception was
catched rethrow it up
+ if (anException != null) {
+ throw new MessagingException("Malformed message", anException);
}
return null; // no matching attachment found
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]