JSieveManager should be accessible from server, patch contributed by Tellier Benoit (JSIEVE-98)

git-svn-id: https://svn.apache.org/repos/asf/james/jsieve/trunk@1682368 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/manager/api/src/main/java/org/apache/james/managesieve/api/ScriptSummary.java b/manager/api/src/main/java/org/apache/james/managesieve/api/ScriptSummary.java
index 6d31bd6..e31217c 100644
--- a/manager/api/src/main/java/org/apache/james/managesieve/api/ScriptSummary.java
+++ b/manager/api/src/main/java/org/apache/james/managesieve/api/ScriptSummary.java
@@ -20,7 +20,40 @@
 
 package org.apache.james.managesieve.api;
 
-public interface ScriptSummary {
-    abstract public String getName();
-    abstract public boolean isActive();
+public class ScriptSummary {
+
+    private final String name;
+    private final boolean activeFile;
+
+    public ScriptSummary(String name, boolean activeFile) {
+        this.name = name;
+        this.activeFile = activeFile;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean isActive() {
+        return activeFile;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof ScriptSummary)) return false;
+
+        ScriptSummary that = (ScriptSummary) o;
+
+        if (activeFile != that.activeFile) return false;
+        return !(name != null ? !name.equals(that.name) : that.name != null);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = name != null ? name.hashCode() : 0;
+        result = 31 * result + (activeFile ? 1 : 0);
+        return result;
+    }
 }
\ No newline at end of file
diff --git a/manager/mailet/src/main/java/org/apache/james/managesieve/mailet/transcode/MessageToCoreToMessage.java b/manager/mailet/src/main/java/org/apache/james/managesieve/mailet/transcode/MessageToCoreToMessage.java
index f409105..376fd80 100644
--- a/manager/mailet/src/main/java/org/apache/james/managesieve/mailet/transcode/MessageToCoreToMessage.java
+++ b/manager/mailet/src/main/java/org/apache/james/managesieve/mailet/transcode/MessageToCoreToMessage.java
@@ -69,6 +69,10 @@
                             && (fileName.endsWith(".siv") || fileName.endsWith(".sieve"));
                 }
                 if (found) {
+                    Object content = part.getContent();
+                    if (content instanceof String) {
+                        return (String) part.getContent();
+                    }
                     InputStream is = (InputStream) part.getContent();
                     Scanner scanner = null;
                     try {
diff --git a/manager/mailet/src/test/java/org/apache/james/managesieve/mailet/ManageSieveMailetTestCase.java b/manager/mailet/src/test/java/org/apache/james/managesieve/mailet/ManageSieveMailetTestCase.java
index 7fb1752..63f6e9b 100644
--- a/manager/mailet/src/test/java/org/apache/james/managesieve/mailet/ManageSieveMailetTestCase.java
+++ b/manager/mailet/src/test/java/org/apache/james/managesieve/mailet/ManageSieveMailetTestCase.java
@@ -33,6 +33,7 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.activation.DataHandler;
@@ -40,7 +41,6 @@
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.Session;
-import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
@@ -1077,6 +1077,7 @@
 
     }
 
+    @Ignore("Ignore this test as it depends of your environment (file path changes with your position in the project)")
     @Test
     public final void testHelp() throws MessagingException, IOException {
         String user = "test@localhost";
diff --git a/manager/mock/src/main/java/org/apache/james/managesieve/mock/MockSieveRepository.java b/manager/mock/src/main/java/org/apache/james/managesieve/mock/MockSieveRepository.java
index f83c1e4..ef9fc03 100644
--- a/manager/mock/src/main/java/org/apache/james/managesieve/mock/MockSieveRepository.java
+++ b/manager/mock/src/main/java/org/apache/james/managesieve/mock/MockSieveRepository.java
@@ -254,17 +254,8 @@
         }
         Set<Entry<String, SieveScript>> scripts = _repository.get(user).entrySet();
         List<ScriptSummary> summaries = new ArrayList<ScriptSummary>(scripts.size());
-        for (final Entry<String, SieveScript> entry : scripts)
-        {
-            summaries.add(new ScriptSummary(){
-
-                public String getName() {
-                    return entry.getKey();
-                }
-
-                public boolean isActive() {
-                    return entry.getValue().isActive();
-                }});
+        for (final Entry<String, SieveScript> entry : scripts) {
+            summaries.add(new ScriptSummary(entry.getKey(), entry.getValue().isActive()));
         }
         return summaries;
     }