You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2016/08/29 12:29:53 UTC

[1/3] james-project git commit: MAILET-107 Regarding RFC-2183 content disposition should be used for attachment detection

Repository: james-project
Updated Branches:
  refs/heads/master 18bca9849 -> 37761372f


MAILET-107 Regarding RFC-2183 content disposition should be used for attachment detection

Especially one can use inlined files that are not considered as attachments, as they should be displayed in the message body by the MUA


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/829dfc69
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/829dfc69
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/829dfc69

Branch: refs/heads/master
Commit: 829dfc697ca47cb55d21d868873679c18a5aed8d
Parents: 18bca98
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 17 15:03:57 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Aug 29 19:28:59 2016 +0700

----------------------------------------------------------------------
 .../apache/james/transport/matchers/HasAttachment.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/829dfc69/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasAttachment.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasAttachment.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasAttachment.java
index a7b842b..a998039 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasAttachment.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/HasAttachment.java
@@ -31,6 +31,8 @@ import javax.mail.Part;
 import javax.mail.internet.MimeMessage;
 import java.util.Collection;
 
+import com.google.common.base.Objects;
+
 /**
  * Checks whether this message has an attachment
  *
@@ -64,8 +66,7 @@ public class HasAttachment extends GenericMatcher {
                 for (int i = 0; i < multipart.getCount(); i++) {
                     try {
                         Part part = multipart.getBodyPart(i);
-                        String fileName = part.getFileName();
-                        if (fileName != null) {
+                        if (isAttachment(part)) {
                             return mail.getRecipients(); // file found
                         }
                     } catch (MessagingException e) {
@@ -73,8 +74,7 @@ public class HasAttachment extends GenericMatcher {
                     } // ignore any messaging exception and process next bodypart
                 }
             } else {
-                String fileName = message.getFileName();
-                if (fileName != null) {
+                if (isAttachment(message)) {
                     return mail.getRecipients(); // file found
                 }
             }
@@ -89,4 +89,8 @@ public class HasAttachment extends GenericMatcher {
         
         return null; // no attachment found
     }
+
+    private boolean isAttachment(Part part) throws MessagingException {
+        return Objects.equal(part.getDisposition(), MimeMessage.ATTACHMENT);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[2/3] james-project git commit: MAILET-107 Provide tests for HasAttachment matcher

Posted by bt...@apache.org.
MAILET-107 Provide tests for HasAttachment matcher


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/16829c1e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/16829c1e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/16829c1e

Branch: refs/heads/master
Commit: 16829c1e3ee94f1c89c32d1e6cb793afff1e472c
Parents: 829dfc6
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 17 15:06:09 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Aug 29 19:29:08 2016 +0700

----------------------------------------------------------------------
 .../transport/matchers/HasAttachmentTest.java   | 108 +++++++++++++++++++
 1 file changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/16829c1e/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java
new file mode 100644
index 0000000..0d47689
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/HasAttachmentTest.java
@@ -0,0 +1,108 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class HasAttachmentTest {
+
+    private HasAttachment testee;
+    private MimeMessage mimeMessage;
+    private Mail mail;
+
+    @Before
+    public void setUp() throws Exception {
+        testee = new HasAttachment();
+
+        mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        mail = new FakeMail();
+        mail.setRecipients(ImmutableList.of(new MailAddress("me@james.apache.org")));
+        mail.setMessage(mimeMessage);
+    }
+
+    @Test
+    public void textMailsShouldNotBeMatched() throws Exception {
+        mimeMessage.setText("A simple text message");
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void emptyMultipartShouldNotBeMatched() throws Exception {
+        mimeMessage.setContent(new MimeMultipart());
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void inlinedOnlyMultipartShouldNotBeMatched() throws Exception {
+        MimeMultipart mimeMultipart = new MimeMultipart();
+        MimeBodyPart part = new MimeBodyPart();
+        part.setDisposition(MimeMessage.INLINE);
+        part.setFileName("bahamas.png");
+        mimeMultipart.addBodyPart(part);
+        mimeMessage.setContent(mimeMultipart);
+
+        assertThat(testee.match(mail)).isNull();
+    }
+
+    @Test
+    public void multipartWithOneAttachmentShouldBeMatched() throws Exception {
+        MimeMultipart mimeMultipart = new MimeMultipart();
+        MimeBodyPart textPart = new MimeBodyPart();
+        textPart.setDisposition(MimeMessage.INLINE);
+        mimeMultipart.addBodyPart(textPart);
+        MimeBodyPart attachmentPart = new MimeBodyPart();
+        attachmentPart.setDisposition(MimeMessage.ATTACHMENT);
+        mimeMultipart.addBodyPart(attachmentPart);
+        mimeMessage.setContent(mimeMultipart);
+
+        assertThat(testee.match(mail)).containsAll(mail.getRecipients());
+    }
+
+    @Test
+    public void attachmentMailsShouldBeMatched() throws Exception {
+        MimeMessage mimeMessage = mock(MimeMessage.class);
+        when(mimeMessage.getContent()).thenReturn(new Object());
+        when(mimeMessage.getDisposition()).thenReturn(MimeMessage.ATTACHMENT);
+        when(mimeMessage.getContentType()).thenReturn("application/json");
+        mail.setMessage(mimeMessage);
+
+        assertThat(testee.match(mail)).containsAll(mail.getRecipients());
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


[3/3] james-project git commit: MAILET-107 Correct documentation for HasAttachment

Posted by bt...@apache.org.
MAILET-107 Correct documentation for HasAttachment


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/37761372
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/37761372
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/37761372

Branch: refs/heads/master
Commit: 37761372f1f91e79622820ed3e810d9bdb033b55
Parents: 16829c1
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Aug 17 15:11:00 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Aug 29 19:29:17 2016 +0700

----------------------------------------------------------------------
 server/src/site/xdoc/dev-provided-matchers.xml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/37761372/server/src/site/xdoc/dev-provided-matchers.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/dev-provided-matchers.xml b/server/src/site/xdoc/dev-provided-matchers.xml
index cd18a91..6818062 100644
--- a/server/src/site/xdoc/dev-provided-matchers.xml
+++ b/server/src/site/xdoc/dev-provided-matchers.xml
@@ -102,7 +102,8 @@
             </subsection>
 
             <subsection name="HasAttachment">
-                <p>Description: Matches those messages with a MIME type of "multipart/mixed".  All recipients are returned.</p>
+                <p>Description: Matches those messages with at list a body part with an attachment. Content disposition
+                    is used to detect attachment, as specified by RFC-2183. All recipients are returned.</p>
                 <p>Configuration string: None.</p>
             </subsection>
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org