james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1720561 [1/2] - in /james/project/trunk: mailet/base/src/test/java/org/apache/mailet/base/test/ protocols/ protocols/managesieve/ protocols/managesieve/src/main/java/org/apache/james/managesieve/api/ protocols/managesieve/src/main/java/org...
Date Thu, 17 Dec 2015 14:51:18 GMT
Author: btellier
Date: Thu Dec 17 14:51:18 2015
New Revision: 1720561

URL: http://svn.apache.org/viewvc?rev=1720561&view=rev
Log:
PROTOCOLS-68 Clean ManageSieve code

Added:
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/RoleTest.java
Removed:
    james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/mock/
    james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/MockMail.java
    james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/MockMailetConfig.java
    james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/MockMailetContext.java
Modified:
    james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
    james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
    james/project/trunk/protocols/managesieve/pom.xml
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
    james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/util/SettableSession.java
    james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java
    james/project/trunk/protocols/pom.xml
    james/project/trunk/server/data/data-api/src/main/java/org/apache/james/sieverepository/api/SieveRepository.java
    james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveDefaultRepository.java
    james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
    james/project/trunk/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
    james/project/trunk/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailet.java
    james/project/trunk/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailetTestCase.java

Modified: james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java (original)
+++ james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java Thu Dec 17 14:51:18 2015
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.mailet.Mail;
@@ -112,6 +113,13 @@ public class FakeMail implements Mail {
 
     public void setMessage(MimeMessage message) {
         this.msg = message;
+        try {
+            if (message != null && message.getSender() != null) {
+                this.sender = new MailAddress((InternetAddress) message.getSender());
+            }
+        } catch (MessagingException e) {
+            throw new RuntimeException("Exception caught", e);
+        }
     }
 
     public void setState(String state) {

Modified: james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java (original)
+++ james/project/trunk/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java Thu Dec 17 14:51:18 2015
@@ -38,6 +38,7 @@ import java.util.List;
 public class FakeMailContext implements MailetContext {
     
     HashMap<String, Object> attributes = new HashMap<String, Object>();
+    private MimeMessage sentMessage;
 
     public void bounce(Mail mail, String message) throws MessagingException {
         // trivial implementation
@@ -79,7 +80,7 @@ public class FakeMailContext implements
     }
 
     public boolean isLocalServer(String serverName) {
-        return false;  // trivial implementation
+        return serverName.equals("localhost");  // trivial implementation
     }
 
     /**
@@ -112,8 +113,8 @@ public class FakeMailContext implements
         // trivial implementation
     }
 
-    public void sendMail(MimeMessage msg) throws MessagingException {
-        throw new UnsupportedOperationException("MOCKed method");
+    public void sendMail(MimeMessage mimemessage) throws MessagingException {
+        sentMessage = mimemessage;
     }
 
     public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg) throws MessagingException {
@@ -159,4 +160,8 @@ public class FakeMailContext implements
     public List<String> dnsLookup(String name, RecordType type) throws TemporaryLookupException, LookupException {
         return null;   // trivial implementation
     }
+
+    public MimeMessage getSentMessage() {
+        return sentMessage;
+    }
 }

Modified: james/project/trunk/protocols/managesieve/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/pom.xml?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/pom.xml (original)
+++ james/project/trunk/protocols/managesieve/pom.xml Thu Dec 17 14:51:18 2015
@@ -53,6 +53,17 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>${mockito-core.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java (original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/api/Session.java Thu Dec 17 14:51:18 2015
@@ -20,31 +20,10 @@
 
 package org.apache.james.managesieve.api;
 
-/**
- * <code>Session</code>
- */
 public interface Session {
-    
-    public interface UserListener
-    {
-        abstract public void notifyChange(String user);
-    }
-    
-    abstract public String getUser();
-    
-    abstract public void addUserListener(UserListener listener);
-    
-    abstract public void removeUserListener(UserListener listener);
-    
-    public interface AuthenticationListener
-    {
-        abstract public void notifyChange(boolean isAuthenticated);
-    }
-    
-    abstract public boolean isAuthenticated();
-    
-    abstract public void addAuthenticationListener(AuthenticationListener listener);
-    
-    abstract public void removeAuthenticationListener(AuthenticationListener listener);
+
+    boolean isAuthenticated();
+
+    String getUser();
 
 }

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java (original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/core/CoreProcessor.java Thu Dec 17 14:51:18 2015
@@ -20,11 +20,11 @@
 
 package org.apache.james.managesieve.core;
 
+import com.google.common.base.Throwables;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.managesieve.api.AuthenticationRequiredException;
 import org.apache.james.managesieve.api.ManageSieveRuntimeException;
 import org.apache.james.managesieve.api.Session;
-import org.apache.james.managesieve.api.Session.UserListener;
 import org.apache.james.managesieve.api.SieveParser;
 import org.apache.james.managesieve.api.SyntaxException;
 import org.apache.james.managesieve.api.commands.CoreCommands;
@@ -37,160 +37,103 @@ import org.apache.james.sieverepository.
 import org.apache.james.sieverepository.api.exception.SieveRepositoryException;
 import org.apache.james.sieverepository.api.exception.StorageException;
 import org.apache.james.sieverepository.api.exception.UserNotFoundException;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-/**
- * <code>CoreProcessor</code>
- */
 public class CoreProcessor implements CoreCommands {
     
     public static final String IMPLEMENTATION_DESCRIPTION = "Apache ManageSieve v1.0";
     public static final String MANAGE_SIEVE_VERSION = "1.0";
     
-    private SieveRepository _repository = null;
-    private Session _session = null;
-    private SieveParser _parser = null;
-
-    /**
-     * Creates a new instance of CoreProcessor.
-     *
-     */
-    private CoreProcessor() {
-        super();
-    }
-    
-    /**
-     * Creates a new instance of CoreProcessor.
-     *
-     */
-    public CoreProcessor(Session session, SieveRepository repository, SieveParser parser) {
-        this();
-        _session = session;
-        _repository = repository;
-        _parser = parser;
-
-        // Ensure the session user is defined in the repository
-        _session.addUserListener(new UserListener() {
-
-            public void notifyChange(String user) {
-                ensureUser(user);
-            }
-        });
+    private final SieveRepository sieveRepository;
+    private final UsersRepository usersRepository;
+    private final Session session;
+    private final SieveParser parser;
+
+    public CoreProcessor(Session session, SieveRepository repository, UsersRepository usersRepository, SieveParser parser) {
+        this.session = session;
+        this.sieveRepository = repository;
+        this.usersRepository = usersRepository;
+        this.parser = parser;
+        ensureUser();
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.Capability#capability()
-     */
     public Map<Capabilities, String> capability() {
         Map<Capabilities, String> capabilities = new HashMap<Capabilities, String>();
         capabilities.put(Capabilities.IMPLEMENTATION, IMPLEMENTATION_DESCRIPTION);
         capabilities.put(Capabilities.VERSION, MANAGE_SIEVE_VERSION);
         StringBuilder builder = new StringBuilder();
-        for (String extension : _parser.getExtensions())
-        {
+        for (String extension : parser.getExtensions()) {
             builder.append(extension).append(' ');
         }
         String extensions = builder.toString().trim();
-        if (!extensions.isEmpty())
-        {
+        if (!extensions.isEmpty()) {
             capabilities.put(Capabilities.SIEVE, extensions);
         }
-        if (isAuthenticated())
-        {
+        if (isAuthenticated()) {
             capabilities.put(Capabilities.OWNER, getUser());
         }
         capabilities.put(Capabilities.GETACTIVE, null);
         return capabilities;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.CheckScript#checkScript(String)
-     */
-    public List<String> checkScript(String content) throws AuthenticationRequiredException,
-            SyntaxException {
+    public List<String> checkScript(String content) throws AuthenticationRequiredException, SyntaxException {
         authenticationCheck();
-        return _parser.parse(content);
+        return parser.parse(content);
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.DeleteScript#deleteScript(String)
-     */
-    public void deleteScript(String name) throws AuthenticationRequiredException,
-            ScriptNotFoundException, IsActiveException {
+    public void deleteScript(String name) throws AuthenticationRequiredException, ScriptNotFoundException, IsActiveException {
         authenticationCheck();
         try {
-            _repository.deleteScript(getUser(), name);
+            sieveRepository.deleteScript(getUser(), name);
         } catch (StorageException ex) {
             throw new ManageSieveRuntimeException(ex);
         } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         }
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.GetScript#getScript(String)
-     */
-    public String getScript(String name) throws AuthenticationRequiredException,
-        ScriptNotFoundException, StorageException {
+    public String getScript(String name) throws AuthenticationRequiredException, ScriptNotFoundException, StorageException {
         authenticationCheck();
-        String script;
         try {
-            script = IOUtils.toString(_repository.getScript(getUser(), name), "UTF-8");
+            return IOUtils.toString(sieveRepository.getScript(getUser(), name));
         } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         } catch (IOException ex) {
             // Unable to read script InputStream
             throw new ManageSieveRuntimeException(ex);
         }
-        return script;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.HaveSpace#haveSpace(String, long)
-     */
-    public void haveSpace(String name, long size) throws AuthenticationRequiredException,
-            QuotaExceededException {
+    public void haveSpace(String name, long size) throws AuthenticationRequiredException, QuotaExceededException {
         authenticationCheck();
         try {
-            _repository.haveSpace(getUser(), name, size);
+            sieveRepository.haveSpace(getUser(), name, size);
         } catch (SieveRepositoryException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         }
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.ListScripts#listScripts()
-     */
     public List<ScriptSummary> listScripts() throws AuthenticationRequiredException {
         authenticationCheck();
-        List<ScriptSummary> summaries;
         try {
-            summaries = _repository.listScripts(getUser());
+            return sieveRepository.listScripts(getUser());
         } catch (SieveRepositoryException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         }
-        return summaries;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.PutScript#putScript(String, String)
-     */
-    public List<String> putScript(String name, String content)
-            throws AuthenticationRequiredException, SyntaxException, QuotaExceededException {
+    public List<String> putScript(String name, String content) throws AuthenticationRequiredException, SyntaxException, QuotaExceededException {
         authenticationCheck();
-        List<String> warnings = _parser.parse(content);
+        List<String> warnings = parser.parse(content);
         try {
-            _repository.putScript(getUser(), name, content);
+            sieveRepository.putScript(getUser(), name, content);
         } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         } catch (StorageException ex) {
             throw new ManageSieveRuntimeException(ex);
@@ -198,85 +141,61 @@ public class CoreProcessor implements Co
         return warnings;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.RenameScript#renameScript(String, String)
-     */
-    public void renameScript(String oldName, String newName)
-            throws AuthenticationRequiredException, ScriptNotFoundException,
-            DuplicateException {
+    public void renameScript(String oldName, String newName) throws AuthenticationRequiredException, ScriptNotFoundException, DuplicateException {
         authenticationCheck();
         try {
-            _repository.renameScript(getUser(), oldName, newName);
+            sieveRepository.renameScript(getUser(), oldName, newName);
         } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         } catch (StorageException ex) {
             throw new ManageSieveRuntimeException(ex);
         }
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.SetActive#setActive(String)
-     */
-    public void setActive(String name) throws AuthenticationRequiredException,
-            ScriptNotFoundException {
+    public void setActive(String name) throws AuthenticationRequiredException, ScriptNotFoundException {
         authenticationCheck();
         try {
-            _repository.setActive(getUser(), name);
+            sieveRepository.setActive(getUser(), name);
         } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session user is defined in the repository
             throw new ManageSieveRuntimeException(ex);
         } catch (StorageException ex) {
             throw new ManageSieveRuntimeException(ex);
         }
-    }   
-    
-    protected String getUser()
-    {
-        return _session.getUser();
     }
-    
-    protected void ensureUser(String user) {
+
+    public String getActive() throws AuthenticationRequiredException, ScriptNotFoundException, StorageException {
+        authenticationCheck();
         try {
-            if (!_repository.hasUser(user)) {
-                _repository.addUser(user);
-            }
-        } catch (SieveRepositoryException ex) {
+            return IOUtils.toString(sieveRepository.getActive(getUser()));
+        } catch (UserNotFoundException ex) {
             throw new ManageSieveRuntimeException(ex);
+        } catch (IOException e) {
+            throw new ManageSieveRuntimeException(e);
         }
     }
     
-    protected void authenticationCheck() throws AuthenticationRequiredException
-    {
-        if (!isAuthenticated())
-        {
-            throw new AuthenticationRequiredException();
-        }
+    protected String getUser() {
+        return session.getUser();
     }
 
-    protected boolean isAuthenticated()
-    {
-        return _session.isAuthenticated();
+    private void ensureUser() {
+        try {
+            if (usersRepository.contains(session.getUser())) {
+                throw new RuntimeException("User " + session.getUser() + " not found");
+            }
+        } catch (UsersRepositoryException e) {
+            Throwables.propagate(e);
+        }
     }
+    
+    protected void authenticationCheck() throws AuthenticationRequiredException {
+        if (!isAuthenticated()) {
+            throw new AuthenticationRequiredException();
 
-    /**
-     * @see org.apache.james.managesieve.api.commands.GetActive#getActive()
-     */
-    public String getActive() throws AuthenticationRequiredException, ScriptNotFoundException, StorageException {
-        authenticationCheck();
-        
-        String script;
-        try {
-            script = IOUtils.toString(_repository.getActive(getUser()), "UTF-8");
-        } catch (UserNotFoundException ex) {
-            // Should not happen as the UserListener should ensure the session
-            // user is defined in the repository
-            throw new ManageSieveRuntimeException(ex);
-        } catch (IOException ex) {
-            // Unable to read script InputStream
-            throw new ManageSieveRuntimeException(ex);
         }
-        return script;
     }
 
-}
+    protected boolean isAuthenticated() {
+        return session.isAuthenticated();
+    }
+}
\ No newline at end of file

Modified: james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/util/SettableSession.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/util/SettableSession.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/util/SettableSession.java (original)
+++ james/project/trunk/protocols/managesieve/src/main/java/org/apache/james/managesieve/util/SettableSession.java Thu Dec 17 14:51:18 2015
@@ -20,77 +20,29 @@
 
 package org.apache.james.managesieve.util;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.james.managesieve.api.Session;
 
-/**
- * <code>SettableSession</code>
- */
 public class SettableSession implements Session {
 
     String _user = null;
     boolean _isAuthenticated = false;
-    List<UserListener> _userListeners = new ArrayList<UserListener>();
-    List<AuthenticationListener> _authenticationListeners = new ArrayList<AuthenticationListener>(); 
-    
-    /**
-     * @see org.apache.james.managesieve.api.Session#addAuthenticationListener(org.apache.james.managesieve.api.Session.AuthenticationListener)
-     */
-    public void addAuthenticationListener(AuthenticationListener listener) {
-        _authenticationListeners.add(listener);
-    }
-
-    /**
-     * @see org.apache.james.managesieve.api.Session#addUserListener(org.apache.james.managesieve.api.Session.UserListener)
-     */
-    public void addUserListener(UserListener listener) {
-        _userListeners.add(listener);            
-    }
 
-    /**
-     * @see org.apache.james.managesieve.api.Session#getUser()
-     */
     public String getUser() {
         return _user;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.Session#isAuthenticated()
-     */
     public boolean isAuthenticated() {
         return _isAuthenticated;
     }
 
-    /**
-     * @see org.apache.james.managesieve.api.Session#removeAuthenticationListener(org.apache.james.managesieve.api.Session.AuthenticationListener)
-     */
-    public void removeAuthenticationListener(AuthenticationListener listener) {
-        _authenticationListeners.remove(listener);
-    }
 
-    /**
-     * @see org.apache.james.managesieve.api.Session#removeUserListener(org.apache.james.managesieve.api.Session.UserListener)
-     */
-    public void removeUserListener(UserListener listener) {
-        _userListeners.remove(listener);       
-    }
-    
     public void setAuthentication(boolean isAuthenticated) {
         _isAuthenticated = isAuthenticated;
-        for(AuthenticationListener listener : _authenticationListeners)
-        {                  
-            listener.notifyChange(isAuthenticated);
-        }                
+
     }
 
     public void setUser(String user) {
         _user = user;
-        for(UserListener listener : _userListeners)
-        {                  
-            listener.notifyChange(user);
-        }
     }
 
 }

Modified: james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java (original)
+++ james/project/trunk/protocols/managesieve/src/test/java/org/apache/james/managesieve/core/CoreProcessorTestCase.java Thu Dec 17 14:51:18 2015
@@ -20,346 +20,279 @@
 
 package org.apache.james.managesieve.core;
 
-import org.apache.commons.io.IOUtils;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Lists;
 import org.apache.james.managesieve.api.AuthenticationRequiredException;
+import org.apache.james.managesieve.api.SieveParser;
 import org.apache.james.managesieve.api.SyntaxException;
 import org.apache.james.managesieve.api.commands.Capability.Capabilities;
-import org.apache.james.managesieve.mock.MockSession;
-import org.apache.james.managesieve.mock.MockSieveParser;
-import org.apache.james.managesieve.mock.MockSieveRepository;
+import org.apache.james.managesieve.util.SettableSession;
+import org.apache.james.sieverepository.api.ScriptSummary;
+import org.apache.james.sieverepository.api.SieveRepository;
 import org.apache.james.sieverepository.api.exception.IsActiveException;
-import org.apache.james.sieverepository.api.exception.QuotaExceededException;
 import org.apache.james.sieverepository.api.exception.ScriptNotFoundException;
-import org.apache.james.sieverepository.api.ScriptSummary;
-import org.apache.james.sieverepository.api.exception.StorageException;
-import org.apache.james.sieverepository.api.exception.UserNotFoundException;
+import org.apache.james.user.api.UsersRepository;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 
-import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * <code>CoreProcessorTestCase</code>
- */
 public class CoreProcessorTestCase {
 
-    private MockSession session;
-    private MockSieveParser parser;
-    private MockSieveRepository repository;
+    public static final String USER = "test";
+    public static final String SCRIPT = "script";
+    public static final String CONTENT = "content";
+    public static final String OLDNAME = "oldname";
+    public static final String NEW_NAME = "newName";
+    private SettableSession session;
+    private SieveParser sieveParser;
+    private SieveRepository sieveRepository;
+
     private CoreProcessor core;
 
     @Before
     public void setUp() throws Exception {
-        session = new MockSession();
-        parser = new MockSieveParser();
-        repository = new MockSieveRepository();
-        core = new CoreProcessor(session, repository, parser);
+        session = new SettableSession();
+        sieveParser = mock(SieveParser.class);
+        sieveRepository = mock(SieveRepository.class);
+        UsersRepository usersRepository = mock(UsersRepository.class);
+        core = new CoreProcessor(session, sieveRepository, usersRepository, sieveParser);
+        when(usersRepository.contains(USER)).thenAnswer(new Answer<Boolean>() {
+            public Boolean answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return true;
+            }
+        });
     }
 
     @Test
-    public final void testCapability() {
-        // Unauthenticated
+    public final void testCapabilityUnauthenticated() {
         session.setAuthentication(false);
-        parser.setExtensions(Arrays.asList("a", "b", "c"));
-        Map<Capabilities, String> capabilities = core.capability();
-        assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
-        assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
-        assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
-        assertFalse(capabilities.containsKey(Capabilities.OWNER));
-        assertTrue(capabilities.containsKey(Capabilities.GETACTIVE));
-
-        // Authenticated
-        session.setAuthentication(true);
-        parser.setExtensions(Arrays.asList("a", "b", "c"));
-        session.setUser("test");
-        capabilities = core.capability();
-        assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
-        assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
-        assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
-        assertEquals("test", capabilities.get(Capabilities.OWNER));
-        assertTrue(capabilities.containsKey(Capabilities.GETACTIVE));
+        when(sieveParser.getExtensions()).thenAnswer(new Answer<List<String>>() {
+            public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return Lists.newArrayList("a", "b", "c");
+            }
+        });
+        assertThat(core.capability()).containsEntry(Capabilities.IMPLEMENTATION, CoreProcessor.IMPLEMENTATION_DESCRIPTION)
+            .containsEntry(Capabilities.VERSION, CoreProcessor.MANAGE_SIEVE_VERSION)
+            .containsEntry(Capabilities.SIEVE, "a b c")
+            .containsKey(Capabilities.GETACTIVE);
     }
 
     @Test
-    public final void testCheckScript() throws AuthenticationRequiredException, SyntaxException {
-        // Unauthorised
-        boolean success = false;
+    public final void testCapabilityAuthenticated() {
+        session.setAuthentication(true);
+        when(sieveParser.getExtensions()).thenAnswer(new Answer<List<String>>() {
+            public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return Lists.newArrayList("a", "b", "c");
+            }
+        });
+        session.setUser(USER);
+        assertThat(core.capability()).containsEntry(Capabilities.IMPLEMENTATION, CoreProcessor.IMPLEMENTATION_DESCRIPTION)
+            .containsEntry(Capabilities.VERSION, CoreProcessor.MANAGE_SIEVE_VERSION)
+            .containsEntry(Capabilities.SIEVE, "a b c")
+            .containsEntry(Capabilities.OWNER, USER)
+            .containsKey(Capabilities.GETACTIVE);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testCheckScriptUnauthorised() throws AuthenticationRequiredException, SyntaxException {
         session.setAuthentication(false);
-        try {
-            core.checkScript("warning");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised
-        session.setAuthentication(true);
-        session.setUser("test");
-        List<String> warnings = core.checkScript("warning");
-        assertEquals(2, warnings.size());
-        assertEquals("warning1", warnings.get(0));
-        assertEquals("warning2", warnings.get(1));
-
-        // Syntax
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        try {
-            core.checkScript("SyntaxException");
-        } catch (SyntaxException ex) {
-            success = true;
-        }
-        assertTrue("Expected SyntaxException", success);
+        core.checkScript("warning");
     }
 
     @Test
-    public final void testDeleteScript() throws Exception {
-        // Unauthorised
-        boolean success = false;
+    public final void testCheckScript() throws Exception {
+        session.setAuthentication(true);
+        session.setUser(USER);
+        when(sieveParser.parse(CONTENT)).thenAnswer(new Answer<List<String>>() {
+            public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return Lists.newArrayList("warning1", "warning2");
+            }
+        });
+        assertThat(core.checkScript(CONTENT)).containsOnly("warning1", "warning2");
+    }
+
+    @Test(expected = SyntaxException.class)
+    public final void testCheckScriptSyntaxException() throws Exception {
+        doThrow(new SyntaxException("Syntax exception")).when(sieveParser).parse(CONTENT);
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.checkScript(CONTENT);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testDeleteScriptUnauthorised() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.deleteScript("script");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised - non-existent script
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        try {
-            core.deleteScript("script");
-        } catch (ScriptNotFoundException ex) {
-            success = true;
-        }
-        assertTrue("Expected ScriptNotFoundException", success);
-
-        // Authorised - existent script
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        core.deleteScript("script");
-        success = false;
-        try {
-            repository.getScript("test", "script");
-        } catch (ScriptNotFoundException ex) {
-            success = true;
-        }
-        assertTrue("Expected ScriptNotFoundException", success);
-
-        // Authorised - active script
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        repository.setActive("test", "script");
-        try {
-            core.deleteScript("script");
-        } catch (IsActiveException ex) {
-            success = true;
-        }
-        assertTrue("Expected IsActiveException", success);
+        core.deleteScript(SCRIPT);
     }
 
+    @Test(expected = ScriptNotFoundException.class)
+    public final void testDeleteScriptNonExistent() throws Exception {
+        doThrow(new ScriptNotFoundException()).when(sieveRepository).deleteScript(USER, SCRIPT);
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.deleteScript(SCRIPT);
+    }
+
+
     @Test
-    public final void testGetScript() throws ScriptNotFoundException, AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
-        // Unauthorised
-        boolean success = false;
+    public final void testDeleteScriptExistent() throws Exception {
+        session.setAuthentication(true);
+        session.setUser(USER);
+        sieveRepository.putScript(USER, SCRIPT, CONTENT);
+        core.deleteScript(SCRIPT);
+        verify(sieveRepository).deleteScript(USER, SCRIPT);
+    }
+
+    @Test(expected = IsActiveException.class)
+    public final void testDeleteScriptActive() throws Exception {
+        doThrow(new IsActiveException()).when(sieveRepository).deleteScript(USER, SCRIPT);
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.deleteScript(SCRIPT);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testGetUnauthorisedScript() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.getScript("script");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised - non-existent script
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        try {
-            core.getScript("script");
-            System.out.println("yop yop");
-        } catch (ScriptNotFoundException ex) {
-            success = true;
-            ex.printStackTrace();
-        } catch (Exception e) {
-            System.out.println("Euh ... ");
-            e.printStackTrace();
-            System.out.println("Yolo");
-        }
-        assertTrue("Expected ScriptNotFoundException", success);
-
-        // Authorised - existent script
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        core.getScript("script");
+        core.getScript(SCRIPT);
+    }
+
+    @Test(expected = ScriptNotFoundException.class)
+    public final void testGetNonExistentScript() throws Exception {
+        doThrow(new ScriptNotFoundException()).when(sieveRepository).getScript(USER, SCRIPT);
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.getScript(SCRIPT);
     }
 
     @Test
-    public final void testHaveSpace() throws Exception {
-        // Unauthorised
-        boolean success = false;
+    public final void testGetScript() throws Exception {
+        session.setAuthentication(true);
+        session.setUser(USER);
+        when(sieveRepository.getScript(USER, SCRIPT)).thenAnswer(new Answer<String>() {
+            public String answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return CONTENT;
+            }
+        });
+        assertThat(core.getScript(SCRIPT)).isEqualTo(CONTENT);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testHaveSpaceUnauthorised() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.haveSpace("script", Long.MAX_VALUE);
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
+        core.haveSpace(SCRIPT, Long.MAX_VALUE);
+    }
 
-        // Authorised - existent script
+    @Test
+    public final void testHaveSpace() throws Exception {
         session.setAuthentication(true);
-        session.setUser("test");
-        core.haveSpace("script", Long.MAX_VALUE);
+        session.setUser(USER);
+        core.haveSpace(SCRIPT, Long.MAX_VALUE);
+        verify(sieveRepository).haveSpace(USER, SCRIPT, Long.MAX_VALUE);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testListScriptsUnauthorised() throws Exception {
+        session.setAuthentication(false);
+        core.listScripts();
     }
 
     @Test
     public final void testListScripts() throws Exception {
-        // Unauthorised
-        boolean success = false;
+        session.setAuthentication(true);
+        session.setUser(USER);
+        when(sieveRepository.listScripts(USER)).thenAnswer(new Answer<List<ScriptSummary>>() {
+            @Override
+            public List<ScriptSummary> answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return Lists.newArrayList(new ScriptSummary(SCRIPT, false));
+            }
+        });
+        sieveRepository.putScript(USER, SCRIPT, CONTENT);
+        assertThat(core.listScripts()).containsOnly(new ScriptSummary(SCRIPT, false));
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testPutScriptUnauthorised() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.listScripts();
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
+        core.putScript(SCRIPT, CONTENT);
+    }
 
-        // Authorised - non-existent script
-        success = false;
+    @Test
+    public final void testPutScriptAuthorized() throws Exception {
         session.setAuthentication(true);
-        session.setUser("test");
-        List<ScriptSummary> summaries = core.listScripts();
-        assertTrue(summaries.isEmpty());
+        session.setUser(USER);
+        core.putScript(SCRIPT, CONTENT);
+        verify(sieveRepository).putScript(USER, SCRIPT, CONTENT);
+    }
 
-        // Authorised - existent script
+    @Test(expected = SyntaxException.class)
+    public final void testPutScriptSyntaxException() throws Exception {
+        doThrow(new SyntaxException("Syntax exception")).when(sieveParser).parse(CONTENT);
         session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        summaries = core.listScripts();
-        assertEquals(1, summaries.size());
+        session.setUser(USER);
+        core.putScript(SCRIPT, CONTENT);
     }
 
-    @Test
-    public final void testPutScript() throws Exception {
-        // Unauthorised
-        boolean success = false;
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testRenameScriptUnauthorized() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.putScript("script", "content");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        core.putScript("script", "content");
-        assertEquals("content", IOUtils.toString(repository.getScript("test", "script")));
-
-        // Syntax
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        try {
-            core.putScript("script", "SyntaxException");
-        } catch (SyntaxException ex) {
-            success = true;
-        }
-        assertTrue("Expected SyntaxException", success);
+        core.renameScript(OLDNAME, NEW_NAME);
     }
 
     @Test
     public final void testRenameScript() throws Exception {
-        // Unauthorised
-        boolean success = false;
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.renameScript(OLDNAME, NEW_NAME);
+        verify(sieveRepository).renameScript(USER, OLDNAME, NEW_NAME);
+    }
+
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testSetActiveUnauthorised() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.renameScript("oldName", "newName");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "oldName", "content");
-        core.renameScript("oldName", "newName");
-        assertEquals("content", IOUtils.toString(repository.getScript("test", "oldName")));
+        core.setActive(SCRIPT);
     }
 
     @Test
     public final void testSetActive() throws Exception {
-        // Unauthorised
-        boolean success = false;
-        session.setAuthentication(false);
-        try {
-            core.setActive("script");
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        core.setActive("script");
-        assertEquals("content", IOUtils.toString(repository.getActive("test")));
+        session.setAuthentication(true);
+        session.setUser(USER);
+        core.setActive(SCRIPT);
+        verify(sieveRepository).setActive(USER, SCRIPT);
     }
 
-    @Test
-    public final void testGetActive() throws Exception {
-        // Unauthorised
-        boolean success = false;
+    @Test(expected = AuthenticationRequiredException.class)
+    public final void testGetUnauthorisedActive() throws Exception {
         session.setAuthentication(false);
-        try {
-            core.getActive();
-        } catch (AuthenticationRequiredException ex) {
-            success = true;
-        }
-        assertTrue("Expected AuthenticationRequiredException", success);
-
-        // Authorised - non-existent script
-        success = false;
-        session.setAuthentication(true);
-        session.setUser("test");
-        try {
-            core.getActive();
-        } catch (ScriptNotFoundException ex) {
-            success = true;
-        }
-        assertTrue("Expected ScriptNotFoundException", success);
-
-        // Authorised - existent script, inactive
-        session.setAuthentication(true);
-        session.setUser("test");
-        repository.putScript("test", "script", "content");
-        try {
-            core.getActive();
-        } catch (ScriptNotFoundException ex) {
-            success = true;
-        }
-        assertTrue("Expected ScriptNotFoundException", success);
+        core.getActive();
+    }
 
-        // Authorised - existent script, active
+    @Test(expected = ScriptNotFoundException.class)
+    public final void testGetNonExistentActive() throws Exception {
+        doThrow(new ScriptNotFoundException()).when(sieveRepository).getActive(USER);
         session.setAuthentication(true);
-        session.setUser("test");
-        repository.setActive("test", "script");
+        session.setUser(USER);
         core.getActive();
     }
+
+    @Test
+    public final void testGetActive() throws Exception {
+        session.setAuthentication(true);
+        session.setUser(USER);
+        sieveRepository.setActive(USER, SCRIPT);
+        when(sieveRepository.getActive(USER)).thenAnswer(new Answer<String>() {
+            public String answer(InvocationOnMock invocationOnMock) throws Throwable {
+                return CONTENT;
+            }
+        });
+        assertThat(core.getActive()).isEqualTo(CONTENT);
+    }
 }

Modified: james/project/trunk/protocols/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/protocols/pom.xml?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/protocols/pom.xml (original)
+++ james/project/trunk/protocols/pom.xml Thu Dec 17 14:51:18 2015
@@ -64,6 +64,7 @@
         <slf4j.version>1.6.3</slf4j.version>
         <james-server-data-api.version>3.0.0-beta5-SNAPSHOT</james-server-data-api.version>
         <jsieve.version>0.6-SNAPSHOT</jsieve.version>
+        <mockito-core.version>1.9.0</mockito-core.version>
     </properties>
 
     <dependencyManagement>
@@ -244,6 +245,16 @@
                 <artifactId>geronimo-javamail_1.4_mail</artifactId>
                 <version>${geronimo-javamail.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.mockito</groupId>
+                <artifactId>mockito-core</artifactId>
+                <version>${mockito-core.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>1.7.1</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

Modified: james/project/trunk/server/data/data-api/src/main/java/org/apache/james/sieverepository/api/SieveRepository.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-api/src/main/java/org/apache/james/sieverepository/api/SieveRepository.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/server/data/data-api/src/main/java/org/apache/james/sieverepository/api/SieveRepository.java (original)
+++ james/project/trunk/server/data/data-api/src/main/java/org/apache/james/sieverepository/api/SieveRepository.java Thu Dec 17 14:51:18 2015
@@ -66,12 +66,6 @@ public interface SieveRepository {
     void deleteScript(String user, String name) throws UserNotFoundException, ScriptNotFoundException, IsActiveException, StorageException;
     
     void renameScript(String user, String oldName, String newName) throws UserNotFoundException, ScriptNotFoundException, DuplicateException, StorageException;
-    
-    boolean hasUser(String user) throws StorageException;
-    
-    void addUser(String user) throws DuplicateUserException, StorageException;
-    
-    void removeUser(String user) throws UserNotFoundException, StorageException;
 
     boolean hasQuota() throws StorageException;
     

Modified: james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveDefaultRepository.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveDefaultRepository.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveDefaultRepository.java (original)
+++ james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveDefaultRepository.java Thu Dec 17 14:51:18 2015
@@ -109,21 +109,6 @@ public class SieveDefaultRepository impl
     }
 
     @Override
-    public boolean hasUser(String user) throws StorageException {
-        throw new StorageException("This implementation is deprecated and does not support user related operation. Please consider using a SieveFileRepository.");
-    }
-
-    @Override
-    public void addUser(String user) throws DuplicateUserException, StorageException {
-        throw new StorageException("This implementation is deprecated and does not support user related operation. Please consider using a SieveFileRepository.");
-    }
-
-    @Override
-    public void removeUser(String user) throws UserNotFoundException, StorageException {
-        throw new StorageException("This implementation is deprecated and does not support user related operation. Please consider using a SieveFileRepository.");
-    }
-
-    @Override
     public boolean hasQuota() throws StorageException {
         throw apologizeForQuotas();
     }

Modified: james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java (original)
+++ james/project/trunk/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java Thu Dec 17 14:51:18 2015
@@ -23,14 +23,13 @@ package org.apache.james.sieverepository
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.sieverepository.api.ScriptSummary;
+import org.apache.james.sieverepository.api.SieveRepository;
 import org.apache.james.sieverepository.api.exception.DuplicateException;
-import org.apache.james.sieverepository.api.exception.DuplicateUserException;
 import org.apache.james.sieverepository.api.exception.IsActiveException;
 import org.apache.james.sieverepository.api.exception.QuotaExceededException;
 import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
 import org.apache.james.sieverepository.api.exception.ScriptNotFoundException;
-import org.apache.james.sieverepository.api.ScriptSummary;
-import org.apache.james.sieverepository.api.SieveRepository;
 import org.apache.james.sieverepository.api.exception.StorageException;
 import org.apache.james.sieverepository.api.exception.UserNotFoundException;
 
@@ -331,7 +330,7 @@ public class SieveFileRepository impleme
     protected File getUserDirectory(String user) throws UserNotFoundException, StorageException {
         File file = getUserDirectoryFile(user);
         if (!file.exists()) {
-            throw new UserNotFoundException("User: " + user);
+            ensureUser(user);
         }
         return file;
     }
@@ -391,47 +390,12 @@ public class SieveFileRepository impleme
         return file;
     }
 
-
-    @Override
-    public boolean hasUser(final String user) throws StorageException {
-        boolean userExists = true;
-        try {
-            getUserDirectory(user);
-        } catch (UserNotFoundException ex) {
-            userExists = false;
-        }
-        return userExists;
-    }
-
-    @Override
-    public void addUser(final String user) throws DuplicateUserException, StorageException {
+    public void ensureUser(final String user) throws StorageException {
         synchronized (lock) {
-            boolean userExists = true;
             try {
-                getUserDirectory(user);
-            } catch (UserNotFoundException ex) {
-                userExists = false;
-            }
-            if (userExists) {
-                throw new DuplicateUserException("User: " + user);
-            }
-            File dir = getUserDirectoryFile(user);
-            try {
-                FileUtils.forceMkdir(dir);
-            } catch (IOException ex) {
-                throw new StorageException(ex);
-            }
-        }
-    }
-
-    @Override
-    public void removeUser(final String user) throws UserNotFoundException, StorageException {
-        synchronized (lock) {
-            File dir = getUserDirectory(user);
-            try {
-                FileUtils.forceDelete(dir);
-            } catch (IOException ex) {
-                throw new StorageException(ex);
+                FileUtils.forceMkdir(getUserDirectoryFile(user));
+            } catch (IOException e) {
+                throw new StorageException("Error while creating directory for " + user, e);
             }
         }
     }

Modified: james/project/trunk/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java (original)
+++ james/project/trunk/server/data/data-library/src/test/java/org/apache/james/sieverepository/lib/AbstractSieveRepositoryTest.java Thu Dec 17 14:51:18 2015
@@ -59,52 +59,36 @@ public abstract class AbstractSieveRepos
         cleanUp();
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void getScriptShouldThrowIfUserDoesNotExist() throws Exception {
-        sieveRepository.getScript(USER, SCRIPT_NAME);
-    }
-
     @Test(expected = ScriptNotFoundException.class)
     public void getScriptShouldThrowIfUnableToFindScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.getScript(USER, SCRIPT_NAME);
     }
 
     @Test
     public void getScriptShouldReturnCorrectContent() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         assertThat(getScriptContent(sieveRepository.getScript(USER, SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void haveSpaceShouldThrowIfUserDoesNotExist() throws Exception {
-        sieveRepository.haveSpace(USER, SCRIPT_NAME, DEFAULT_QUOTA + 1L);
-    }
-
     @Test
     public void haveSpaceShouldNotThrowWhenUserDoesNotHaveQuota() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, DEFAULT_QUOTA + 1L);
     }
 
     @Test
     public void haveSpaceShouldNotThrowWhenQuotaIsNotReached() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(DEFAULT_QUOTA);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, DEFAULT_QUOTA);
     }
 
     @Test(expected = QuotaExceededException.class)
     public void haveSpaceShouldThrowWhenQuotaIsExceed() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(DEFAULT_QUOTA);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, DEFAULT_QUOTA + 1);
     }
 
     @Test
     public void haveSpaceShouldNotThrowWhenAttemptToReplaceOtherScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, USER_QUOTA);
@@ -112,7 +96,6 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = QuotaExceededException.class)
     public void haveSpaceShouldThrowWhenAttemptToReplaceOtherScriptWithTooLargeScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, USER_QUOTA + 1);
@@ -120,7 +103,6 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = QuotaExceededException.class)
     public void haveSpaceShouldTakeAlreadyExistingScriptsIntoAccount() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.haveSpace(USER, OTHER_SCRIPT_NAME, USER_QUOTA - 1);
@@ -128,34 +110,30 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void haveSpaceShouldNotThrowAfterActivatingAScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.haveSpace(USER, SCRIPT_NAME, USER_QUOTA);
     }
 
-    @Test(expected = UserNotFoundException.class)
+    @Test
     public void listScriptsShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.listScripts(USER);
+        assertThat(sieveRepository.listScripts(USER)).isEmpty();
     }
 
     @Test
     public void listScriptsShouldReturnEmptyListWhenThereIsNoScript() throws Exception {
-        sieveRepository.addUser(USER);
         assertThat(sieveRepository.listScripts(USER)).isEmpty();
     }
 
     @Test
     public void putScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         assertThat(sieveRepository.listScripts(USER)).containsOnly(new ScriptSummary(SCRIPT_NAME, false));
     }
 
     @Test
     public void setActiveShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         assertThat(sieveRepository.listScripts(USER)).containsOnly(new ScriptSummary(SCRIPT_NAME, true));
@@ -163,71 +141,33 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void listScriptShouldCombineActiveAndPassiveScripts() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.putScript(USER, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
         assertThat(sieveRepository.listScripts(USER)).containsOnly(new ScriptSummary(SCRIPT_NAME, true), new ScriptSummary(OTHER_SCRIPT_NAME, false));
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void putScriptShouldThrowIfUserDoesNotExist() throws Exception {
-        sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
-    }
-
     @Test(expected = QuotaExceededException.class)
     public void putScriptShouldThrowWhenScriptTooBig() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(SCRIPT_CONTENT.length() - 1);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
     }
 
     @Test(expected = QuotaExceededException.class)
     public void putScriptShouldThrowWhenQuotaChangedInBetween() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(SCRIPT_CONTENT.length());
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setQuota(SCRIPT_CONTENT.length() - 1);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
     }
 
-    @Test
-    public void hasUserShouldReturnFalseOnNonExistingUser() throws Exception {
-        assertThat(sieveRepository.hasUser(USER)).isFalse();
-    }
-
-    @Test
-    public void hasUserShouldReturnTrueOnExistingUser() throws Exception {
-        sieveRepository.addUser(USER);
-        assertThat(sieveRepository.hasUser(USER)).isTrue();
-    }
-
-    @Test(expected = UserNotFoundException.class)
-    public void removeUserShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.removeUser(USER);
-    }
-
-    @Test
-    public void removeUserShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
-        sieveRepository.removeUser(USER);
-        assertThat(sieveRepository.hasUser(USER)).isFalse();
-    }
-
-    @Test(expected = UserNotFoundException.class)
-    public void setActiveScriptShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.setActive(USER, SCRIPT_NAME);
-    }
-
     @Test(expected = ScriptNotFoundException.class)
     public void setActiveScriptShouldThrowOnNonExistentScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setActive(USER, SCRIPT_NAME);
     }
 
     @Test
     public void setActiveScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         assertThat(getScriptContent(sieveRepository.getActive(USER))).isEqualTo(SCRIPT_CONTENT);
@@ -235,7 +175,6 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void setActiveSwitchScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.putScript(USER, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
@@ -245,7 +184,6 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = ScriptNotFoundException.class)
     public void switchOffActiveScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.setActive(USER, "");
@@ -254,7 +192,6 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void switchOffActiveScriptShouldNotThrow() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.setActive(USER, "");
@@ -262,24 +199,16 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = ScriptNotFoundException.class)
     public void getActiveShouldThrowWhenNoActiveScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.getActive(USER);
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void deleteActiveScriptShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.deleteScript(USER, SCRIPT_NAME);
-    }
-
     @Test(expected = ScriptNotFoundException.class)
     public void deleteActiveScriptShouldThrowIfScriptDoNotExist() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.deleteScript(USER, SCRIPT_NAME);
     }
 
     @Test(expected = IsActiveException.class)
     public void deleteActiveScriptShouldThrow() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.deleteScript(USER, SCRIPT_NAME);
@@ -287,27 +216,19 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = IsActiveException.class)
     public void deleteScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.deleteScript(USER, SCRIPT_NAME);
         sieveRepository.getScript(USER, SCRIPT_NAME);
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void renameScriptShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.renameScript(USER, SCRIPT_NAME, OTHER_SCRIPT_NAME);
-    }
-
     @Test(expected = ScriptNotFoundException.class)
     public void renameScriptShouldThrowIfScriptNotFound() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.renameScript(USER, SCRIPT_NAME, OTHER_SCRIPT_NAME);
     }
 
     @Test
     public void renameScriptShouldWork() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.renameScript(USER, SCRIPT_NAME, OTHER_SCRIPT_NAME);
         assertThat(getScriptContent(sieveRepository.getScript(USER, OTHER_SCRIPT_NAME))).isEqualTo(SCRIPT_CONTENT);
@@ -315,7 +236,6 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void renameScriptShouldPropagateActiveScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.setActive(USER, SCRIPT_NAME);
         sieveRepository.renameScript(USER, SCRIPT_NAME, OTHER_SCRIPT_NAME);
@@ -324,17 +244,11 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = DuplicateException.class)
     public void renameScriptShouldNotOverwriteExistingScript() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.putScript(USER, SCRIPT_NAME, SCRIPT_CONTENT);
         sieveRepository.putScript(USER, OTHER_SCRIPT_NAME, OTHER_SCRIPT_CONTENT);
         sieveRepository.renameScript(USER, SCRIPT_NAME, OTHER_SCRIPT_NAME);
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void getQuotaShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.getQuota(USER);
-    }
-
     @Test(expected = QuotaNotFoundException.class)
     public void getQuotaShouldThrowIfQuotaNotFound() throws Exception {
         sieveRepository.getQuota();
@@ -348,16 +262,10 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void getQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         assertThat(sieveRepository.getQuota(USER)).isEqualTo(USER_QUOTA);
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void hasQuotaShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.hasQuota(USER);
-    }
-
     @Test
     public void hasQuotaShouldReturnFalseWhenRepositoryDoesNotHaveQuota() throws Exception {
         assertThat(sieveRepository.hasQuota()).isFalse();
@@ -371,22 +279,15 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void hasQuotaShouldReturnFalseWhenUserDoesNotHaveQuota() throws Exception {
-        sieveRepository.addUser(USER);
         assertThat(sieveRepository.hasQuota()).isFalse();
     }
 
     @Test
     public void hasQuotaShouldReturnTrueWhenUserHaveQuota() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, DEFAULT_QUOTA);
         assertThat(sieveRepository.hasQuota(USER)).isTrue();
     }
 
-    @Test(expected = UserNotFoundException.class)
-    public void removeQuotaShouldThrowIfUserNotFound() throws Exception {
-        sieveRepository.removeQuota(USER);
-    }
-
     @Test(expected = QuotaNotFoundException.class)
     public void removeQuotaShouldThrowIfRepositoryDoesNotHaveQuota() throws Exception {
         sieveRepository.removeQuota();
@@ -401,7 +302,6 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void removeQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.removeQuota(USER);
         assertThat(sieveRepository.hasQuota(USER)).isFalse();
@@ -409,7 +309,6 @@ public abstract class AbstractSieveRepos
 
     @Test(expected = QuotaNotFoundException.class)
     public void removeQuotaShouldWorkOnUsersWithGlobalQuota() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(DEFAULT_QUOTA);
         sieveRepository.setQuota(USER, USER_QUOTA);
         sieveRepository.removeQuota(USER);
@@ -424,7 +323,6 @@ public abstract class AbstractSieveRepos
 
     @Test
     public void setQuotaShouldWorkOnUsers() throws Exception {
-        sieveRepository.addUser(USER);
         sieveRepository.setQuota(USER, DEFAULT_QUOTA);
         assertThat(sieveRepository.getQuota(USER)).isEqualTo(DEFAULT_QUOTA);
     }

Modified: james/project/trunk/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailet.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailet.java?rev=1720561&r1=1720560&r2=1720561&view=diff
==============================================================================
--- james/project/trunk/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailet.java (original)
+++ james/project/trunk/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/managesieve/ManageSieveMailet.java Thu Dec 17 14:51:18 2015
@@ -36,6 +36,7 @@ import org.apache.james.managesieve.tran
 import org.apache.james.managesieve.util.SettableSession;
 import org.apache.james.sieverepository.api.SieveRepository;
 import org.apache.james.transport.mailets.managesieve.transcode.MessageToCoreToMessage;
+import org.apache.james.user.api.UsersRepository;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
@@ -88,10 +89,6 @@ public class ManageSieveMailet extends G
             super();
         }
 
-        /**
-         * @param mail
-         *            the mail to set
-         */
         public void setMail(Mail mail) {
             setUser(getUser(mail.getSender()));
             setAuthentication(null != mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME));
@@ -105,86 +102,42 @@ public class ManageSieveMailet extends G
 
     public final static String SMTP_AUTH_USER_ATTRIBUTE_NAME = "org.apache.james.SMTPAuthUser";
 
-    private MailSession _session = null;
-
+    private MailSession session = null;
     // Injected
-    private SieveRepository _sieveRepository = null;
-
+    private SieveRepository sieveRepository = null;
     // Injected
-    private SieveParser _sieveParser = null;
+    private SieveParser sieveParser = null;
+    private UsersRepository usersRepository;
+    private MessageToCoreToMessage transcoder = null;
+    private URL helpURL = null;
+    private String help = null;
+    private boolean cache = true;
 
-    private MessageToCoreToMessage _transcoder = null;
-    
-    private URL _helpURL = null;
-    
-    private String _help = null;
-    
-    private boolean _cache = true;
-
-    /**
-     * Creates a new instance of ManageSieveMailet.
-     * 
-     */
-    public ManageSieveMailet() {
-        super();
-    }
-    
-    /**
-     * Creates a new instance of ManageSieveMailet.
-     *
-     * @param sieveRepository
-     * @param sieveParser
-     */
-    public ManageSieveMailet(SieveRepository sieveRepository, SieveParser sieveParser)
-    {
-        this();
-        setSieveRepository(sieveRepository);
-        setSieveParser(sieveParser);
-    }
-     
-    /**
-     * @see GenericMailet#init()
-     */
     @Override
     public void init() throws MessagingException {
         super.init();
         // Validate resources
-        if (null == _sieveParser)
-        {
+        if (null == sieveParser) {
             throw new MessagingException("Missing resource \"sieveparser\"");
         }
-        if (null == _sieveRepository)
-        {
+        if (null == sieveRepository) {
             throw new MessagingException("Missing resource \"sieverepository\"");
         }
         
         setHelpURL(getInitParameter("helpURL"));
-        _cache = getInitParameter("cache", true);
-        _session = new MailSession();
-        _transcoder = new MessageToCoreToMessage(new LineToCoreToLine(new LineToCore(new CoreProcessor(_session,
-                _sieveRepository, _sieveParser))), this);
-    }
-    
-    protected void setHelpURL(String helpURL) throws MessagingException
-    {
-        try
-        {
-            _helpURL = new URL(helpURL);
-        }
-        catch (MalformedURLException ex)
-        {
-            throw new MessagingException("Invalid helpURL", ex);
-        }
-    } 
+        cache = getInitParameter("cache", true);
+        session = new MailSession();
+        transcoder = new MessageToCoreToMessage(
+            new LineToCoreToLine(
+                new LineToCore(
+                    new CoreProcessor(session, sieveRepository, usersRepository, sieveParser))),
+            this);
+    }
 
-    /**
-     * @see GenericMailet#service(Mail)
-     */
     @Override
     public void service(Mail mail) throws MessagingException {
-
         // Sanity checks
-        if (null == mail.getSender()) {
+        if (mail.getSender() == null) {
             getMailetContext().log("ERROR: Sender is null");
             return;
         }
@@ -195,44 +148,65 @@ public class ManageSieveMailet extends G
         }
 
         // Update the Session for the current mail and execute
-        _session.setMail(mail);
-        getMailetContext().sendMail(_transcoder.execute(mail.getMessage()));
+        session.setMail(mail);
+        getMailetContext().sendMail(transcoder.execute(mail.getMessage()));
         mail.setState(Mail.GHOST);
         
         // And tidy up
         clearCaches();
     }
-    
-    protected void clearCaches()
-    {
-        if (!_cache)
-        {
-            _help = null;
+
+    @Inject
+    public void setSieveRepository(SieveRepository repository) {
+        sieveRepository = repository;
+    }
+
+    @Inject
+    public void setSieveParser(SieveParser sieveParser) {
+        this.sieveParser = sieveParser;
+    }
+
+    @Inject
+    public void setUsersRepository(UsersRepository usersRepository) {
+        this.usersRepository = usersRepository;
+    }
+
+    @Override
+    public String getMailetInfo() {
+        return getClass().getName();
+    }
+
+    protected void setHelpURL(String helpURL) throws MessagingException {
+        try {
+            this.helpURL = new URL(helpURL);
+        } catch (MalformedURLException ex) {
+            throw new MessagingException("Invalid helpURL", ex);
+        }
+    }
+
+    protected void clearCaches() {
+        if (!cache) {
+            help = null;
         }
     }
 
     public String getHelp() throws MessagingException {
-        if (null == _help)
-        {
-            _help = computeHelp();
-        }
-        return _help;
-    }
-    
-    protected String computeHelp() throws MessagingException
-    {
+        if (null == help) {
+            help = computeHelp();
+        }
+        return help;
+    }
+
+    protected String computeHelp() throws MessagingException {
         InputStream stream = null;
-        String help = null;
         try {
-            stream = _helpURL.openStream();
-            help = new Scanner(stream, "UTF-8").useDelimiter("\\A").next();
+            stream = helpURL.openStream();
+            return new Scanner(stream, "UTF-8").useDelimiter("\\A").next();
         } catch (IOException ex) {
-            throw new MessagingException("Unable to access help URL: " + _helpURL.toExternalForm(), ex);
+            throw new MessagingException("Unable to access help URL: " + helpURL.toExternalForm(), ex);
         }
-        finally
-        {
-            if (null != stream)
-            {
+        finally {
+            if (stream != null) {
                 try {
                     stream.close();
                 } catch (IOException ex) {
@@ -240,31 +214,6 @@ public class ManageSieveMailet extends G
                 }
             }
         }
-        return help;
-    }
-
-    /**
-     */
-    @Inject
-    public void setSieveRepository(SieveRepository repository) {
-        _sieveRepository = repository;
-    }
-
-    /**
-     * @param sieveParser
-     *            the sieveParser to set
-     */
-    @Inject
-    public void setSieveParser(SieveParser sieveParser) {
-        _sieveParser = sieveParser;
-    }
-
-    /**
-     * @see GenericMailet#getMailetInfo()
-     */
-    @Override
-    public String getMailetInfo() {
-        return getClass().getName();
     }
 
 }



---------------------------------------------------------------------
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