james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1722972 - in /james/jsieve/trunk: mailet/pom.xml mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java pom.xml
Date Mon, 04 Jan 2016 22:40:10 GMT
Author: btellier
Date: Mon Jan  4 22:40:10 2016
New Revision: 1722972

URL: http://svn.apache.org/viewvc?rev=1722972&view=rev
Log:
JSIEVE-73 Mailet adapter should rely on mime4j/james-utils to match against mail content

Modified:
    james/jsieve/trunk/mailet/pom.xml
    james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
    james/jsieve/trunk/pom.xml

Modified: james/jsieve/trunk/mailet/pom.xml
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/pom.xml?rev=1722972&r1=1722971&r2=1722972&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/pom.xml (original)
+++ james/jsieve/trunk/mailet/pom.xml Mon Jan  4 22:40:10 2016
@@ -71,11 +71,19 @@
             <groupId>org.apache.james</groupId>
             <artifactId>apache-mime4j-dom</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>apache-mime4j-james-utils</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>junit</groupId>

Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java?rev=1722972&r1=1722971&r2=1722972&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
(original)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailAdapter.java
Mon Jan  4 22:40:10 2016
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.jsieve.mailet;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.james.mime4j.dom.address.AddressList;
@@ -25,6 +27,7 @@ import org.apache.james.mime4j.dom.addre
 import org.apache.james.mime4j.dom.address.MailboxList;
 import org.apache.james.mime4j.dom.field.ParseException;
 import org.apache.james.mime4j.field.address.DefaultAddressParser;
+import org.apache.james.mime4j.utils.search.MessageMatcher;
 import org.apache.jsieve.SieveContext;
 import org.apache.jsieve.exception.InternetAddressException;
 import org.apache.jsieve.exception.SieveException;
@@ -41,7 +44,6 @@ import org.apache.mailet.MailetContext;
 import javax.mail.Header;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -80,8 +82,6 @@ public class SieveMailAdapter implements
     
     private final Poster poster;
 
-    private String contentText;
-    
     /**
      * Constructor for SieveMailAdapter.
      * 
@@ -340,7 +340,6 @@ public class SieveMailAdapter implements
     protected void setMail(Mail mail)
     {
         fieldMail = mail;
-        contentText = null;
     }
     
     /**
@@ -431,30 +430,55 @@ public class SieveMailAdapter implements
         getMailetContext().sendMail(sender, recipients, mail);
     }
 
-
-    public boolean isInBodyText(String phraseCaseInsensitive) throws SieveMailException {
+    public boolean isInBodyText(List<String> phrasesCaseInsensitive) throws SieveMailException
{
         try {
-            if (contentText == null) {
-                contentText = getMessage().getContent().toString().toLowerCase();
-            }
-            return contentText.contains(phraseCaseInsensitive);
-        } catch (MessagingException e) {
-            throw new SieveMailException(e);
-        } catch (IOException e) {
-            throw new SieveMailException(e);
+            return MessageMatcher.builder()
+                .contentTypes(Lists.newArrayList("text/plain"))
+                .includeHeaders(false)
+                .caseInsensitive(false)
+                .searchContents(Lists.transform(phrasesCaseInsensitive, new Function<String,
CharSequence>() {
+                    public CharSequence apply(String s) {
+                        return s;
+                    }
+                })).build()
+                .messageMatches(getMail().getMessage().getInputStream());
+        } catch (Exception e) {
+            throw new SieveMailException("Error searching in the mail content", e);
         }
     }
 
-    public boolean isInBodyText(List<String> phrasesCaseInsensitive) throws SieveMailException
{
-        throw new SieveMailException("Not yet implemented");
-    }
-
     public boolean isInBodyRaw(List<String> phrasesCaseInsensitive) throws SieveMailException
{
-        throw new SieveMailException("Not yet implemented");
+        try {
+            return MessageMatcher.builder()
+                .includeHeaders(false)
+                .caseInsensitive(false)
+                .ignoringMime(true)
+                .searchContents(Lists.transform(phrasesCaseInsensitive, new Function<String,
CharSequence>() {
+                    public CharSequence apply(String s) {
+                        return s;
+                    }
+                })).build()
+                .messageMatches(getMail().getMessage().getInputStream());
+        } catch (Exception e) {
+            throw new SieveMailException("Error searching in the mail content", e);
+        }
     }
 
     public boolean isInBodyContent(List<String> contentTypes, List<String> phrasesCaseInsensitive)
throws SieveMailException {
-        throw new SieveMailException("Not yet implemented");
+        try {
+            return MessageMatcher.builder()
+                .contentTypes(contentTypes)
+                .includeHeaders(false)
+                .caseInsensitive(false)
+                .searchContents(Lists.transform(phrasesCaseInsensitive, new Function<String,
CharSequence>() {
+                    public CharSequence apply(String s) {
+                        return s;
+                    }
+                })).build()
+                .messageMatches(getMail().getMessage().getInputStream());
+        } catch (Exception e) {
+            throw new SieveMailException("Error searching in the mail content", e);
+        }
     }
 
     public void setContext(SieveContext context) {}

Modified: james/jsieve/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/pom.xml?rev=1722972&r1=1722971&r2=1722972&view=diff
==============================================================================
--- james/jsieve/trunk/pom.xml (original)
+++ james/jsieve/trunk/pom.xml Mon Jan  4 22:40:10 2016
@@ -89,6 +89,7 @@
         <commons-io.version>2.1</commons-io.version>
         <mockito-core.version>1.9.0</mockito-core.version>
         <assertj.version>1.7.1</assertj.version>
+        <guava.version>16.0</guava.version>
     </properties>
 
     <dependencyManagement>
@@ -150,6 +151,16 @@
                 <version>${mime4j.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.james</groupId>
+                <artifactId>apache-mime4j-james-utils</artifactId>
+                <version>${mime4j.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.google.guava</groupId>
+                <artifactId>guava</artifactId>
+                <version>${guava.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>commons-logging</groupId>
                 <artifactId>commons-logging</artifactId>
                 <version>1.1.1</version>



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


Mime
View raw message