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/01/04 23:42:10 UTC

svn commit: r1722974 - in /james/project/trunk/server: data/data-memory/src/main/java/org/apache/james/user/memory/ mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ mailet/mailets/src/test/resources/org/apache/james/transport/m...

Author: btellier
Date: Mon Jan  4 22:42:10 2016
New Revision: 1722974

URL: http://svn.apache.org/viewvc?rev=1722974&view=rev
Log:
JSIEVE-73 Integration tests for SIEVE body extension ( RFC-5173 )

Added:
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentInvalid.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentMatch.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawInvalid.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawMatch.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextInvalid.script
    james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextMatch.script
Modified:
    james/project/trunk/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
    james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveMailetTest.java

Modified: james/project/trunk/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java?rev=1722974&r1=1722973&r2=1722974&view=diff
==============================================================================
--- james/project/trunk/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java (original)
+++ james/project/trunk/server/data/data-memory/src/main/java/org/apache/james/user/memory/MemoryUsersRepository.java Mon Jan  4 22:42:10 2016
@@ -86,7 +86,6 @@ public class MemoryUsersRepository exten
         return Optional.fromNullable(userByName.get(name))
             .transform(new Function<User, Boolean>() {
                 public Boolean apply(User user) {
-                    System.out.println(user);
                     return user.verifyPassword(password);
                 }
             }).or(false);

Modified: james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveMailetTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveMailetTest.java?rev=1722974&r1=1722973&r2=1722974&view=diff
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveMailetTest.java (original)
+++ james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/SieveMailetTest.java Mon Jan  4 22:42:10 2016
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets.delivery;
 
 import com.google.common.collect.Lists;
+import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -704,7 +705,75 @@ public class SieveMailetTest {
         verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
     }
 
-    // TODO Body extension....
+    @Test
+    public void bodyRawShouldNotMatchNotContainedData() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyRawInvalid.script");
+        final MessageManager messageManager = prepareMessageManagerOn(NOT_SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyRawShouldMatchContent() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyRawMatch.script");
+        final MessageManager messageManager = prepareMessageManagerOn(SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyContentShouldMatchContent() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyContentMatch.script");
+        final MessageManager messageManager = prepareMessageManagerOn(SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyContentShouldNotMatchNotContainedData() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyContentInvalid.script");
+        final MessageManager messageManager = prepareMessageManagerOn(NOT_SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyContentShouldNotMatchWhenWrongContentType() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script");
+        final MessageManager messageManager = prepareMessageManagerOn(NOT_SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyTextShouldNotMatchNotContainedData() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyTextInvalid.script");
+        final MessageManager messageManager = prepareMessageManagerOn(NOT_SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
+
+    @Test
+    public void bodyTextShouldMatchContent() throws Exception {
+        prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyTextMatch.script");
+        final MessageManager messageManager = prepareMessageManagerOn(SELECTED_MAILBOX);
+
+        sieveMailet.service(createMail());
+
+        verify(messageManager).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+    }
 
     private void prepareTestUsingScript(final String script) throws Exception {
         when(usersRepository.supportVirtualHosting()).thenReturn(false);
@@ -740,10 +809,10 @@ public class SieveMailetTest {
             new DataHandler(
                 new ByteArrayDataSource(
                     "A text to match",
-                    "application/sieve; charset=UTF-8")
+                    "text/plain; charset=UTF-8")
             ));
         scriptPart.setDisposition(MimeBodyPart.ATTACHMENT);
-        scriptPart.setHeader("Content-Type", "application/sieve; charset=UTF-8");
+        scriptPart.setHeader("Content-Type", "text/plain; charset=UTF-8");
         scriptPart.setFileName("file.txt");
         multipart.addBodyPart(scriptPart);
         message.setContent(multipart);

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentInvalid.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentInvalid.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentInvalid.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentInvalid.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :content "text/plain" :contains "invalid" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentMatch.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentMatch.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentMatch.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentMatch.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :content "text/plain" :contains "to match" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyContentWrongContentType.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :content "any" :contains "invalid" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawInvalid.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawInvalid.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawInvalid.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawInvalid.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :raw :contains "invalid" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawMatch.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawMatch.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawMatch.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyRawMatch.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :raw :contains "; charset=UTF-8" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextInvalid.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextInvalid.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextInvalid.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextInvalid.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :text :contains "unicorns will get to the power" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file

Added: james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextMatch.script
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextMatch.script?rev=1722974&view=auto
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextMatch.script (added)
+++ james/project/trunk/server/mailet/mailets/src/test/resources/org/apache/james/transport/mailets/delivery/bodyTextMatch.script Mon Jan  4 22:42:10 2016
@@ -0,0 +1,27 @@
+################################################################
+# 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.                                           #
+################################################################
+
+require "fileinto";
+require "body";
+
+if body :text :contains "to match" {
+    fileinto "INBOX.select";
+} else {
+    fileinto "INBOX.not.selected";
+}
\ No newline at end of file



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