You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/04/03 11:10:00 UTC

[01/15] james-project git commit: MAILET-152 Add instructions for implementing TooMuchRecipients

Repository: james-project
Updated Branches:
  refs/heads/master 5d3bedee1 -> a281f59fd


MAILET-152 Add instructions for implementing TooMuchRecipients


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

Branch: refs/heads/master
Commit: 398663e7bc575c5e95fb6f470a81b49a27394717
Parents: 5d3bede
Author: benwa <bt...@linagora.com>
Authored: Tue Mar 21 09:16:03 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:24 2017 +0700

----------------------------------------------------------------------
 .../transport/matchers/TooManyRecipients.java   |  62 +++++++
 .../matchers/TooManyRecipientsTest.java         | 172 +++++++++++++++++++
 2 files changed, 234 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/398663e7/mailet/standard/src/main/java/org/apache/james/transport/matchers/TooManyRecipients.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/TooManyRecipients.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/TooManyRecipients.java
new file mode 100644
index 0000000..51895a3
--- /dev/null
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/TooManyRecipients.java
@@ -0,0 +1,62 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.GenericMatcher;
+
+import com.google.common.collect.ImmutableList;
+
+public class TooManyRecipients extends GenericMatcher {
+
+    private int maximumRecipientCount;
+
+    @Override
+    public void init() throws MessagingException {
+        String condition = getCondition();
+
+        if (condition == null) {
+            throw new MessagingException("it should have a condition");
+        }
+
+        try {
+            maximumRecipientCount = Integer.parseInt(condition);
+        } catch (Exception e) {
+            throw new MessagingException("Condition should be a number");
+        }
+
+        if (maximumRecipientCount < 1) {
+            throw new MessagingException("it should be positive condition");
+        }
+    }
+
+    @Override
+    public Collection<MailAddress> match(Mail mail) throws MessagingException {
+        if (mail.getRecipients().size() > maximumRecipientCount) {
+            return mail.getRecipients();
+        }
+        return ImmutableList.of();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/398663e7/mailet/standard/src/test/java/org/apache/james/transport/matchers/TooManyRecipientsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/TooManyRecipientsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/TooManyRecipientsTest.java
new file mode 100644
index 0000000..d399d11
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/TooManyRecipientsTest.java
@@ -0,0 +1,172 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.google.common.collect.ImmutableList;
+
+public class TooManyRecipientsTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    private TooManyRecipients testee;
+
+    @Before
+    public void setUp() {
+        testee = new TooManyRecipients();
+    }
+
+    @Test
+    public void initShouldThrowOnAbsentCondition() throws Exception {
+        expectedException.expect(MessagingException.class);
+
+        testee.init(FakeMatcherConfig.builder()
+            .matcherName("matcherName")
+            .build());
+    }
+
+    @Test
+    public void initShouldThrowOnInvalidCondition() throws Exception{
+        expectedException.expect(MessagingException.class);
+
+        testee.init(FakeMatcherConfig.builder()
+            .condition("a")
+            .matcherName("matcherName")
+            .build());
+    }
+
+    @Test
+    public void initShouldThrowOnEmptyCondition() throws Exception {
+        expectedException.expect(MessagingException.class);
+
+        testee.init(FakeMatcherConfig.builder()
+            .condition("")
+            .matcherName("matcherName")
+            .build());
+    }
+
+    @Test
+    public void initShouldThrowOnZeroCondition() throws Exception {
+        expectedException.expect(MessagingException.class);
+
+        testee.init(FakeMatcherConfig.builder()
+            .condition("0")
+            .matcherName("matcherName")
+            .build());
+    }
+
+    @Test
+    public void initShouldThrowOnNegativeCondition() throws Exception {
+        expectedException.expect(MessagingException.class);
+
+        testee.init(FakeMatcherConfig.builder()
+            .condition("-10")
+            .matcherName("matcherName")
+            .build());
+    }
+
+    @Test
+    public void matchShouldReturnNoRecipientWhenMailHaveNoRecipient() throws Exception {
+        testee.init(FakeMatcherConfig.builder()
+            .condition("3")
+            .matcherName("matcherName")
+            .build());
+
+        Collection<MailAddress> result = testee.match(FakeMail.builder().build());
+
+        assertThat(result).isEmpty();
+    }
+
+    @Test
+    public void matchShouldAcceptMailsUnderLimit() throws Exception {
+        testee.init(FakeMatcherConfig.builder()
+            .condition("3")
+            .matcherName("matcherName")
+            .build());
+
+        FakeMail fakeMail = FakeMail.builder()
+            .recipient(new MailAddress("cuong.tran@gmail.com"))
+            .build();
+
+        Collection<MailAddress> result = testee.match(fakeMail);
+
+        assertThat(result).isEmpty();
+    }
+
+
+    @Test
+    public void matchShouldAcceptMailsAtLimit() throws Exception {
+        testee.init(FakeMatcherConfig.builder()
+            .condition("3")
+            .matcherName("matcherName")
+            .build());
+
+        ImmutableList<MailAddress> mailAddresses = ImmutableList.of(
+            new MailAddress("cuong.tran@gmail.com"),
+            new MailAddress("suu.tran@gmail.com"),
+            new MailAddress("tuan.tran@gmail.com"));
+
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(mailAddresses)
+            .build();
+
+        Collection<MailAddress> result = testee.match(fakeMail);
+
+        assertThat(result).isEmpty();
+    }
+
+    @Test
+    public void matchShouldRejectMailsOverLimit() throws Exception {
+        testee.init(FakeMatcherConfig.builder()
+            .condition("3")
+            .matcherName("matcherName")
+            .build());
+
+        ImmutableList<MailAddress> mailAddresses = ImmutableList.of(
+            new MailAddress("cuong.tran@gmail.com"),
+            new MailAddress("suu.tran@gmail.com"),
+            new MailAddress("tuan.tran@gmail.com"),
+            new MailAddress("sang.tran@gmail.com"));
+
+
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(mailAddresses)
+            .build();
+
+        Collection<MailAddress> result = testee.match(fakeMail);
+
+        assertThat(result).isEqualTo(mailAddresses);
+    }
+
+}


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


[13/15] james-project git commit: JAMES-1983 Write CLI integration tests on the printed output

Posted by bt...@apache.org.
JAMES-1983 Write CLI integration tests on the printed output


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

Branch: refs/heads/master
Commit: c994be049e91bb3e9a6ca0fa31dec94fb2d23860
Parents: e854211
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 18:24:01 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:33 2017 +0700

----------------------------------------------------------------------
 .../james/cli/DataCommandsIntegrationTest.java  | 97 +++++++++++++++-----
 .../cli/MailboxCommandsIntegrationTest.java     | 25 +++--
 .../james/cli/QuotaCommandsIntegrationTest.java | 83 ++++++++++++++---
 .../cli/SieveQuotaCommandsIntegrationTest.java  | 31 +++++--
 .../apache/james/cli/util/OutputCapture.java    | 39 ++++++++
 .../james/cli/util/OutputCaptureTest.java       | 58 ++++++++++++
 .../java/org/apache/james/cli/ServerCmd.java    | 63 +++++++------
 7 files changed, 315 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
index 1e3a6d3..9c46c2a 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
@@ -24,32 +24,27 @@ import static org.mockito.Mockito.mock;
 
 import java.util.AbstractMap;
 
-import javax.inject.Singleton;
-
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.cli.util.OutputCapture;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.modules.server.JMXServerModule;
 import org.apache.james.rrt.lib.MappingImpl;
 import org.apache.james.rrt.lib.Mappings;
 import org.apache.james.rrt.lib.MappingsImpl;
 import org.apache.james.utils.DataProbeImpl;
-import org.apache.james.utils.MailboxManagerDefinition;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import com.google.inject.Inject;
-import com.google.inject.multibindings.Multibinder;
-
 public class DataCommandsIntegrationTest {
 
-    public static final String DOMAIN_COM = "domain.com";
-    public static final String USER = "user";
-    public static final String MAIL_ADDRESS = USER + "@" + DOMAIN_COM;
+    public static final String DOMAIN = "domain.com";
+    public static final String USER = "chibenwa";
+    public static final String MAIL_ADDRESS = USER + "@" + DOMAIN;
     public static final String PASSWORD = "12345";
+    private OutputCapture outputCapture;
 
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
@@ -62,6 +57,7 @@ public class DataCommandsIntegrationTest {
             binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
         dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
+        outputCapture = new OutputCapture();
     }
 
     @After
@@ -71,23 +67,43 @@ public class DataCommandsIntegrationTest {
 
     @Test
     public void addDomainShouldWork() throws Exception {
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "ADDDOMAIN", DOMAIN_COM});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "ADDDOMAIN", DOMAIN});
 
-        assertThat(dataProbe.containsDomain(DOMAIN_COM)).isTrue();
+        assertThat(dataProbe.containsDomain(DOMAIN)).isTrue();
     }
 
     @Test
     public void removeDomainShouldWork() throws Exception {
-        dataProbe.addDomain(DOMAIN_COM);
+        dataProbe.addDomain(DOMAIN);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "REMOVEDOMAIN", DOMAIN});
+
+        assertThat(dataProbe.containsDomain(DOMAIN)).isFalse();
+    }
+
+    @Test
+    public void listDomainsShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN);
 
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "REMOVEDOMAIN", DOMAIN_COM});
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "listdomains"}, outputCapture.getPrintStream());
 
-        assertThat(dataProbe.containsDomain(DOMAIN_COM)).isFalse();
+        assertThat(outputCapture.getContent()).contains(DOMAIN);
+    }
+
+    @Test
+    public void containsDomainShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN);
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "containsdomain", DOMAIN},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce(DOMAIN + " exists");
     }
 
     @Test
     public void addUserShouldWork() throws Exception {
-        dataProbe.addDomain(DOMAIN_COM);
+        dataProbe.addDomain(DOMAIN);
 
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "ADDUSER", MAIL_ADDRESS, PASSWORD});
 
@@ -96,7 +112,7 @@ public class DataCommandsIntegrationTest {
 
     @Test
     public void removeUserShouldWork() throws Exception {
-        dataProbe.addDomain(DOMAIN_COM);
+        dataProbe.addDomain(DOMAIN);
         dataProbe.addUser(MAIL_ADDRESS, PASSWORD);
 
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "REMOVEUSER", MAIL_ADDRESS});
@@ -105,9 +121,20 @@ public class DataCommandsIntegrationTest {
     }
 
     @Test
+    public void listUsersShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN);
+        dataProbe.addUser(MAIL_ADDRESS, PASSWORD);
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "listusers"}, outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce(USER);
+    }
+
+    @Test
     public void addAddressMappingShouldWork() throws Exception {
         String redirectionAddress = "redirect@apache.org";
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN, redirectionAddress});
 
         assertThat(dataProbe.listMappings())
             .containsOnly(
@@ -119,11 +146,35 @@ public class DataCommandsIntegrationTest {
     }
 
     @Test
+    public void listMappingsShouldWork() throws Exception {
+        String redirectionAddress = "redirect@apache.org";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN, redirectionAddress});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "listmappings"},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("chibenwa@domain.com=redirect@apache.org");
+    }
+
+    @Test
+    public void listUsersDomainMappingShouldWork() throws Exception {
+        String redirectionAddress = "redirect@apache.org";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN, redirectionAddress});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "listuserdomainmappings", USER, DOMAIN},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("redirect@apache.org");
+    }
+
+    @Test
     public void removeAddressMappingShouldWork() throws Exception {
         String redirectionAddress = "redirect@apache.org";
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN, redirectionAddress});
 
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeaddressmapping", USER, DOMAIN, redirectionAddress});
 
         assertThat(dataProbe.listMappings())
             .isNull();
@@ -132,7 +183,7 @@ public class DataCommandsIntegrationTest {
     @Test
     public void addRegexMappingShouldWork() throws Exception {
         String regex = "regex";
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN_COM, regex});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN, regex});
 
         assertThat(dataProbe.listMappings())
             .containsOnly(
@@ -146,9 +197,9 @@ public class DataCommandsIntegrationTest {
     @Test
     public void removeRegexMappingShouldWork() throws Exception {
         String regex = "regex";
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN_COM, regex});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN, regex});
 
-        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeregexmapping", USER, DOMAIN_COM, regex});
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeregexmapping", USER, DOMAIN, regex});
 
         assertThat(dataProbe.listMappings())
             .isNull();

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
index 074a22a..9e131bb 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
@@ -22,40 +22,34 @@ package org.apache.james.cli;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
-import javax.inject.Singleton;
-
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.cli.util.OutputCapture;
 import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.store.quota.QuotaRootImpl;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.modules.server.JMXServerModule;
-import org.apache.james.utils.MailboxManagerDefinition;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import com.google.inject.Inject;
-import com.google.inject.multibindings.Multibinder;
-
 public class MailboxCommandsIntegrationTest {
     public static final String USER = "user";
-    public static final String MAILBOX = "mailbox";
+    public static final String MAILBOX = "mailboxExampleName";
 
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
     private GuiceJamesServer guiceJamesServer;
     private MailboxProbeImpl mailboxProbe;
+    private OutputCapture outputCapture;
 
     @Before
     public void setUp() throws Exception {
         guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
             binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
+        outputCapture = new OutputCapture();
         mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class);
     }
 
@@ -81,6 +75,17 @@ public class MailboxCommandsIntegrationTest {
     }
 
     @Test
+    public void listUserMailboxesShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "createmailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "listusermailboxes", USER},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce(MAILBOX);
+    }
+
+    @Test
     public void deleteMailboxeShouldWork() throws Exception {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "createmailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
index 517457d..551a5f0 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
@@ -22,36 +22,23 @@ package org.apache.james.cli;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
-import javax.inject.Singleton;
-
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.cli.util.OutputCapture;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.quota.QuotaRootImpl;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.modules.QuotaProbesImpl;
 import org.apache.james.modules.server.JMXServerModule;
-import org.apache.james.utils.MailboxManagerDefinition;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import com.google.inject.Inject;
-import com.google.inject.multibindings.Multibinder;
-
 public class QuotaCommandsIntegrationTest {
     public static final String USER = "user";
     public static final QuotaRoot QUOTA_ROOT = QuotaRootImpl.quotaRoot("#private&" + USER);
-
-    @Singleton
-    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
-        @Inject
-        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
-            super("memory-mailboxmanager", manager);
-        }
-    }
+    private OutputCapture outputCapture;
 
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
@@ -64,6 +51,7 @@ public class QuotaCommandsIntegrationTest {
             binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
         quotaProbe = guiceJamesServer.getProbe(QuotaProbesImpl.class);
+        outputCapture = new OutputCapture();
     }
 
     @After
@@ -79,6 +67,17 @@ public class QuotaCommandsIntegrationTest {
     }
 
     @Test
+    public void getDefaultMaxStorageShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxstoragequota", "36M"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getdefaultmaxstoragequota"},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Default Maximum Storage Quota: 36 MB");
+    }
+
+    @Test
     public void setDefaultMaxMessageCountShouldWork() throws Exception {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxmessagecountquota", "36"});
 
@@ -86,6 +85,17 @@ public class QuotaCommandsIntegrationTest {
     }
 
     @Test
+    public void getDefaultMaxMessageCountShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxmessagecountquota", "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getdefaultmaxmessagecountquota"},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Default Maximum message count Quota: 36");
+    }
+
+    @Test
     public void setMaxStorageShouldWork() throws Exception {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxstoragequota", QUOTA_ROOT.getValue(), "36"});
 
@@ -93,10 +103,53 @@ public class QuotaCommandsIntegrationTest {
     }
 
     @Test
+    public void getMaxStorageShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxstoragequota", QUOTA_ROOT.getValue(), "1g"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getmaxstoragequota", QUOTA_ROOT.getValue()},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Storage space allowed for Quota Root #private&user: 1 GB");
+    }
+
+    @Test
     public void setMaxMessageCountShouldWork() throws Exception {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxmessagecountquota", QUOTA_ROOT.getValue(), "36"});
 
         assertThat(quotaProbe.getMaxMessageCount(QUOTA_ROOT.getValue())).isEqualTo(36);
     }
 
+    @Test
+    public void getMaxMessageCountShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxmessagecountquota", QUOTA_ROOT.getValue(), "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getmaxmessagecountquota", QUOTA_ROOT.getValue()},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("MailboxMessage count allowed for Quota Root #private&user: 36");
+    }
+
+    @Test
+    public void getStorageQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxstoragequota", QUOTA_ROOT.getValue(), "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getstoragequota", QUOTA_ROOT.getValue()},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Storage quota for #private&user is: 0 bytes / 36 bytes");
+    }
+
+    @Test
+    public void getMessageCountQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxmessagecountquota", QUOTA_ROOT.getValue(), "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getmessagecountquota", QUOTA_ROOT.getValue()},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("MailboxMessage count quota for #private&user is: 0 / 36");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
index bc2fb30..4e086ab 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
@@ -22,17 +22,14 @@ package org.apache.james.cli;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
-import javax.inject.Singleton;
-
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.cli.util.OutputCapture;
 import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.modules.TestFilesystemModule;
 import org.apache.james.modules.protocols.SieveProbeImpl;
 import org.apache.james.modules.server.JMXServerModule;
 import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
-import org.apache.james.utils.MailboxManagerDefinition;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -40,9 +37,6 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 
-import com.google.inject.Inject;
-import com.google.inject.multibindings.Multibinder;
-
 public class SieveQuotaCommandsIntegrationTest {
     public static final String USER = "user";
 
@@ -54,6 +48,7 @@ public class SieveQuotaCommandsIntegrationTest {
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
     private GuiceJamesServer guiceJamesServer;
     private SieveProbeImpl sieveProbe;
+    private OutputCapture outputCapture;
 
     @Before
     public void setUp() throws Exception {
@@ -61,6 +56,7 @@ public class SieveQuotaCommandsIntegrationTest {
             binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)))
             .overrideWith(new TestFilesystemModule(temporaryFolder));
         guiceJamesServer.start();
+        outputCapture = new OutputCapture();
         sieveProbe = guiceJamesServer.getProbe(SieveProbeImpl.class);
     }
 
@@ -77,12 +73,33 @@ public class SieveQuotaCommandsIntegrationTest {
     }
 
     @Test
+    public void getSieveUserQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setsieveuserquota", USER, "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getsieveuserquota", USER},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Storage space allowed for user Sieve scripts: 36 bytes");
+    }
+
+    @Test
     public void setSieveQuotaShouldWork() throws Exception {
         ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setsievequota", "36"});
 
         assertThat(sieveProbe.getSieveQuota()).isEqualTo(36);
     }
 
+    @Test
+    public void getSieveQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setsievequota", "36"});
+
+        ServerCmd.executeAndOutputToStream(new String[] {"-h", "127.0.0.1", "-p", "9999", "getsievequota"},
+            outputCapture.getPrintStream());
+
+        assertThat(outputCapture.getContent())
+            .containsOnlyOnce("Storage space allowed for Sieve scripts by default: 36 bytes");
+    }
 
     @Test
     public void removeSieveUserQuotaShouldWork() throws Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCapture.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCapture.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCapture.java
new file mode 100644
index 0000000..20fef6a
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCapture.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import com.google.common.base.Charsets;
+
+public class OutputCapture {
+
+    private final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+    public PrintStream getPrintStream() {
+        return new PrintStream(byteArrayOutputStream);
+    }
+
+    public String getContent() {
+        return new String(byteArrayOutputStream.toByteArray(), Charsets.UTF_8);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCaptureTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCaptureTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCaptureTest.java
new file mode 100644
index 0000000..a76c2fb
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/util/OutputCaptureTest.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+
+public class OutputCaptureTest {
+
+    @Test
+    public void contentShouldBeEmptyByDefault() {
+        assertThat(new OutputCapture().getContent()).isEmpty();
+    }
+
+    @Test
+    public void contentShouldReturnOutputStreamInput() throws Exception {
+        OutputCapture outputCapture = new OutputCapture();
+
+        String message = "Hello world!\n";
+        outputCapture.getPrintStream().write(message.getBytes(Charsets.UTF_8));
+
+        assertThat(outputCapture.getContent()).isEqualTo(message);
+    }
+
+
+    @Test
+    public void mixingReadsAndWritesShouldWork() throws Exception {
+        OutputCapture outputCapture = new OutputCapture();
+        String message = "Hello world!\n";
+        outputCapture.getPrintStream().write(message.getBytes(Charsets.UTF_8));
+        outputCapture.getContent();
+
+        String additionalMessage = "Additional message!\n";
+        outputCapture.getPrintStream().write(additionalMessage.getBytes(Charsets.UTF_8));
+
+        assertThat(outputCapture.getContent()).isEqualTo(message + additionalMessage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/c994be04/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
index af882ed..edf86fa 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
@@ -102,6 +102,11 @@ public class ServerCmd {
     }
 
     public static void doMain(String[] args) throws Exception {
+        PrintStream printStream = System.out;
+        executeAndOutputToStream(args, printStream);
+    }
+
+    public static void executeAndOutputToStream(String[] args, PrintStream printStream) throws Exception {
         StopWatch stopWatch = new StopWatch();
         stopWatch.start();
         CommandLine cmd = parseCommandLine(args);
@@ -112,11 +117,11 @@ public class ServerCmd {
                 new JmxQuotaProbe().connect(jmxConnection),
                 new JmxSieveProbe().connect(jmxConnection)
             )
-            .executeCommandLine(cmd);
+            .executeCommandLine(cmd, printStream);
         stopWatch.split();
         print(new String[] { Joiner.on(' ')
                 .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")},
-            System.out);
+            printStream);
         stopWatch.stop();
     }
 
@@ -169,8 +174,8 @@ public class ServerCmd {
     }
 
     @VisibleForTesting
-    CmdType executeCommandLine(CommandLine cmd) throws Exception {
-        String[] arguments = cmd.getArgs();
+    private CmdType executeCommandLine(CommandLine commandLine, PrintStream printStream) throws Exception {
+        String[] arguments = commandLine.getArgs();
         String cmdName = arguments[0];
         CmdType cmdType = CmdType.lookup(cmdName);
         if (cmdType == null) {
@@ -179,11 +184,17 @@ public class ServerCmd {
         if (! cmdType.hasCorrectArguments(arguments.length)) {
             throw new InvalidArgumentNumberException(cmdType, arguments.length);
         }
-        executeCommand(arguments, cmdType);
+        executeCommand(arguments, cmdType, printStream);
         return cmdType;
     }
 
-    private void executeCommand(String[] arguments, CmdType cmdType) throws Exception {
+
+    @VisibleForTesting
+    CmdType executeCommandLine(CommandLine commandLine) throws Exception {
+        return executeCommandLine(commandLine, new PrintStream(System.out));
+    }
+
+    private void executeCommand(String[] arguments, CmdType cmdType, PrintStream printStream) throws Exception {
         switch (cmdType) {
         case ADDUSER:
             probe.addUser(arguments[1], arguments[2]);
@@ -192,7 +203,7 @@ public class ServerCmd {
             probe.removeUser(arguments[1]);
             break;
         case LISTUSERS:
-            print(probe.listUsers(), System.out);
+            print(probe.listUsers(), printStream);
             break;
         case ADDDOMAIN:
             probe.addDomain(arguments[1]);
@@ -202,20 +213,20 @@ public class ServerCmd {
             break;
         case CONTAINSDOMAIN:
             if (probe.containsDomain(arguments[1])) {
-                System.out.println(arguments[1] + " exists");
+                printStream.println(arguments[1] + " exists");
             } else {
-                System.out.println(arguments[1] + " does not exists");
+                printStream.println(arguments[1] + " does not exists");
             }
             break;
         case LISTDOMAINS:
-            print(probe.listDomains(), System.out);
+            print(probe.listDomains(), printStream);
             break;
         case LISTMAPPINGS:
-            print(probe.listMappings(), System.out);
+            print(probe.listMappings(), printStream);
             break;
         case LISTUSERDOMAINMAPPINGS:
             Mappings userDomainMappings = probe.listUserDomainMappings(arguments[1], arguments[2]);
-            print(userDomainMappings.asStrings(), System.out);
+            print(userDomainMappings.asStrings(), printStream);
             break;
         case ADDADDRESSMAPPING:
             probe.addAddressMapping(arguments[1], arguments[2], arguments[3]);
@@ -243,28 +254,28 @@ public class ServerCmd {
             break;
         case LISTUSERMAILBOXES:
             Collection<String> mailboxes = mailboxProbe.listUserMailboxes(arguments[1]);
-            print(mailboxes.toArray(new String[0]), System.out);
+            print(mailboxes.toArray(new String[0]), printStream);
             break;
         case DELETEMAILBOX:
             mailboxProbe.deleteMailbox(arguments[1], arguments[2], arguments[3]);
             break;
         case GETSTORAGEQUOTA:
-            printStorageQuota(arguments[1], quotaProbe.getStorageQuota(arguments[1]));
+            printStorageQuota(arguments[1], quotaProbe.getStorageQuota(arguments[1]), printStream);
             break;
         case GETMESSAGECOUNTQUOTA:
-            printMessageQuota(arguments[1], quotaProbe.getMessageCountQuota(arguments[1]));
+            printMessageQuota(arguments[1], quotaProbe.getMessageCountQuota(arguments[1]), printStream);
             break;
         case GETQUOTAROOT:
-            System.out.println("Quota Root : " + quotaProbe.getQuotaRoot(arguments[1], arguments[2], arguments[3]));
+            printStream.println("Quota Root : " + quotaProbe.getQuotaRoot(arguments[1], arguments[2], arguments[3]));
             break;
         case GETMAXSTORAGEQUOTA:
-            System.out.println("Storage space allowed for Quota Root "
+            printStream.println("Storage space allowed for Quota Root "
                 + arguments[1]
                 + " : "
                 + formatStorageValue(quotaProbe.getMaxStorage(arguments[1])));
             break;
         case GETMAXMESSAGECOUNTQUOTA:
-            System.out.println("MailboxMessage count allowed for Quota Root " + arguments[1] + " : " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1])));
+            printStream.println("MailboxMessage count allowed for Quota Root " + arguments[1] + " : " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1])));
             break;
         case SETMAXSTORAGEQUOTA:
             quotaProbe.setMaxStorage(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue());
@@ -279,10 +290,10 @@ public class ServerCmd {
             quotaProbe.setDefaultMaxMessageCount(Long.parseLong(arguments[1]));
             break;
         case GETDEFAULTMAXSTORAGEQUOTA:
-            System.out.println("Default Maximum Storage Quota : " + formatStorageValue(quotaProbe.getDefaultMaxStorage()));
+            printStream.println("Default Maximum Storage Quota : " + formatStorageValue(quotaProbe.getDefaultMaxStorage()));
             break;
         case GETDEFAULTMAXMESSAGECOUNTQUOTA:
-            System.out.println("Default Maximum message count Quota : " + formatMessageValue(quotaProbe.getDefaultMaxMessageCount()));
+            printStream.println("Default Maximum message count Quota : " + formatMessageValue(quotaProbe.getDefaultMaxMessageCount()));
             break;
         case REINDEXMAILBOX:
             mailboxProbe.reIndexMailbox(arguments[1], arguments[2], arguments[3]);
@@ -297,11 +308,11 @@ public class ServerCmd {
             sieveProbe.setSieveQuota(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue());
             break;
         case GETSIEVEQUOTA:
-            System.out.println("Storage space allowed for Sieve scripts by default : "
+            printStream.println("Storage space allowed for Sieve scripts by default : "
                 + formatStorageValue(sieveProbe.getSieveQuota()));
             break;
         case GETSIEVEUSERQUOTA:
-            System.out.println("Storage space allowed for "
+            printStream.println("Storage space allowed for "
                 + arguments[1]
                 + " Sieve scripts : "
                 + formatStorageValue(sieveProbe.getSieveQuota(arguments[1])));
@@ -327,15 +338,15 @@ public class ServerCmd {
         }
     }
 
-    private void printStorageQuota(String quotaRootString, SerializableQuota quota) {
-        System.out.println(String.format("Storage quota for %s is : %s / %s",
+    private void printStorageQuota(String quotaRootString, SerializableQuota quota, PrintStream printStream) {
+        printStream.println(String.format("Storage quota for %s is : %s / %s",
             quotaRootString,
             formatStorageValue(quota.getUsed()),
             formatStorageValue(quota.getMax())));
     }
 
-    private void printMessageQuota(String quotaRootString, SerializableQuota quota) {
-        System.out.println(String.format("MailboxMessage count quota for %s is : %s / %s",
+    private void printMessageQuota(String quotaRootString, SerializableQuota quota, PrintStream printStream) {
+        printStream.println(String.format("MailboxMessage count quota for %s is : %s / %s",
             quotaRootString,
             formatMessageValue(quota.getUsed()),
             formatMessageValue(quota.getMax())));


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


[08/15] james-project git commit: JAMES-1982 Provides default values for JMX & unbound sockets

Posted by bt...@apache.org.
JAMES-1982 Provides default values for JMX & unbound sockets


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

Branch: refs/heads/master
Commit: 4321bcc58781d57e065da8ea87617bcf2e123160
Parents: f41a3cf
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 10:19:00 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 server/container/guice/jmx/pom.xml                   |  4 ++++
 .../org/apache/james/modules/server/JMXServer.java   | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4321bcc5/server/container/guice/jmx/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/pom.xml b/server/container/guice/jmx/pom.xml
index 397d0bb..abf5f41 100644
--- a/server/container/guice/jmx/pom.xml
+++ b/server/container/guice/jmx/pom.xml
@@ -190,6 +190,10 @@
                     <artifactId>guice-multibindings</artifactId>
                 </dependency>
                 <dependency>
+                    <groupId>com.github.fge</groupId>
+                    <artifactId>throwing-lambdas</artifactId>
+                </dependency>
+                <dependency>
                     <groupId>org.slf4j</groupId>
                     <artifactId>slf4j-api</artifactId>
                 </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4321bcc5/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
index 4b4e63d..5078629 100644
--- a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
+++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServer.java
@@ -19,8 +19,8 @@
 
 package org.apache.james.modules.server;
 
-import java.io.IOException;
 import java.lang.management.ManagementFactory;
+import java.net.ServerSocket;
 import java.rmi.registry.LocateRegistry;
 import java.util.HashSet;
 import java.util.Map;
@@ -38,6 +38,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.util.RestrictingRMISocketFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 
@@ -48,6 +49,7 @@ public class JMXServer {
     private final Object lock;
     private JMXConnectorServer jmxConnectorServer;
     private boolean isStarted;
+    private RestrictingRMISocketFactory restrictingRMISocketFactory;
 
     @Inject
     public JMXServer(FileSystem fileSystem) {
@@ -88,10 +90,10 @@ public class JMXServer {
     private void doStart() {
         try {
             PropertiesConfiguration configuration = new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties"));
-            String address = configuration.getString("jmx.address");
-            int port = configuration.getInt("jmx.port");
+            String address = configuration.getString("jmx.address", "localhost");
+            int port = configuration.getInt("jmx.port", 9999);
             String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi";
-            RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address);
+            restrictingRMISocketFactory = new RestrictingRMISocketFactory(address);
             LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory);
 
             Map<String, ?> environment = ImmutableMap.of();
@@ -117,7 +119,10 @@ public class JMXServer {
             });
             registeredKeys.clear();
             jmxConnectorServer.stop();
-        } catch (IOException e) {
+            restrictingRMISocketFactory.getSockets()
+                .forEach(Throwing.consumer(ServerSocket::close)
+                    .sneakyThrow());
+        } catch (Exception e) {
             throw Throwables.propagate(e);
         }
     }


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


[03/15] james-project git commit: JAMES-1982 Add integration test for some CLI commands

Posted by bt...@apache.org.
JAMES-1982 Add integration test for some CLI commands


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

Branch: refs/heads/master
Commit: b052f86a7a1919f2eabcae7c687e024b431b9522
Parents: 8942eaf
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 12:11:14 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 server/container/cli-integration/pom.xml        | 237 +++++++++++++++++++
 .../james/cli/DataCommandsIntegrationTest.java  | 168 +++++++++++++
 .../cli/MailboxCommandsIntegrationTest.java     | 102 ++++++++
 .../james/cli/QuotaCommandsIntegrationTest.java | 105 ++++++++
 .../cli/SieveQuotaCommandsIntegrationTest.java  | 118 +++++++++
 .../src/test/resources/conf/jmx.properties      |  22 ++
 .../src/test/resources/dnsservice.xml           |  29 +++
 .../src/test/resources/imapserver.xml           |  54 +++++
 .../src/test/resources/jmap.properties          |  11 +
 .../src/test/resources/jwt_publickey            |   9 +
 .../src/test/resources/lmtpserver.xml           |  41 ++++
 .../src/test/resources/logback-test.xml         |  15 ++
 .../src/test/resources/mailetcontainer.xml      | 105 ++++++++
 .../src/test/resources/mailrepositorystore.xml  |  31 +++
 .../src/test/resources/managesieveserver.xml    |  65 +++++
 .../src/test/resources/pop3server.xml           |  42 ++++
 .../src/test/resources/smtpserver.xml           | 105 ++++++++
 .../org/apache/james/MemoryJmapTestRule.java    |  13 +-
 .../james/util/RestrictingRMISocketFactory.java |   8 +
 server/pom.xml                                  |   1 +
 20 files changed, 1276 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/pom.xml b/server/container/cli-integration/pom.xml
new file mode 100644
index 0000000..dbe8f0a
--- /dev/null
+++ b/server/container/cli-integration/pom.xml
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>james-server</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.0.0-beta6-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>james-server-cli-integration</artifactId>
+    <name>Apache James :: Server :: Cli :: Integretion</name>
+
+    <profiles>
+        <profile>
+            <id>disable-build-for-older-jdk</id>
+            <activation>
+                <jdk>(,1.8)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-jar-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>jar</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>test-jar</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-compile</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testCompile</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-test</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-source-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-sources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-install-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-install</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>default-resources</id>
+                                <phase>none</phase>
+                            </execution>
+                            <execution>
+                                <id>default-testResources</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-site-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>attach-descriptor</id>
+                                <phase>none</phase>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>build-for-jdk-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-cli</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-common</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
+                    <artifactId>james-server-guice-jmap</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-memory-guice</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
+                    <artifactId>james-server-memory-guice</artifactId>
+                    <scope>test</scope>
+                </dependency>
+
+                <dependency>
+                    <groupId>com.github.fge</groupId>
+                    <artifactId>throwing-lambdas</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.mockito</groupId>
+                    <artifactId>mockito-core</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.assertj</groupId>
+                    <artifactId>assertj-core</artifactId>
+                    <version>${assertj-3.version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-simple</artifactId>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-compiler-plugin</artifactId>
+                        <configuration>
+                            <source>1.8</source>
+                            <target>1.8</target>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>animal-sniffer-java-8</id>
+            <activation>
+                <jdk>[1.8,)</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>animal-sniffer-maven-plugin</artifactId>
+                        <configuration>
+                            <signature>
+                                <groupId>org.codehaus.mojo.signature</groupId>
+                                <artifactId>java18</artifactId>
+                                <version>1.0</version>
+                            </signature>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>check_java_8</id>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>check</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
new file mode 100644
index 0000000..d1e4ee9
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
@@ -0,0 +1,168 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.util.AbstractMap;
+
+import javax.inject.Singleton;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.modules.server.JMXServerModule;
+import org.apache.james.rrt.lib.MappingImpl;
+import org.apache.james.rrt.lib.Mappings;
+import org.apache.james.rrt.lib.MappingsImpl;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.MailboxManagerDefinition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+
+public class DataCommandsIntegrationTest {
+
+    public static final String DOMAIN_COM = "domain.com";
+    public static final String USER = "user";
+    public static final String MAIL_ADDRESS = USER + "@" + DOMAIN_COM;
+    public static final String PASSWORD = "12345";
+
+    @Singleton
+    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
+        @Inject
+        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
+            super("memory-mailboxmanager", manager);
+        }
+    }
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    private GuiceJamesServer guiceJamesServer;
+    private DataProbeImpl dataProbe;
+
+    @Before
+    public void setUp() throws Exception {
+        guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
+            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
+                .addBinding()
+                .to(MemoryMailboxManagerDefinition.class));
+        guiceJamesServer.start();
+        dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    @Test
+    public void addDomainShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "ADDDOMAIN", DOMAIN_COM});
+
+        assertThat(dataProbe.containsDomain(DOMAIN_COM)).isTrue();
+    }
+
+    @Test
+    public void removeDomainShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN_COM);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "REMOVEDOMAIN", DOMAIN_COM});
+
+        assertThat(dataProbe.containsDomain(DOMAIN_COM)).isFalse();
+    }
+
+    @Test
+    public void addUserShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN_COM);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "ADDUSER", MAIL_ADDRESS, PASSWORD});
+
+        assertThat(dataProbe.listUsers()).contains(MAIL_ADDRESS);
+    }
+
+    @Test
+    public void removeUserShouldWork() throws Exception {
+        dataProbe.addDomain(DOMAIN_COM);
+        dataProbe.addUser(MAIL_ADDRESS, PASSWORD);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "REMOVEUSER", MAIL_ADDRESS});
+
+        assertThat(dataProbe.listUsers()).doesNotContain(MAIL_ADDRESS);
+    }
+
+    @Test
+    public void addAddressMappingShouldWork() throws Exception {
+        String redirectionAddress = "redirect@apache.org";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+
+        assertThat(dataProbe.listMappings())
+            .containsOnly(
+                new AbstractMap.SimpleEntry<String, Mappings>(
+                    MAIL_ADDRESS,
+                    MappingsImpl.builder()
+                        .add(MappingImpl.address(redirectionAddress))
+                        .build()));
+    }
+
+    @Test
+    public void removeAddressMappingShouldWork() throws Exception {
+        String redirectionAddress = "redirect@apache.org";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeaddressmapping", USER, DOMAIN_COM, redirectionAddress});
+
+        assertThat(dataProbe.listMappings())
+            .isNull();
+    }
+
+    @Test
+    public void addRegexMappingShouldWork() throws Exception {
+        String regex = "regex";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN_COM, regex});
+
+        assertThat(dataProbe.listMappings())
+            .containsOnly(
+                new AbstractMap.SimpleEntry<String, Mappings>(
+                    MAIL_ADDRESS,
+                    MappingsImpl.builder()
+                        .add(MappingImpl.regex(regex))
+                        .build()));
+    }
+
+    @Test
+    public void removeRegexMappingShouldWork() throws Exception {
+        String regex = "regex";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "addregexmapping", USER, DOMAIN_COM, regex});
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removeregexmapping", USER, DOMAIN_COM, regex});
+
+        assertThat(dataProbe.listMappings())
+            .isNull();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
new file mode 100644
index 0000000..4aabb44
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
@@ -0,0 +1,102 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import javax.inject.Singleton;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.store.quota.QuotaRootImpl;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.modules.MailboxProbeImpl;
+import org.apache.james.modules.server.JMXServerModule;
+import org.apache.james.utils.MailboxManagerDefinition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+
+public class MailboxCommandsIntegrationTest {
+    public static final String USER = "user";
+    public static final String MAILBOX = "mailbox";
+
+    @Singleton
+    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
+        @Inject
+        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
+            super("memory-mailboxmanager", manager);
+        }
+    }
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    private GuiceJamesServer guiceJamesServer;
+    private MailboxProbeImpl mailboxProbe;
+
+    @Before
+    public void setUp() throws Exception {
+        guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
+            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
+                .addBinding()
+                .to(MemoryMailboxManagerDefinition.class));
+        guiceJamesServer.start();
+        mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class);
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    @Test
+    public void createMailboxShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "createmailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
+
+        assertThat(mailboxProbe.listUserMailboxes(USER)).containsOnly(MAILBOX);
+    }
+
+    @Test
+    public void deleteUserMailboxesShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "createmailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "deleteusermailboxes", USER});
+
+        assertThat(mailboxProbe.listUserMailboxes(USER)).isEmpty();
+    }
+
+    @Test
+    public void deleteMailboxeShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "createmailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "deletemailbox", MailboxConstants.USER_NAMESPACE, USER, MAILBOX});
+
+        assertThat(mailboxProbe.listUserMailboxes(USER)).isEmpty();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
new file mode 100644
index 0000000..b20dd87
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
@@ -0,0 +1,105 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import javax.inject.Singleton;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.store.quota.QuotaRootImpl;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.modules.QuotaProbesImpl;
+import org.apache.james.modules.server.JMXServerModule;
+import org.apache.james.utils.MailboxManagerDefinition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+
+public class QuotaCommandsIntegrationTest {
+    public static final String USER = "user";
+    public static final QuotaRoot QUOTA_ROOT = QuotaRootImpl.quotaRoot("#private&" + USER);
+
+    @Singleton
+    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
+        @Inject
+        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
+            super("memory-mailboxmanager", manager);
+        }
+    }
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    private GuiceJamesServer guiceJamesServer;
+    private QuotaProbesImpl quotaProbe;
+
+    @Before
+    public void setUp() throws Exception {
+        guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
+            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
+                .addBinding()
+                .to(MemoryMailboxManagerDefinition.class));
+        guiceJamesServer.start();
+        quotaProbe = guiceJamesServer.getProbe(QuotaProbesImpl.class);
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    @Test
+    public void setDefaultMaxStorageShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxstoragequota", "36"});
+
+        assertThat(quotaProbe.getDefaultMaxStorage()).isEqualTo(36);
+    }
+
+    @Test
+    public void setDefaultMaxMessageCountShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setdefaultmaxmessagecountquota", "36"});
+
+        assertThat(quotaProbe.getDefaultMaxMessageCount()).isEqualTo(36);
+    }
+
+    @Test
+    public void setMaxStorageShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxstoragequota", QUOTA_ROOT.getValue(), "36"});
+
+        assertThat(quotaProbe.getMaxStorage(QUOTA_ROOT.getValue())).isEqualTo(36);
+    }
+
+    @Test
+    public void setMaxMessageCountShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setmaxmessagecountquota", QUOTA_ROOT.getValue(), "36"});
+
+        assertThat(quotaProbe.getMaxMessageCount(QUOTA_ROOT.getValue())).isEqualTo(36);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
new file mode 100644
index 0000000..3cf3a1b
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import javax.inject.Singleton;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.modules.TestFilesystemModule;
+import org.apache.james.modules.protocols.SieveProbeImpl;
+import org.apache.james.modules.server.JMXServerModule;
+import org.apache.james.sieverepository.api.exception.QuotaNotFoundException;
+import org.apache.james.utils.MailboxManagerDefinition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+
+import com.google.inject.Inject;
+import com.google.inject.multibindings.Multibinder;
+
+public class SieveQuotaCommandsIntegrationTest {
+    public static final String USER = "user";
+
+    @Singleton
+    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
+        @Inject
+        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
+            super("memory-mailboxmanager", manager);
+        }
+    }
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private GuiceJamesServer guiceJamesServer;
+    private SieveProbeImpl sieveProbe;
+
+    @Before
+    public void setUp() throws Exception {
+        guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
+            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
+                .addBinding()
+                .to(MemoryMailboxManagerDefinition.class))
+            .overrideWith(new TestFilesystemModule(temporaryFolder));
+        guiceJamesServer.start();
+        sieveProbe = guiceJamesServer.getProbe(SieveProbeImpl.class);
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    @Test
+    public void setSieveUserQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setsieveuserquota", USER, "36"});
+
+        assertThat(sieveProbe.getSieveQuota(USER)).isEqualTo(36);
+    }
+
+    @Test
+    public void setSieveQuotaShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "setsievequota", "36"});
+
+        assertThat(sieveProbe.getSieveQuota()).isEqualTo(36);
+    }
+
+
+    @Test
+    public void removeSieveUserQuotaShouldWork() throws Exception {
+        sieveProbe.setSieveQuota(USER, 36);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removesieveuserquota", USER});
+
+        expectedException.expect(QuotaNotFoundException.class);
+        sieveProbe.getSieveQuota(USER);
+    }
+
+    @Test
+    public void removeSieveQuotaShouldWork() throws Exception {
+        sieveProbe.setSieveQuota(36);
+
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "removesievequota"});
+
+        expectedException.expect(QuotaNotFoundException.class);
+        sieveProbe.getSieveQuota();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/conf/jmx.properties
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/conf/jmx.properties b/server/container/cli-integration/src/test/resources/conf/jmx.properties
new file mode 100644
index 0000000..0437d95
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/conf/jmx.properties
@@ -0,0 +1,22 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+# See http://james.apache.org/server/3/config.html for usage
+
+jmx.address=127.0.0.1
+jmx.port=9999

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/dnsservice.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/dnsservice.xml b/server/container/cli-integration/src/test/resources/dnsservice.xml
new file mode 100644
index 0000000..0978a00
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/dnsservice.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one   
+  or more contributor license agreements.  See the NOTICE file 
+  distributed with this work for additional information        
+  regarding copyright ownership.  The ASF licenses this file   
+  to you under the Apache License, Version 2.0 (the            
+  "License"); you may not use this file except in compliance   
+  with the License.  You may obtain a copy of the License at   
+                                                               
+    http://www.apache.org/licenses/LICENSE-2.0                 
+                                                               
+  Unless required by applicable law or agreed to in writing,   
+  software distributed under the License is distributed on an  
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       
+  KIND, either express or implied.  See the License for the    
+  specific language governing permissions and limitations      
+  under the License.                                           
+ -->
+
+<dnsservice>
+  <servers>
+    <server>8.8.8.8</server>
+    <server>62.210.16.6</server>
+  </servers>
+  <autodiscover>false</autodiscover>
+  <authoritative>false</authoritative>
+  <maxcachesize>50000</maxcachesize>
+</dnsservice>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/imapserver.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/imapserver.xml b/server/container/cli-integration/src/test/resources/imapserver.xml
new file mode 100644
index 0000000..ff478a9
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/imapserver.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+
+<imapservers>
+	<imapserver enabled="true">
+		<jmxName>imapserver</jmxName>
+		<bind>0.0.0.0:1143</bind>
+		<connectionBacklog>200</connectionBacklog>
+		<tls socketTLS="false" startTLS="false">
+			<!-- To create a new keystore execute:
+            keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
+              -->
+			<keystore>file://conf/keystore</keystore>
+			<secret>james72laBalle</secret>
+			<provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+		</tls>
+		<connectionLimit>0</connectionLimit>
+		<connectionLimitPerIP>0</connectionLimitPerIP>
+	</imapserver>
+	<imapserver enabled="true">
+		<jmxName>imapserver-ssl</jmxName>
+		<bind>0.0.0.0:1993</bind>
+		<connectionBacklog>200</connectionBacklog>
+		<tls socketTLS="false" startTLS="false">
+			<!-- To create a new keystore execute:
+              keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
+             -->
+			<keystore>file://conf/keystore</keystore>
+			<secret>james72laBalle</secret>
+			<provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+		</tls>
+		<connectionLimit>0</connectionLimit>
+		<connectionLimitPerIP>0</connectionLimitPerIP>
+	</imapserver>
+</imapservers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/jmap.properties
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/jmap.properties b/server/container/cli-integration/src/test/resources/jmap.properties
new file mode 100644
index 0000000..34ab451
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/jmap.properties
@@ -0,0 +1,11 @@
+# Configuration file for JMAP
+
+tls.keystoreURL=file://conf/keystore
+tls.secret=james72laBalle
+
+#
+# If you wish to use OAuth authentication, you should provide a valid JWT public key.
+# The following entry specify the link to the URL of the public key file,
+# which should be a PEM format file.
+#
+jwt.publickeypem.url=file://conf/jwt_publickey

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/jwt_publickey
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/jwt_publickey b/server/container/cli-integration/src/test/resources/jwt_publickey
new file mode 100644
index 0000000..53914e0
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/jwt_publickey
@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtlChO/nlVP27MpdkG0Bh
+16XrMRf6M4NeyGa7j5+1UKm42IKUf3lM28oe82MqIIRyvskPc11NuzSor8HmvH8H
+lhDs5DyJtx2qp35AT0zCqfwlaDnlDc/QDlZv1CoRZGpQk1Inyh6SbZwYpxxwh0fi
++d/4RpE3LBVo8wgOaXPylOlHxsDizfkL8QwXItyakBfMO6jWQRrj7/9WDhGf4Hi+
+GQur1tPGZDl9mvCoRHjFrD5M/yypIPlfMGWFVEvV5jClNMLAQ9bYFuOc7H1fEWw6
+U1LZUUbJW9/CH45YXz82CYqkrfbnQxqRb2iVbVjs/sHopHd1NTiCfUtwvcYJiBVj
+kwIDAQAB
+-----END PUBLIC KEY-----

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/lmtpserver.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/lmtpserver.xml b/server/container/cli-integration/src/test/resources/lmtpserver.xml
new file mode 100644
index 0000000..5c4a9c7
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/lmtpserver.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one   
+  or more contributor license agreements.  See the NOTICE file 
+  distributed with this work for additional information        
+  regarding copyright ownership.  The ASF licenses this file   
+  to you under the Apache License, Version 2.0 (the            
+  "License"); you may not use this file except in compliance   
+  with the License.  You may obtain a copy of the License at   
+                                                               
+    http://www.apache.org/licenses/LICENSE-2.0                 
+                                                               
+  Unless required by applicable law or agreed to in writing,   
+  software distributed under the License is distributed on an  
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       
+  KIND, either express or implied.  See the License for the    
+  specific language governing permissions and limitations      
+  under the License.                                           
+ -->
+
+<lmtpservers>
+
+    <lmtpserver enabled="true">
+        <jmxName>lmtpserver</jmxName>
+        <!-- LMTP should not be reachable from outside your network so bind it to loopback-->
+        <bind>127.0.0.1:1024</bind>
+        <connectionBacklog>200</connectionBacklog>
+        <connectiontimeout>1200</connectiontimeout>
+        <!-- Set the maximum simultaneous incoming connections for this service -->
+        <connectionLimit>0</connectionLimit>
+        <!-- Set the maximum simultaneous incoming connections per IP for this service -->
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <!--  This sets the maximum allowed message size (in kilobytes) for this -->
+        <!--  LMTP service. If unspecified, the value defaults to 0, which means no limit. -->
+        <maxmessagesize>0</maxmessagesize>
+        <handlerchain>
+            <handler class="org.apache.james.lmtpserver.CoreCmdHandlerLoader"/>
+        </handlerchain>
+    </lmtpserver>
+
+</lmtpservers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/logback-test.xml b/server/container/cli-integration/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..6f13ac9
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/logback-test.xml
@@ -0,0 +1,15 @@
+<configuration>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%date %-5level [%thread] - [%logger]- %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <root level="WARN">
+        <appender-ref ref="STDOUT" />
+    </root>
+
+    <logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
+
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/mailetcontainer.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/mailetcontainer.xml b/server/container/cli-integration/src/test/resources/mailetcontainer.xml
new file mode 100644
index 0000000..28bdcee
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/mailetcontainer.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+ -->
+
+<mailetcontainer enableJmx="false">
+
+    <context>
+        <postmaster>postmaster@james.minet.net</postmaster>
+    </context>
+
+    <spooler>
+        <threads>20</threads>
+    </spooler>
+
+    <processors>
+        <processor state="root" enableJmx="false">
+            <mailet match="All" class="PostmasterAlias"/>
+            <mailet match="RelayLimit=30" class="Null"/>
+            <!-- Hook on sievemanager@james.linagora.com
+                 Mail send to this address will get interpreted with SIEVE Manage -->
+            <mailet match="All" class="ToProcessor">
+                <processor>transport</processor>
+            </mailet>
+        </processor>
+
+        <processor state="error" enableJmx="false">
+            <mailet match="All" class="Bounce"/>
+        </processor>
+
+
+        <processor state="transport" enableJmx="false">
+            <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
+                <name>X-UserIsAuth</name>
+                <value>true</value>
+            </mailet>
+            <mailet match="All" class="RemoveMimeHeader">
+                <name>bcc</name>
+            </mailet>
+            <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/>
+            <mailet match="RecipientIsLocal" class="Sieve"/>
+            <mailet match="RecipientIsLocal" class="LocalDelivery"/>
+            <mailet match="HostIsLocal" class="ToProcessor">
+                <processor>local-address-error</processor>
+                <notice>550 - Requested action not taken: no such user here</notice>
+            </mailet>
+            <mailet match="SMTPAuthSuccessful" class="RemoteDelivery">
+                <outgoingQueue>outgoing</outgoingQueue>
+                <delayTime>5000, 100000, 500000</delayTime>
+                <maxRetries>25</maxRetries>
+                <maxDnsProblemRetries>0</maxDnsProblemRetries>
+                <deliveryThreads>10</deliveryThreads>
+                <sendpartial>true</sendpartial>
+                <bounceProcessor>bounces</bounceProcessor>
+            </mailet>
+            <mailet match="All" class="ToProcessor">
+                <processor>relay-denied</processor>
+            </mailet>
+        </processor>
+
+        <processor state="spam" enableJmx="false">
+            <mailet match="All" class="ToRepository">
+                <repositoryPath>file://var/mail/spam/</repositoryPath>
+            </mailet>
+        </processor>
+
+        <processor state="local-address-error" enableJmx="false">
+            <mailet match="All" class="Bounce">
+                <attachment>none</attachment>
+            </mailet>
+        </processor>
+
+        <processor state="relay-denied" enableJmx="false">
+            <mailet match="All" class="Bounce">
+                <attachment>none</attachment>
+            </mailet>
+        </processor>
+
+        <processor state="bounces" enableJmx="false">
+            <mailet match="All" class="DSNBounce">
+                <passThrough>false</passThrough>
+            </mailet>
+        </processor>
+
+    </processors>
+
+</mailetcontainer>
+
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/mailrepositorystore.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/mailrepositorystore.xml b/server/container/cli-integration/src/test/resources/mailrepositorystore.xml
new file mode 100644
index 0000000..3ca4a1d
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/mailrepositorystore.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+ -->
+
+<mailrepositorystore>
+    <mailrepositories>
+        <mailrepository class="org.apache.james.mailrepository.file.FileMailRepository">
+            <protocols>
+                <protocol>file</protocol>
+            </protocols>
+            <config FIFO="false" CACHEKEYS="true"/>
+        </mailrepository>
+    </mailrepositories>
+</mailrepositorystore>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/managesieveserver.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/managesieveserver.xml b/server/container/cli-integration/src/test/resources/managesieveserver.xml
new file mode 100644
index 0000000..ec57e09
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/managesieveserver.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one   
+  or more contributor license agreements.  See the NOTICE file 
+  distributed with this work for additional information        
+  regarding copyright ownership.  The ASF licenses this file   
+  to you under the Apache License, Version 2.0 (the            
+  "License"); you may not use this file except in compliance   
+  with the License.  You may obtain a copy of the License at   
+                                                               
+    http://www.apache.org/licenses/LICENSE-2.0                 
+                                                               
+  Unless required by applicable law or agreed to in writing,   
+  software distributed under the License is distributed on an  
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       
+  KIND, either express or implied.  See the License for the    
+  specific language governing permissions and limitations      
+  under the License.                                           
+ -->
+ 
+<!--
+   This template file can be used as example for James Server configuration
+   DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS
+-->
+ 
+<!-- See http://james.apache.org/server/3/config.html for usage -->
+
+<managesieveservers>
+
+   <managesieveserver enabled="true">
+
+     <jmxName>managesieveserver</jmxName>
+
+     <bind>0.0.0.0:4190</bind>
+
+     <connectionBacklog>200</connectionBacklog>
+
+     <tls socketTLS="false" startTLS="false">
+       <!-- To create a new keystore execute:
+        keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
+         -->
+       <keystore>file://conf/keystore</keystore>
+       <secret>james72laBalle</secret>
+       <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+       <!-- The algorithm is optional and only needs to be specified when using something other
+        than the Sun JCE provider - You could use IbmX509 with IBM Java runtime. -->
+       <algorithm>SunX509</algorithm>
+     </tls>
+         
+        <!-- connection timeout in secconds -->
+        <connectiontimeout>360</connectiontimeout>
+
+        <!-- Set the maximum simultaneous incoming connections for this service -->
+        <connectionLimit>0</connectionLimit>
+         
+        <!-- Set the maximum simultaneous incoming connections per IP for this service -->
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <maxmessagesize>0</maxmessagesize>
+        <addressBracketsEnforcement>true</addressBracketsEnforcement>
+  
+   </managesieveserver>
+
+</managesieveservers>
+
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/pop3server.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/pop3server.xml b/server/container/cli-integration/src/test/resources/pop3server.xml
new file mode 100644
index 0000000..e4187da
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/pop3server.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one   
+  or more contributor license agreements.  See the NOTICE file 
+  distributed with this work for additional information        
+  regarding copyright ownership.  The ASF licenses this file   
+  to you under the Apache License, Version 2.0 (the            
+  "License"); you may not use this file except in compliance   
+  with the License.  You may obtain a copy of the License at   
+                                                               
+    http://www.apache.org/licenses/LICENSE-2.0                 
+                                                               
+  Unless required by applicable law or agreed to in writing,   
+  software distributed under the License is distributed on an  
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       
+  KIND, either express or implied.  See the License for the    
+  specific language governing permissions and limitations      
+  under the License.                                           
+ -->
+
+
+<pop3servers>
+    <pop3server enabled="true">
+        <jmxName>pop3server</jmxName>
+        <bind>0.0.0.0:1110</bind>
+        <connectionBacklog>200</connectionBacklog>
+        <tls socketTLS="false" startTLS="false">
+            <!-- To create a new keystore execute:
+                  keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore
+             -->
+            <keystore>file://conf/keystore</keystore>
+            <secret>james72laBalle</secret>
+            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+        </tls>
+        <connectiontimeout>1200</connectiontimeout>
+        <connectionLimit>0</connectionLimit>
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <handlerchain>
+            <handler class="org.apache.james.pop3server.core.CoreCmdHandlerLoader"/>
+        </handlerchain>
+    </pop3server>
+</pop3servers>

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/cli-integration/src/test/resources/smtpserver.xml
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/resources/smtpserver.xml b/server/container/cli-integration/src/test/resources/smtpserver.xml
new file mode 100644
index 0000000..a3d4b8f
--- /dev/null
+++ b/server/container/cli-integration/src/test/resources/smtpserver.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+ -->
+
+<smtpservers>
+    <smtpserver enabled="true">
+        <jmxName>smtpserver-global</jmxName>
+        <bind>0.0.0.0:1025</bind>
+        <connectionBacklog>200</connectionBacklog>
+        <tls socketTLS="false" startTLS="false">
+            <keystore>file://conf/keystore</keystore>
+            <secret>james72laBalle</secret>
+            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+            <algorithm>SunX509</algorithm>
+        </tls>
+        <connectiontimeout>360</connectiontimeout>
+        <connectionLimit>0</connectionLimit>
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <authRequired>false</authRequired>
+        <authorizedAddresses>0.0.0.0/0</authorizedAddresses>
+        <verifyIdentity>true</verifyIdentity>
+        <maxmessagesize>0</maxmessagesize>
+        <addressBracketsEnforcement>true</addressBracketsEnforcement>
+        <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting>
+        <handlerchain>
+            <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/>
+            <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
+        </handlerchain>
+    </smtpserver>
+    <smtpserver enabled="true">
+        <jmxName>smtpserver-TLS</jmxName>
+        <bind>0.0.0.0:10465</bind>
+        <connectionBacklog>200</connectionBacklog>
+        <tls socketTLS="false" startTLS="false">
+            <keystore>file://conf/keystore</keystore>
+            <secret>james72laBalle</secret>
+            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+            <algorithm>SunX509</algorithm>
+        </tls>
+        <connectiontimeout>360</connectiontimeout>
+        <connectionLimit>0</connectionLimit>
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <!--
+           Authorize only local users
+        -->
+        <authRequired>true</authRequired>
+        <authorizedAddresses>0.0.0.0/0</authorizedAddresses>
+        <!-- Trust authenticated users -->
+        <verifyIdentity>false</verifyIdentity>
+        <maxmessagesize>0</maxmessagesize>
+        <addressBracketsEnforcement>true</addressBracketsEnforcement>
+        <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting>
+        <handlerchain>
+            <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/>
+            <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
+        </handlerchain>
+    </smtpserver>
+    <smtpserver enabled="true">
+        <jmxName>smtpserver-authenticated</jmxName>
+        <bind>0.0.0.0:1587</bind>
+        <connectionBacklog>200</connectionBacklog>
+        <tls socketTLS="false" startTLS="false">
+            <keystore>file://conf/keystore</keystore>
+            <secret>james72laBalle</secret>
+            <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+            <algorithm>SunX509</algorithm>
+        </tls>
+        <connectiontimeout>360</connectiontimeout>
+        <connectionLimit>0</connectionLimit>
+        <connectionLimitPerIP>0</connectionLimitPerIP>
+        <!--
+           Authorize only local users
+        -->
+        <authRequired>true</authRequired>
+        <authorizedAddresses>0.0.0.0/0</authorizedAddresses>
+        <!-- Trust authenticated users -->
+        <verifyIdentity>false</verifyIdentity>
+        <maxmessagesize>0</maxmessagesize>
+        <addressBracketsEnforcement>true</addressBracketsEnforcement>
+        <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting>
+        <handlerchain>
+            <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/>
+            <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
+        </handlerchain>
+    </smtpserver>
+</smtpservers>
+
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
index 6653cd9..5a3dd07 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
@@ -28,18 +28,21 @@ import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
+import com.google.inject.Module;
+
 public class MemoryJmapTestRule implements TestRule {
 
     private static final int LIMIT_TO_3_MESSAGES = 3;
     
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
-    public GuiceJamesServer jmapServer() {
+    public GuiceJamesServer jmapServer(Module... modules) {
         return new GuiceJamesServer()
-                .combineWith(MemoryJamesServerMain.inMemoryServerModule)
-                .overrideWith(new TestFilesystemModule(temporaryFolder),
-                        new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
-                .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class));
+            .combineWith(MemoryJamesServerMain.inMemoryServerModule)
+            .combineWith(modules)
+            .overrideWith(new TestFilesystemModule(temporaryFolder),
+                new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
+            .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/container/util/src/main/java/org/apache/james/util/RestrictingRMISocketFactory.java
----------------------------------------------------------------------
diff --git a/server/container/util/src/main/java/org/apache/james/util/RestrictingRMISocketFactory.java b/server/container/util/src/main/java/org/apache/james/util/RestrictingRMISocketFactory.java
index 1b53bba..f0f706d 100644
--- a/server/container/util/src/main/java/org/apache/james/util/RestrictingRMISocketFactory.java
+++ b/server/container/util/src/main/java/org/apache/james/util/RestrictingRMISocketFactory.java
@@ -23,6 +23,8 @@ import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.rmi.server.RMISocketFactory;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * {@link RMISocketFactory} implementation which allow to bind JMX to a specific
@@ -32,6 +34,8 @@ public class RestrictingRMISocketFactory extends RMISocketFactory {
 
     private final String address;
 
+    private final List<ServerSocket> sockets = new ArrayList<ServerSocket>();
+
     public RestrictingRMISocketFactory(String address) {
         this.address = address;
     }
@@ -48,6 +52,7 @@ public class RestrictingRMISocketFactory extends RMISocketFactory {
     public ServerSocket createServerSocket(int port) throws IOException {
         ServerSocket socket = new ServerSocket();
         socket.bind(new InetSocketAddress(address, port));
+        sockets.add(socket);
         return socket;
     }
 
@@ -58,4 +63,7 @@ public class RestrictingRMISocketFactory extends RMISocketFactory {
         return new Socket(host, port);
     }
 
+    public List<ServerSocket> getSockets() {
+        return sockets;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b052f86a/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index cfffd6f..a46f7dd 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -57,6 +57,7 @@
         <module>karaf/integration</module>
 
         <module>container/cli</module>
+        <module>container/cli-integration</module>
         <module>container/core</module>
         <module>container/filesystem-api</module>
         <module>container/guice</module>


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


[06/15] james-project git commit: JAMES-1982 Allow Quota and Sieve administration threw JMX

Posted by bt...@apache.org.
JAMES-1982 Allow Quota and Sieve administration threw JMX


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

Branch: refs/heads/master
Commit: 336d02e7a70b5947b4c236ef74b9e85906c7f013
Parents: 604a9da
Author: benwa <bt...@linagora.com>
Authored: Fri Mar 31 19:03:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../james/modules/server/JMXServerModule.java     | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/336d02e7/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
index 9d66b8a..fc97468 100644
--- a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
+++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
@@ -26,6 +26,8 @@ import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean;
 import org.apache.james.adapter.mailbox.MailboxManagerManagement;
 import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean;
 import org.apache.james.adapter.mailbox.MailboxManagerResolver;
+import org.apache.james.adapter.mailbox.QuotaManagement;
+import org.apache.james.adapter.mailbox.QuotaManagementMBean;
 import org.apache.james.adapter.mailbox.ReIndexerManagement;
 import org.apache.james.adapter.mailbox.ReIndexerManagementMBean;
 import org.apache.james.domainlist.api.DomainListManagementMBean;
@@ -39,6 +41,8 @@ import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean;
 import org.apache.james.mailetcontainer.impl.JamesMailSpooler;
 import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
 import org.apache.james.rrt.lib.RecipientRewriteTableManagement;
+import org.apache.james.sieverepository.api.SieveRepositoryManagementMBean;
+import org.apache.james.sieverepository.lib.SieveRepositoryManagement;
 import org.apache.james.user.api.UsersRepositoryManagementMBean;
 import org.apache.james.user.lib.UsersRepositoryManagement;
 import org.apache.james.utils.ConfigurationPerformer;
@@ -60,6 +64,8 @@ public class JMXServerModule extends AbstractModule {
     private static final String JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN = "org.apache.james:type=component,name=mailboxmanagerbean";
     private static final String JMX_COMPONENT_MAILBOXCOPIER = "org.apache.james:type=component,name=mailboxcopier";
     private static final String JMX_COMPONENT_REINDEXER = "org.apache.james:type=component,name=reindexerbean";
+    private final static String JMX_COMPONENT_QUOTA = "org.apache.james:type=component,name=quotamanagerbean";
+    private final static String JMX_COMPONENT_SIEVE = "org.apache.james:type=component,name=sievemanagerbean";
 
     @Override
     protected void configure() {
@@ -73,6 +79,8 @@ public class JMXServerModule extends AbstractModule {
         bind(MailSpoolerMBean.class).to(JamesMailSpooler.class);
         bind(ReIndexer.class).annotatedWith(Names.named("reindexer")).to(ReIndexerImpl.class);
         bind(ReIndexerManagementMBean.class).to(ReIndexerManagement.class);
+        bind(QuotaManagementMBean.class).to(QuotaManagement.class);
+        bind(SieveRepositoryManagementMBean.class).to(SieveRepositoryManagement.class);
         Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JMXModuleConfigurationPerformer.class);
     }
 
@@ -86,6 +94,8 @@ public class JMXServerModule extends AbstractModule {
         private final MailboxManagerManagementMBean mailboxManagerManagementMBean;
         private final MailboxCopierManagementMBean mailboxCopierManagementMBean;
         private final ReIndexerManagementMBean reIndexerManagementMBean;
+        private final QuotaManagementMBean quotaManagementMBean;
+        private final SieveRepositoryManagementMBean sieveRepositoryManagementMBean;
 
         @Inject
         public JMXModuleConfigurationPerformer(JMXServer jmxServer,
@@ -94,7 +104,9 @@ public class JMXServerModule extends AbstractModule {
                                                RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean,
                                                MailboxManagerManagementMBean mailboxManagerManagementMBean,
                                                MailboxCopierManagementMBean mailboxCopierManagementMBean,
-                                               ReIndexerManagementMBean reIndexerManagementMBean) {
+                                               ReIndexerManagementMBean reIndexerManagementMBean,
+                                               QuotaManagementMBean quotaManagementMBean,
+                                               SieveRepositoryManagementMBean sieveRepositoryManagementMBean) {
             this.jmxServer = jmxServer;
             this.domainListManagementMBean = domainListManagementMBean;
             this.usersRepositoryManagementMBean = usersRepositoryManagementMBean;
@@ -102,6 +114,8 @@ public class JMXServerModule extends AbstractModule {
             this.mailboxManagerManagementMBean = mailboxManagerManagementMBean;
             this.mailboxCopierManagementMBean = mailboxCopierManagementMBean;
             this.reIndexerManagementMBean = reIndexerManagementMBean;
+            this.quotaManagementMBean = quotaManagementMBean;
+            this.sieveRepositoryManagementMBean = sieveRepositoryManagementMBean;
         }
 
         @Override
@@ -114,6 +128,8 @@ public class JMXServerModule extends AbstractModule {
                 jmxServer.register(JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN, mailboxManagerManagementMBean);
                 jmxServer.register(JMX_COMPONENT_MAILBOXCOPIER, mailboxCopierManagementMBean);
                 jmxServer.register(JMX_COMPONENT_REINDEXER, reIndexerManagementMBean);
+                jmxServer.register(JMX_COMPONENT_QUOTA, quotaManagementMBean);
+                jmxServer.register(JMX_COMPONENT_SIEVE, sieveRepositoryManagementMBean);
             } catch (Exception e) {
                 Throwables.propagate(e);
             }


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


[15/15] james-project git commit: JAMES-1982 Correct punctuation spacing for CLI output

Posted by bt...@apache.org.
JAMES-1982 Correct punctuation spacing for CLI output


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

Branch: refs/heads/master
Commit: a281f59fdc4630b6c67a69fe8b3455d42cce543f
Parents: c994be0
Author: benwa <bt...@linagora.com>
Authored: Sun Apr 2 10:58:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:33 2017 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/cli/ServerCmd.java | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a281f59f/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
index edf86fa..a9f6e69 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
@@ -266,16 +266,16 @@ public class ServerCmd {
             printMessageQuota(arguments[1], quotaProbe.getMessageCountQuota(arguments[1]), printStream);
             break;
         case GETQUOTAROOT:
-            printStream.println("Quota Root : " + quotaProbe.getQuotaRoot(arguments[1], arguments[2], arguments[3]));
+            printStream.println("Quota Root: " + quotaProbe.getQuotaRoot(arguments[1], arguments[2], arguments[3]));
             break;
         case GETMAXSTORAGEQUOTA:
             printStream.println("Storage space allowed for Quota Root "
                 + arguments[1]
-                + " : "
+                + ": "
                 + formatStorageValue(quotaProbe.getMaxStorage(arguments[1])));
             break;
         case GETMAXMESSAGECOUNTQUOTA:
-            printStream.println("MailboxMessage count allowed for Quota Root " + arguments[1] + " : " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1])));
+            printStream.println("MailboxMessage count allowed for Quota Root " + arguments[1] + ": " + formatMessageValue(quotaProbe.getMaxMessageCount(arguments[1])));
             break;
         case SETMAXSTORAGEQUOTA:
             quotaProbe.setMaxStorage(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue());
@@ -290,10 +290,10 @@ public class ServerCmd {
             quotaProbe.setDefaultMaxMessageCount(Long.parseLong(arguments[1]));
             break;
         case GETDEFAULTMAXSTORAGEQUOTA:
-            printStream.println("Default Maximum Storage Quota : " + formatStorageValue(quotaProbe.getDefaultMaxStorage()));
+            printStream.println("Default Maximum Storage Quota: " + formatStorageValue(quotaProbe.getDefaultMaxStorage()));
             break;
         case GETDEFAULTMAXMESSAGECOUNTQUOTA:
-            printStream.println("Default Maximum message count Quota : " + formatMessageValue(quotaProbe.getDefaultMaxMessageCount()));
+            printStream.println("Default Maximum message count Quota: " + formatMessageValue(quotaProbe.getDefaultMaxMessageCount()));
             break;
         case REINDEXMAILBOX:
             mailboxProbe.reIndexMailbox(arguments[1], arguments[2], arguments[3]);
@@ -308,13 +308,13 @@ public class ServerCmd {
             sieveProbe.setSieveQuota(arguments[1], ValueWithUnit.parse(arguments[2]).getConvertedValue());
             break;
         case GETSIEVEQUOTA:
-            printStream.println("Storage space allowed for Sieve scripts by default : "
+            printStream.println("Storage space allowed for Sieve scripts by default: "
                 + formatStorageValue(sieveProbe.getSieveQuota()));
             break;
         case GETSIEVEUSERQUOTA:
             printStream.println("Storage space allowed for "
                 + arguments[1]
-                + " Sieve scripts : "
+                + " Sieve scripts: "
                 + formatStorageValue(sieveProbe.getSieveQuota(arguments[1])));
             break;
         case REMOVESIEVEQUOTA:
@@ -339,14 +339,14 @@ public class ServerCmd {
     }
 
     private void printStorageQuota(String quotaRootString, SerializableQuota quota, PrintStream printStream) {
-        printStream.println(String.format("Storage quota for %s is : %s / %s",
+        printStream.println(String.format("Storage quota for %s is: %s / %s",
             quotaRootString,
             formatStorageValue(quota.getUsed()),
             formatStorageValue(quota.getMax())));
     }
 
     private void printMessageQuota(String quotaRootString, SerializableQuota quota, PrintStream printStream) {
-        printStream.println(String.format("MailboxMessage count quota for %s is : %s / %s",
+        printStream.println(String.format("MailboxMessage count quota for %s is: %s / %s",
             quotaRootString,
             formatMessageValue(quota.getUsed()),
             formatMessageValue(quota.getMax())));


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


[04/15] james-project git commit: JAMES-1982 Correct JMX Sieve probe

Posted by bt...@apache.org.
JAMES-1982 Correct JMX Sieve probe


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

Branch: refs/heads/master
Commit: 95d241de993bd78baec2958d65b59ed9f4a5fda9
Parents: 184c2b5
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 11:36:05 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/95d241de/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java
index acfcf7d..2e5529d 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxSieveProbe.java
@@ -34,7 +34,7 @@ public class JmxSieveProbe implements SieveProbe, JmxProbe {
     
     public JmxSieveProbe connect(JmxConnection jmxc) throws IOException {
         try {
-            jmxc.retrieveBean(SieveRepositoryManagementMBean.class, SIEVEMANAGER_OBJECT_NAME);
+            sieveRepositoryManagement = jmxc.retrieveBean(SieveRepositoryManagementMBean.class, SIEVEMANAGER_OBJECT_NAME);
         } catch (MalformedObjectNameException e) {
             throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
         }


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


[09/15] james-project git commit: JAMES-1982 Create Sieve file folder in constructor

Posted by bt...@apache.org.
JAMES-1982 Create Sieve file folder in constructor


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

Branch: refs/heads/master
Commit: 184c2b5c9015ad977309becf9d4ed42bf72de971
Parents: fe92e8b
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 11:35:37 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../managesieve/file/host/FileHostSystem.java   |  2 -
 .../file/SieveFileRepository.java               | 55 ++++++++------------
 .../file/SieveFileRepositoryTest.java           |  2 -
 3 files changed, 21 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/184c2b5c/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/host/FileHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/host/FileHostSystem.java b/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/host/FileHostSystem.java
index 389209c..7bd28dc 100644
--- a/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/host/FileHostSystem.java
+++ b/mpt/impl/managesieve/file/src/test/java/org/apache/james/mpt/managesieve/file/host/FileHostSystem.java
@@ -52,8 +52,6 @@ public class FileHostSystem extends JamesManageSieveHostSystem {
     }
 
     protected static SieveRepository createSieveRepository() throws Exception {
-        File root = getFileSystem().getFile(SIEVE_ROOT);
-        FileUtils.forceMkdir(root);
         return new SieveFileRepository(fileSystem);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/184c2b5c/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
index af9b2ba..221320e 100644
--- a/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
+++ b/server/data/data-file/src/main/java/org/apache/james/sieverepository/file/SieveFileRepository.java
@@ -20,20 +20,6 @@
 
 package org.apache.james.sieverepository.file;
 
-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.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.exception.StorageException;
-import org.joda.time.DateTime;
-
-import javax.inject.Inject;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -49,6 +35,21 @@ import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Scanner;
 
+import javax.inject.Inject;
+
+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.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.exception.StorageException;
+import org.joda.time.DateTime;
+
 /**
  * <code>SieveFileRepository</code> manages sieve scripts stored on the file system.
  * <p>The sieve root directory is a sub-directory of the application base directory named "sieve".
@@ -65,7 +66,7 @@ public class SieveFileRepository implements SieveRepository {
     private static final int MAX_BUFF_SIZE = 32768;
     public static final String SIEVE_EXTENSION = ".sieve";
 
-    private FileSystem _fileSystem = null;
+    private final FileSystem fileSystem;
     private final Object lock = new Object();
 
     /**
@@ -134,25 +135,11 @@ public class SieveFileRepository implements SieveRepository {
         }
     }
 
-    /**
-     * Creates a new instance of SieveFileRepository.
-     */
-    public SieveFileRepository() {
-
-    }
-
-    /**
-     * Creates a new instance of SieveFileRepository.
-     *
-     * @param fileSystem
-     */
-    public SieveFileRepository(FileSystem fileSystem) {
-        setFileSystem(fileSystem);
-    }
-
     @Inject
-    public void setFileSystem(FileSystem fileSystem) {
-        _fileSystem = fileSystem;
+    public SieveFileRepository(FileSystem fileSystem) throws IOException {
+        this.fileSystem = fileSystem;
+        File root = fileSystem.getFile(SIEVE_ROOT);
+        FileUtils.forceMkdir(root);
     }
 
     @Override
@@ -318,7 +305,7 @@ public class SieveFileRepository implements SieveRepository {
 
     protected File getSieveRootDirectory() throws StorageException {
         try {
-            return _fileSystem.getFile(SIEVE_ROOT);
+            return fileSystem.getFile(SIEVE_ROOT);
         } catch (FileNotFoundException ex1) {
             throw new StorageException(ex1);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/184c2b5c/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java b/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
index d1e3bc0..f2a7daf 100644
--- a/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
+++ b/server/data/data-file/src/test/java/org/apache/james/sieverepository/file/SieveFileRepositoryTest.java
@@ -35,8 +35,6 @@ public class SieveFileRepositoryTest extends AbstractSieveRepositoryTest {
 
     @Override
     protected SieveRepository createSieveRepository() throws Exception {
-        File root = fileSystem.getFile(SIEVE_ROOT);
-        FileUtils.forceMkdir(root);
         return new SieveFileRepository(fileSystem);
     }
 


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


[02/15] james-project git commit: JAMES-1980 Improves for UseHeaderRecipients

Posted by bt...@apache.org.
JAMES-1980 Improves for UseHeaderRecipients


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

Branch: refs/heads/master
Commit: 604a9dae7c12bb9eb55ea7b7093deaa55b95558e
Parents: 398663e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Wed Dec 28 09:31:54 2016 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:28 2017 +0700

----------------------------------------------------------------------
 .../mailet/base/test/FakeMailContext.java       |   5 +
 mailet/standard/pom.xml                         |   5 +
 .../transport/mailets/UseHeaderRecipients.java  | 131 +++++++++----
 .../mailets/UseHeaderRecipientsTest.java        | 184 +++++++++++++++++++
 4 files changed, 292 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/604a9dae/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
index 4617a94..1b22e44 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java
@@ -122,6 +122,11 @@ public class FakeMailContext implements MailetContext {
                 return this;
             }
 
+            public Builder recipients(MailAddress... recipients) {
+                this.recipients = Optional.<Collection<MailAddress>>of(ImmutableList.copyOf(recipients));
+                return this;
+            }
+
             public Builder recipient(MailAddress recipient) {
                 Preconditions.checkNotNull(recipient);
                 return recipients(ImmutableList.of(recipient));

http://git-wip-us.apache.org/repos/asf/james-project/blob/604a9dae/mailet/standard/pom.xml
----------------------------------------------------------------------
diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index 04ba9e5..45048ac 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -50,6 +50,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>apache-mime4j-dom</artifactId>
+            <version>${mime4j.version}</version>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/604a9dae/mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java
index 603a617..b802d5d 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java
@@ -20,16 +20,29 @@
 
 package org.apache.james.transport.mailets;
 
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeUtility;
+
+import org.apache.james.mime4j.dom.address.Address;
+import org.apache.james.mime4j.dom.address.AddressList;
+import org.apache.james.mime4j.dom.address.Group;
+import org.apache.james.mime4j.dom.address.Mailbox;
+import org.apache.james.mime4j.field.address.LenientAddressParser;
+import org.apache.james.mime4j.util.MimeUtil;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 
-import javax.mail.MessagingException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import java.util.Collection;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.base.Throwables;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
 
 /**
  * <p>Mailet designed to process the recipients from the mail headers rather
@@ -55,6 +68,17 @@ import java.util.Vector;
  */
 public class UseHeaderRecipients extends GenericMailet {
 
+    public static final Function<Mailbox, MailAddress> TO_MAIL_ADDRESS = new Function<Mailbox, MailAddress>() {
+        @Override
+        public MailAddress apply(Mailbox input) {
+            try {
+                return new MailAddress(input.getAddress());
+            } catch (AddressException e) {
+                throw Throwables.propagate(e);
+            }
+        }
+    };
+
     /**
      * Controls certain log messages
      */
@@ -79,20 +103,10 @@ public class UseHeaderRecipients extends GenericMailet {
     public void service(Mail mail) throws MessagingException {
         MimeMessage message = mail.getMessage();
 
-        // Utilise features of Set Collections such that they automatically
-        // ensure that no two entries are equal using the equality method
-        // of the element objects.  MailAddress objects test equality based
-        // on equivalent but not necessarily visually identical addresses.
-        Collection<MailAddress> recipients = mail.getRecipients();
-        // Wipe all the exist recipients
-        recipients.clear();
-        recipients.addAll(getHeaderMailAddresses(message, "Mail-For"));
-        if (recipients.isEmpty()) {
-            recipients.addAll(getHeaderMailAddresses(message, "To"));
-            recipients.addAll(getHeaderMailAddresses(message, "Cc"));
-        }
+        mail.setRecipients(headersAddresses(message));
+
         if (isDebug) {
-            log("All recipients = " + recipients.toString());
+            log("All recipients = " + mail.getRecipients());
             log("Reprocessing mail using recipients in message headers");
         }
 
@@ -101,6 +115,18 @@ public class UseHeaderRecipients extends GenericMailet {
         mail.setState(Mail.GHOST);
     }
 
+    public Collection<MailAddress> headersAddresses(MimeMessage mimeMessage) throws MessagingException {
+        Collection<MailAddress> mailForHeaderAddresses = getHeaderMailAddresses(mimeMessage, "Mail-For");
+        if (!mailForHeaderAddresses.isEmpty()) {
+            return mailForHeaderAddresses;
+        }
+        return ImmutableList.<MailAddress>builder()
+            .addAll(getHeaderMailAddresses(mimeMessage, "To"))
+            .addAll(getHeaderMailAddresses(mimeMessage, "Cc"))
+            .addAll(getHeaderMailAddresses(mimeMessage, "Bcc"))
+            .build();
+    }
+
 
     /**
      * Return a string describing this mailet.
@@ -120,28 +146,67 @@ public class UseHeaderRecipients extends GenericMailet {
      * @return the collection of MailAddress objects.
      */
     private Collection<MailAddress> getHeaderMailAddresses(MimeMessage message, String name) throws MessagingException {
-
         if (isDebug) {
             log("Checking " + name + " headers");
         }
-        Collection<MailAddress> addresses = new Vector<MailAddress>();
         String[] headers = message.getHeader(name);
-        String addressString;
-        InternetAddress iAddress;
+        ImmutableList.Builder<MailAddress> addresses = ImmutableList.builder();
+
         if (headers != null) {
             for (String header : headers) {
-                StringTokenizer st = new StringTokenizer(header, ",", false);
-                while (st.hasMoreTokens()) {
-                    addressString = st.nextToken();
-                    iAddress = new InternetAddress(addressString);
-                    if (isDebug) {
-                        log("Address = " + iAddress.toString());
-                    }
-                    addresses.add(new MailAddress(iAddress));
-                }
+               addresses.addAll(getMailAddressesFromHeaderLine(header));
             }
         }
-        return addresses;
+        return addresses.build();
+    }
+
+    private ImmutableList<MailAddress> getMailAddressesFromHeaderLine(String header) throws MessagingException {
+        String unfoldedDecodedString = sanitizeHeaderString(header);
+        Iterable<String> headerParts = Splitter.on(",").split(unfoldedDecodedString);
+        return getMailAddressesFromHeadersParts(headerParts);
+    }
+
+    private ImmutableList<MailAddress> getMailAddressesFromHeadersParts(Iterable<String> headerParts) throws AddressException {
+        ImmutableList.Builder<MailAddress> result = ImmutableList.builder();
+        for (String headerPart : headerParts) {
+            if (isDebug) {
+                log("Address = " + headerPart);
+            }
+            result.addAll(readMailAddresses(headerPart));
+        }
+        return result.build();
+    }
+
+    private Collection<MailAddress> readMailAddresses(String headerPart) throws AddressException {
+        AddressList addressList = LenientAddressParser.DEFAULT
+            .parseAddressList(MimeUtil.unfold(headerPart));
+
+        ImmutableList.Builder<Mailbox> mailboxList = ImmutableList.builder();
+
+        for (Address address: addressList) {
+            mailboxList.addAll(convertAddressToMailboxCollection(address));
+        }
+
+        return FluentIterable.from(mailboxList.build())
+            .transform(TO_MAIL_ADDRESS)
+            .toList();
+    }
+
+    private Collection<Mailbox> convertAddressToMailboxCollection(Address address) {
+        if (address instanceof Mailbox) {
+            return ImmutableList.of((Mailbox) address);
+        } else if (address instanceof Group) {
+            return ImmutableList.copyOf(((Group) address).getMailboxes());
+        }
+        return ImmutableList.of();
+    }
+
+    private String sanitizeHeaderString(String header) throws MessagingException {
+        try {
+            return MimeUtility.unfold(MimeUtility.decodeText(header));
+        } catch (UnsupportedEncodingException e) {
+            throw new MessagingException("Can not decode header", e);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/604a9dae/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java
new file mode 100644
index 0000000..95d220a
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/UseHeaderRecipientsTest.java
@@ -0,0 +1,184 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.MailAddressFixture;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.apache.mailet.base.test.MimeMessageBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class UseHeaderRecipientsTest {
+
+    public static final String RECIPIENT1 = "abc1@apache1.org";
+    public static final String RECIPIENT2 = "abc2@apache2.org";
+    public static final String RECIPIENT3 = "abc3@apache3.org";
+    private UseHeaderRecipients testee;
+    private FakeMailContext mailetContext;
+    private MailAddress mailAddress1;
+    private MailAddress mailAddress2;
+    private MailAddress mailAddress3;
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Before
+    public void setUp() throws Exception {
+        testee = new UseHeaderRecipients();
+        mailetContext = FakeMailContext.defaultContext();
+        testee.init(FakeMailetConfig.builder().mailetContext(mailetContext).build());
+
+        mailAddress1 = new MailAddress(RECIPIENT1);
+        mailAddress2 = new MailAddress(RECIPIENT2);
+        mailAddress3 = new MailAddress(RECIPIENT3);
+    }
+
+    @Test
+    public void serviceShouldSetMimeMessageRecipients() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.ANY_AT_JAMES2)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient(RECIPIENT1, RECIPIENT2)
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getRecipients())
+            .containsOnly(mailAddress1, mailAddress2);
+    }
+
+    @Test
+    public void serviceShouldSetToCcAndBccSpecifiedInTheMimeMessage() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient(RECIPIENT1)
+                .addCcRecipient(RECIPIENT2)
+                .addBccRecipient(RECIPIENT3)
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getRecipients())
+            .containsOnly(mailAddress1, mailAddress2, mailAddress3);
+    }
+
+    @Test
+    public void serviceShouldSetEmptyRecipientWhenNoRecipientsInTheMimeMessage() throws Exception {
+
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getRecipients())
+            .isEmpty();
+    }
+
+    @Test
+    public void serviceShouldGhostEmail() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getState())
+            .isEqualTo(Mail.GHOST);
+    }
+
+    @Test
+    public void serviceShouldResendTheEmail() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient(RECIPIENT1)
+                .addCcRecipient(RECIPIENT2)
+                .addBccRecipient(RECIPIENT3)
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(mailetContext.getSentMails())
+            .containsOnly(FakeMailContext.sentMailBuilder()
+                .recipients(mailAddress1, mailAddress2, mailAddress3)
+                .build());
+    }
+
+    @Test
+    public void serviceShouldThrowOnInvalidMailAddress() throws Exception {
+        expectedException.expect(RuntimeException.class);
+
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients(mailAddress1)
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient("invalid")
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+    }
+
+    @Test
+    public void serviceShouldSupportAddressList() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients()
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient(RECIPIENT1, RECIPIENT2)
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getRecipients())
+            .containsOnly(mailAddress1, mailAddress2);
+    }
+
+    @Test
+    public void serviceShouldSupportMailboxes() throws Exception {
+        FakeMail fakeMail = FakeMail.builder()
+            .recipients()
+            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
+                .addToRecipient("APACHE" + "<" + UseHeaderRecipientsTest.RECIPIENT1 + ">")
+                .build())
+            .build();
+
+        testee.service(fakeMail);
+
+        assertThat(fakeMail.getRecipients())
+            .containsOnly(mailAddress1);
+    }
+}


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


[05/15] james-project git commit: JAMES-1982 Set logger on MailboxManagement to avoid NPE

Posted by bt...@apache.org.
JAMES-1982 Set logger on MailboxManagement to avoid NPE


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

Branch: refs/heads/master
Commit: 8942eaff850265defa6c9c6e629350067d65a1f9
Parents: 95d241d
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 12:08:11 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../james/modules/server/JMXServerModule.java   | 36 +++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8942eaff/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
index fc97468..626ef3a 100644
--- a/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
+++ b/server/container/guice/jmx/src/main/java/org/apache/james/modules/server/JMXServerModule.java
@@ -47,11 +47,13 @@ import org.apache.james.user.api.UsersRepositoryManagementMBean;
 import org.apache.james.user.lib.UsersRepositoryManagement;
 import org.apache.james.utils.ConfigurationPerformer;
 import org.apache.james.utils.GuiceMailboxManagerResolver;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
+import com.google.inject.Scopes;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
 import com.google.inject.name.Names;
@@ -69,6 +71,15 @@ public class JMXServerModule extends AbstractModule {
 
     @Override
     protected void configure() {
+        bind(ReIndexerManagement.class).in(Scopes.SINGLETON);
+        bind(QuotaManagement.class).in(Scopes.SINGLETON);
+        bind(RecipientRewriteTableManagement.class).in(Scopes.SINGLETON);
+        bind(MailboxManagerManagement.class).in(Scopes.SINGLETON);
+        bind(UsersRepositoryManagement.class).in(Scopes.SINGLETON);
+        bind(DomainListManagement.class).in(Scopes.SINGLETON);
+        bind(MailboxCopierManagement.class).in(Scopes.SINGLETON);
+        bind(SieveRepositoryManagement.class).in(Scopes.SINGLETON);
+
         bind(MailboxCopier.class).annotatedWith(Names.named("mailboxcopier")).to(MailboxCopierImpl.class);
         bind(MailboxCopierManagementMBean.class).to(MailboxCopierManagement.class);
         bind(MailboxManagerResolver.class).to(GuiceMailboxManagerResolver.class);
@@ -81,7 +92,9 @@ public class JMXServerModule extends AbstractModule {
         bind(ReIndexerManagementMBean.class).to(ReIndexerManagement.class);
         bind(QuotaManagementMBean.class).to(QuotaManagement.class);
         bind(SieveRepositoryManagementMBean.class).to(SieveRepositoryManagement.class);
-        Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JMXModuleConfigurationPerformer.class);
+        Multibinder<ConfigurationPerformer> configurationMultibinder = Multibinder.newSetBinder(binder(), ConfigurationPerformer.class);
+        configurationMultibinder.addBinding().to(JMXModuleConfigurationPerformer.class);
+        configurationMultibinder.addBinding().to(MailboxManagementLogSetter.class);
     }
 
     @Singleton
@@ -141,4 +154,25 @@ public class JMXServerModule extends AbstractModule {
         }
     }
 
+    @Singleton
+    public static class MailboxManagementLogSetter implements ConfigurationPerformer {
+
+        private final MailboxManagerManagement mailboxManagerManagement;
+
+        @Inject
+        public MailboxManagementLogSetter(MailboxManagerManagement mailboxManagerManagement) {
+            this.mailboxManagerManagement = mailboxManagerManagement;
+        }
+
+        @Override
+        public void initModule() {
+            mailboxManagerManagement.setLog(LoggerFactory.getLogger(MailboxManagerManagement.class));
+        }
+
+        @Override
+        public List<Class<? extends Configurable>> forClasses() {
+            return ImmutableList.of();
+        }
+    }
+
 }


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


[12/15] james-project git commit: JAMES-1982 getAllMapping result was not serializable

Posted by bt...@apache.org.
JAMES-1982 getAllMapping result was not serializable

Guava ImmutableList copy solves the issue


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

Branch: refs/heads/master
Commit: e854211397d22104c9dfa7c591edae47505be8f4
Parents: f1e4b34
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 18:37:06 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:33 2017 +0700

----------------------------------------------------------------------
 .../apache/james/rrt/lib/RecipientRewriteTableManagement.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e8542113/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
index e3d2b6c..879ccfb 100644
--- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
+++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableManagement.java
@@ -28,6 +28,8 @@ import org.apache.james.rrt.api.RecipientRewriteTable;
 import org.apache.james.rrt.api.RecipientRewriteTableException;
 import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
 
+import com.google.common.collect.ImmutableMap;
+
 /**
  * Management for RecipientRewriteTables
  */
@@ -182,7 +184,7 @@ public class RecipientRewriteTableManagement extends StandardMBean implements Re
      */
     public Map<String, Mappings> getAllMappings() throws Exception {
         try {
-            return rrt.getAllMappings();
+            return ImmutableMap.copyOf(rrt.getAllMappings());
         } catch (RecipientRewriteTableException e) {
             throw new Exception(e.getMessage());
         }


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


[14/15] james-project git commit: JAMES-1983 CLI test for re-indexing

Posted by bt...@apache.org.
JAMES-1983 CLI test for re-indexing


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

Branch: refs/heads/master
Commit: f1e4b343d1ba334cbe7e9c93e78650ab7f4d8ed8
Parents: b052f86
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 18:02:48 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:33 2017 +0700

----------------------------------------------------------------------
 .../james/cli/DataCommandsIntegrationTest.java  | 13 +---
 .../cli/MailboxCommandsIntegrationTest.java     | 13 +---
 .../james/cli/QuotaCommandsIntegrationTest.java |  5 +-
 .../cli/ReindexCommandIntegrationTest.java      | 77 ++++++++++++++++++++
 .../cli/SieveQuotaCommandsIntegrationTest.java  | 13 +---
 .../modules/mailbox/MemoryMailboxModule.java    | 15 ++++
 6 files changed, 96 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
index d1e4ee9..1e3a6d3 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/DataCommandsIntegrationTest.java
@@ -51,14 +51,6 @@ public class DataCommandsIntegrationTest {
     public static final String MAIL_ADDRESS = USER + "@" + DOMAIN_COM;
     public static final String PASSWORD = "12345";
 
-    @Singleton
-    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
-        @Inject
-        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
-            super("memory-mailboxmanager", manager);
-        }
-    }
-
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
     private GuiceJamesServer guiceJamesServer;
@@ -67,10 +59,7 @@ public class DataCommandsIntegrationTest {
     @Before
     public void setUp() throws Exception {
         guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
-            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
-            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
-                .addBinding()
-                .to(MemoryMailboxManagerDefinition.class));
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
         dataProbe = guiceJamesServer.getProbe(DataProbeImpl.class);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
index 4aabb44..074a22a 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/MailboxCommandsIntegrationTest.java
@@ -46,14 +46,6 @@ public class MailboxCommandsIntegrationTest {
     public static final String USER = "user";
     public static final String MAILBOX = "mailbox";
 
-    @Singleton
-    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
-        @Inject
-        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
-            super("memory-mailboxmanager", manager);
-        }
-    }
-
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
     private GuiceJamesServer guiceJamesServer;
@@ -62,10 +54,7 @@ public class MailboxCommandsIntegrationTest {
     @Before
     public void setUp() throws Exception {
         guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
-            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
-            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
-                .addBinding()
-                .to(MemoryMailboxManagerDefinition.class));
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
         mailboxProbe = guiceJamesServer.getProbe(MailboxProbeImpl.class);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
index b20dd87..517457d 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/QuotaCommandsIntegrationTest.java
@@ -61,10 +61,7 @@ public class QuotaCommandsIntegrationTest {
     @Before
     public void setUp() throws Exception {
         guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
-            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
-            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
-                .addBinding()
-                .to(MemoryMailboxManagerDefinition.class));
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
         guiceJamesServer.start();
         quotaProbe = guiceJamesServer.getProbe(QuotaProbesImpl.class);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java
new file mode 100644
index 0000000..ac7bfd7
--- /dev/null
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/ReindexCommandIntegrationTest.java
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.cli;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJmapTestRule;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.james.modules.server.JMXServerModule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.inject.name.Names;
+
+public class ReindexCommandIntegrationTest {
+    public static final String USER = "user";
+    private ReIndexer reIndexer;
+
+    @Rule
+    public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+    private GuiceJamesServer guiceJamesServer;
+
+    @Before
+    public void setUp() throws Exception {
+        reIndexer = mock(ReIndexer.class);
+        guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)))
+            .overrideWith(binder -> binder.bind(ReIndexer.class)
+                .annotatedWith(Names.named("reindexer")).toInstance(reIndexer));
+        guiceJamesServer.start();
+    }
+
+    @After
+    public void tearDown() {
+        guiceJamesServer.stop();
+    }
+
+    @Test
+    public void reindexAllShouldWork() throws Exception {
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "reindexall"});
+
+        verify(reIndexer).reIndex();
+    }
+
+    @Test
+    public void reindexMailboxShouldWork() throws Exception {
+        String mailbox = "mailbox";
+        ServerCmd.doMain(new String[] {"-h", "127.0.0.1", "-p", "9999", "reindexmailbox", MailboxConstants.USER_NAMESPACE, USER, mailbox});
+
+        verify(reIndexer).reIndex(new MailboxPath(MailboxConstants.USER_NAMESPACE, USER, mailbox));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
index 3cf3a1b..bc2fb30 100644
--- a/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
+++ b/server/container/cli-integration/src/test/java/org/apache/james/cli/SieveQuotaCommandsIntegrationTest.java
@@ -46,14 +46,6 @@ import com.google.inject.multibindings.Multibinder;
 public class SieveQuotaCommandsIntegrationTest {
     public static final String USER = "user";
 
-    @Singleton
-    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
-        @Inject
-        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
-            super("memory-mailboxmanager", manager);
-        }
-    }
-
     @Rule
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
     @Rule
@@ -66,10 +58,7 @@ public class SieveQuotaCommandsIntegrationTest {
     @Before
     public void setUp() throws Exception {
         guiceJamesServer = memoryJmap.jmapServer(new JMXServerModule(),
-            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)),
-            binder -> Multibinder.newSetBinder(binder, MailboxManagerDefinition.class)
-                .addBinding()
-                .to(MemoryMailboxManagerDefinition.class))
+            binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)))
             .overrideWith(new TestFilesystemModule(temporaryFolder));
         guiceJamesServer.start();
         sieveProbe = guiceJamesServer.getProbe(SieveProbeImpl.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1e4b343/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
index 7b1de77..0b28b08 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
@@ -63,10 +63,13 @@ import org.apache.james.mailbox.store.search.MessageSearchIndex;
 import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex;
 import org.apache.james.mailbox.store.user.SubscriptionMapperFactory;
 import org.apache.james.modules.Names;
+import org.apache.james.utils.MailboxManagerDefinition;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
+import com.google.inject.multibindings.Multibinder;
 import com.google.inject.name.Named;
 
 public class MemoryMailboxModule extends AbstractModule {
@@ -114,6 +117,10 @@ public class MemoryMailboxModule extends AbstractModule {
         bind(InMemoryMessageIdManager.class).in(Scopes.SINGLETON);
         bind(MailboxEventDispatcher.class).in(Scopes.SINGLETON);
         bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
+
+        Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class)
+            .addBinding()
+            .to(MemoryMailboxManagerDefinition.class);
     }
 
     @Provides @Named(Names.MAILBOXMANAGER_NAME) @Singleton
@@ -125,4 +132,12 @@ public class MemoryMailboxModule extends AbstractModule {
         mailboxManager.init();
         return mailboxManager;
     }
+
+    @Singleton
+    private static class MemoryMailboxManagerDefinition extends MailboxManagerDefinition {
+        @Inject
+        private MemoryMailboxManagerDefinition(InMemoryMailboxManager manager) {
+            super("memory-mailboxmanager", manager);
+        }
+    }
 }
\ No newline at end of file


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


[10/15] james-project git commit: JAMES-1982 Cli should not double output

Posted by bt...@apache.org.
JAMES-1982 Cli should not double output


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

Branch: refs/heads/master
Commit: b547e70f38390b8e865470348089771a87716984
Parents: 4321bcc
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 10:25:45 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/cli/ServerCmd.java    | 39 ++++++++++----------
 1 file changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b547e70f/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
index 402b0d2..af882ed 100644
--- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
+++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java
@@ -86,24 +86,8 @@ public class ServerCmd {
      * @param args Command-line arguments.
      */
     public static void main(String[] args) {
-
         try {
-            StopWatch stopWatch = new StopWatch();
-            stopWatch.start();
-            CommandLine cmd = parseCommandLine(args);
-            JmxConnection jmxConnection = new JmxConnection(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd));
-            CmdType cmdType = new ServerCmd(
-                    new JmxDataProbe().connect(jmxConnection),
-                    new JmxMailboxProbe().connect(jmxConnection),
-                    new JmxQuotaProbe().connect(jmxConnection),
-                    new JmxSieveProbe().connect(jmxConnection)
-                )
-                .executeCommandLine(cmd);
-            stopWatch.split();
-            print(new String[] { Joiner.on(' ')
-                    .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")},
-                System.out);
-            stopWatch.stop();
+            doMain(args);
             System.exit(0);
         } catch (JamesCliException e) {
             failWithMessage(e.getMessage());
@@ -115,7 +99,25 @@ public class ServerCmd {
             LOG.error("Error on command: {}", e);
             failWithMessage("Error " + e.getClass() + " while executing command:" + e.getMessage());
         }
+    }
 
+    public static void doMain(String[] args) throws Exception {
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start();
+        CommandLine cmd = parseCommandLine(args);
+        JmxConnection jmxConnection = new JmxConnection(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd));
+        CmdType cmdType = new ServerCmd(
+                new JmxDataProbe().connect(jmxConnection),
+                new JmxMailboxProbe().connect(jmxConnection),
+                new JmxQuotaProbe().connect(jmxConnection),
+                new JmxSieveProbe().connect(jmxConnection)
+            )
+            .executeCommandLine(cmd);
+        stopWatch.split();
+        print(new String[] { Joiner.on(' ')
+                .join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.")},
+            System.out);
+        stopWatch.stop();
     }
 
     private final DataProbe probe;
@@ -321,9 +323,6 @@ public class ServerCmd {
     
     private static void print(Iterable<String> data, PrintStream out) {
         if (data != null) {
-            for (String u : data) {
-                out.println(u);
-            }
             out.println(Joiner.on('\n').join(data));
         }
     }


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


[07/15] james-project git commit: JAMES-1982 Add a quota probe

Posted by bt...@apache.org.
JAMES-1982 Add a quota probe


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

Branch: refs/heads/master
Commit: f41a3cf550af35f35856dc2641dfb4f818cc75d4
Parents: 336d02e
Author: benwa <bt...@linagora.com>
Authored: Fri Mar 31 19:09:40 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/modules/MailboxModule.java |   4 +-
 .../apache/james/modules/QuotaProbesImpl.java   | 102 +++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f41a3cf5/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
index b342aac..48a9077 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxModule.java
@@ -27,7 +27,9 @@ public class MailboxModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(MailboxProbeImpl.class);
+        Multibinder<GuiceProbe> probeMultiBinder = Multibinder.newSetBinder(binder(), GuiceProbe.class);
+        probeMultiBinder.addBinding().to(MailboxProbeImpl.class);
+        probeMultiBinder.addBinding().to(QuotaProbesImpl.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f41a3cf5/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java
new file mode 100644
index 0000000..2277f1a
--- /dev/null
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/QuotaProbesImpl.java
@@ -0,0 +1,102 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.mail.model.SerializableQuota;
+import org.apache.james.mailbox.store.probe.QuotaProbe;
+import org.apache.james.utils.GuiceProbe;
+
+public class QuotaProbesImpl implements QuotaProbe, GuiceProbe {
+
+    private final MaxQuotaManager maxQuotaManager;
+    private final QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
+
+    @Inject
+    public QuotaProbesImpl(MaxQuotaManager maxQuotaManager, QuotaRootResolver quotaRootResolver, QuotaManager quotaManager) {
+        this.maxQuotaManager = maxQuotaManager;
+        this.quotaRootResolver = quotaRootResolver;
+        this.quotaManager = quotaManager;
+    }
+
+    @Override
+    public String getQuotaRoot(String namespace, String user, String name) throws MailboxException {
+        return quotaRootResolver.getQuotaRoot(new MailboxPath(namespace, user, name)).getValue();
+    }
+
+    @Override
+    public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException {
+        return new SerializableQuota(quotaManager.getMessageQuota(quotaRootResolver.createQuotaRoot(quotaRoot)));
+    }
+
+    @Override
+    public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException {
+        return new SerializableQuota(quotaManager.getStorageQuota(quotaRootResolver.createQuotaRoot(quotaRoot)));
+    }
+
+    @Override
+    public long getMaxMessageCount(String quotaRoot) throws MailboxException {
+        return maxQuotaManager.getMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot));
+    }
+
+    @Override
+    public long getMaxStorage(String quotaRoot) throws MailboxException {
+        return maxQuotaManager.getMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot));
+    }
+
+    @Override
+    public long getDefaultMaxMessageCount() throws MailboxException {
+        return maxQuotaManager.getDefaultMaxMessage();
+    }
+
+    @Override
+    public long getDefaultMaxStorage() throws MailboxException {
+        return maxQuotaManager.getDefaultMaxStorage();
+    }
+
+    @Override
+    public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException {
+        maxQuotaManager.setMaxMessage(quotaRootResolver.createQuotaRoot(quotaRoot),
+            maxMessageCount);
+    }
+
+    @Override
+    public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException {
+        maxQuotaManager.setMaxStorage(quotaRootResolver.createQuotaRoot(quotaRoot),
+            maxSize);
+    }
+
+    @Override
+    public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException {
+        maxQuotaManager.setDefaultMaxMessage(maxDefaultMessageCount);
+    }
+
+    @Override
+    public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException {
+        maxQuotaManager.setDefaultMaxStorage(maxDefaultSize);
+    }
+}


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


[11/15] james-project git commit: JAMES-1982 Correct injects on QuotaManagement

Posted by bt...@apache.org.
JAMES-1982 Correct injects on QuotaManagement


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

Branch: refs/heads/master
Commit: fe92e8bceb6c31f584c5c48bbbcb1753066622ce
Parents: b547e70
Author: benwa <bt...@linagora.com>
Authored: Sat Apr 1 11:11:56 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Apr 3 18:09:32 2017 +0700

----------------------------------------------------------------------
 .../james/adapter/mailbox/QuotaManagement.java     | 17 +++++++----------
 .../META-INF/org/apache/james/spring-server.xml    |  6 +-----
 2 files changed, 8 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fe92e8bc/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
index dd779a3..9083ab4 100644
--- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
+++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.adapter.mailbox;
 
+import javax.inject.Inject;
+
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
@@ -28,19 +30,14 @@ import org.apache.james.mailbox.store.mail.model.SerializableQuota;
 
 public class QuotaManagement implements QuotaManagementMBean {
 
-    private QuotaManager quotaManager;
-    private MaxQuotaManager maxQuotaManager;
-    private QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
+    private final MaxQuotaManager maxQuotaManager;
+    private final QuotaRootResolver quotaRootResolver;
 
-    public void setQuotaManager(QuotaManager quotaManager) {
+    @Inject
+    public QuotaManagement(QuotaManager quotaManager, MaxQuotaManager maxQuotaManager, QuotaRootResolver quotaRootResolver) {
         this.quotaManager = quotaManager;
-    }
-
-    public void setMaxQuotaManager(MaxQuotaManager maxQuotaManager) {
         this.maxQuotaManager = maxQuotaManager;
-    }
-
-    public void setQuotaRootResolver(QuotaRootResolver quotaRootResolver) {
         this.quotaRootResolver = quotaRootResolver;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/fe92e8bc/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index a08cedc..322c4c6 100644
--- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -280,11 +280,7 @@
     <bean id="domainlistmanagement" class="org.apache.james.domainlist.lib.DomainListManagement"/>
     <bean id="mailboxmanagermanagementbean" class="org.apache.james.adapter.mailbox.MailboxManagerManagement"/>
     <bean id="mailboxcopiermanagement" class="org.apache.james.adapter.mailbox.MailboxCopierManagement"/>
-    <bean id="quotamanagermanagement" class="org.apache.james.adapter.mailbox.QuotaManagement">
-        <property name="maxQuotaManager" ref="maxQuotaManager"/>
-        <property name="quotaRootResolver" ref="quotaRootResolver"/>
-        <property name="quotaManager" ref="quotaManager"/>
-    </bean>
+    <bean id="quotamanagermanagement" class="org.apache.james.adapter.mailbox.QuotaManagement"/>
     <bean id="reindexermanagement" class="org.apache.james.adapter.mailbox.ReIndexerManagement"/>
     <bean id="sievemanagerbean" class="org.apache.james.sieverepository.lib.SieveRepositoryManagement"/>
     <!--


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