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 2018/08/29 03:14:31 UTC
[03/34] james-project git commit: JAMES-2521 Limit CLI mailbox
dependencies
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java b/server/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
deleted file mode 100644
index 39520e7..0000000
--- a/server/container/mailbox-adapter/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
+++ /dev/null
@@ -1,308 +0,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. *
- ****************************************************************/
-
-package org.apache.james.adapter.mailbox;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Iterator;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.exception.MailboxExistsException;
-import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.junit.Before;
-import org.junit.Test;
-
-public class MailboxManagementTest {
-
- public static final String USER = "user";
- public static final int UID_VALIDITY = 10;
- public static final int LIMIT = 1;
-
- private MailboxManagerManagement mailboxManagerManagement;
- private MailboxSessionMapperFactory mapperFactory;
- private MailboxSession session;
-
- @Before
- public void setUp() throws Exception {
- StoreMailboxManager mailboxManager = new InMemoryIntegrationResources()
- .createMailboxManager(new SimpleGroupMembershipResolver());
- mapperFactory = mailboxManager.getMapperFactory();
-
- mailboxManagerManagement = new MailboxManagerManagement();
- mailboxManagerManagement.setMailboxManager(mailboxManager);
- session = mailboxManager.createSystemSession("TEST");
- }
-
- @Test
- public void deleteMailboxesShouldDeleteMailboxes() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test
- public void deleteMailboxesShouldDeleteInbox() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY));
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test
- public void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY));
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test
- public void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception {
- Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
- }
-
- @Test
- public void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception {
- Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
- }
-
- @Test
- public void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, ""), UID_VALIDITY));
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test(expected = NullPointerException.class)
- public void deleteMailboxesShouldThrowOnNullUserName() throws Exception {
- mailboxManagerManagement.deleteMailboxes(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void deleteMailboxesShouldThrowOnEmptyUserName() throws Exception {
- mailboxManagerManagement.deleteMailboxes("");
- }
-
- @Test
- public void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY));
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY));
- mailboxManagerManagement.deleteMailboxes(USER);
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test
- public void createMailboxShouldCreateAMailbox() throws Exception {
- mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
- assertThat(mapperFactory.createMailboxMapper(session).list()).hasSize(1);
- assertThat(mapperFactory.createMailboxMapper(session).findMailboxByPath(MailboxPath.forUser(USER, "name"))).isNotNull();
- }
-
- @Test
- public void createMailboxShouldThrowIfMailboxAlreadyExists() throws Exception {
- MailboxPath path = MailboxPath.forUser(USER, "name");
- Mailbox mailbox = new SimpleMailbox(path, UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
-
- assertThatThrownBy(() -> mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"))
- .isInstanceOf(RuntimeException.class)
- .hasCauseInstanceOf(MailboxExistsException.class);
- }
-
- @Test
- public void createMailboxShouldNotCreateAdditionalMailboxesIfMailboxAlreadyExists() throws Exception {
- MailboxPath path = MailboxPath.forUser(USER, "name");
- Mailbox mailbox = new SimpleMailbox(path, UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
-
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
- }
-
- @Test(expected = NullPointerException.class)
- public void createMailboxShouldThrowOnNullNamespace() {
- mailboxManagerManagement.createMailbox(null, "a", "a");
- }
-
- @Test(expected = NullPointerException.class)
- public void createMailboxShouldThrowOnNullUser() {
- mailboxManagerManagement.createMailbox("a", null, "a");
- }
-
- @Test(expected = NullPointerException.class)
- public void createMailboxShouldThrowOnNullName() {
- mailboxManagerManagement.createMailbox("a", "a", null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void createMailboxShouldThrowOnEmptyNamespace() {
- mailboxManagerManagement.createMailbox("", "a", "a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void createMailboxShouldThrowOnEmptyUser() {
- mailboxManagerManagement.createMailbox("a", "", "a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void createMailboxShouldThrowOnEmptyName() {
- mailboxManagerManagement.createMailbox("a", "a", "");
- }
-
- @Test
- public void listMailboxesShouldReturnUserMailboxes() throws Exception {
- Mailbox mailbox1 = new SimpleMailbox(new MailboxPath("#top", USER, "name1"), UID_VALIDITY);
- Mailbox mailbox2 = new SimpleMailbox(MailboxPath.forUser(USER, "name2"), UID_VALIDITY);
- Mailbox mailbox3 = new SimpleMailbox(MailboxPath.forUser("other_user", "name3"), UID_VALIDITY);
- Mailbox mailbox4 = new SimpleMailbox(MailboxPath.forUser(USER, "name4"), UID_VALIDITY);
- Mailbox mailbox5 = new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY);
- Mailbox mailbox6 = new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.toto"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox1);
- mapperFactory.createMailboxMapper(session).save(mailbox2);
- mapperFactory.createMailboxMapper(session).save(mailbox3);
- mapperFactory.createMailboxMapper(session).save(mailbox4);
- mapperFactory.createMailboxMapper(session).save(mailbox5);
- mapperFactory.createMailboxMapper(session).save(mailbox6);
- assertThat(mailboxManagerManagement.listMailboxes(USER)).containsOnly("name2", "name4", "INBOX", "INBOX.toto");
- }
-
- @Test(expected = NullPointerException.class)
- public void listMailboxesShouldThrowOnNullUserName() {
- mailboxManagerManagement.listMailboxes(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void listMailboxesShouldThrowOnEmptyUserName() {
- mailboxManagerManagement.listMailboxes("");
- }
-
- @Test
- public void deleteMailboxShouldDeleteGivenMailbox() throws Exception {
- mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
- mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
- assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
- }
-
- @Test
- public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception {
- Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
- }
-
- @Test
- public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception {
- Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
- }
-
- @Test
- public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception {
- Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
- assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
- }
-
- @Test
- public void importEmlFileToMailboxShouldImportEmlFileToGivenMailbox() throws Exception {
- Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "name"),
- UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
- mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER, "name", emlpath);
-
- assertThat(mapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(1);
- Iterator<MailboxMessage> iterator = mapperFactory.getMessageMapper(session).findInMailbox(mailbox,
- MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
- MailboxMessage mailboxMessage = iterator.next();
-
- assertThat(IOUtils.toString(new FileInputStream(new File(emlpath)), StandardCharsets.UTF_8))
- .isEqualTo(IOUtils.toString(mailboxMessage.getFullContent(), StandardCharsets.UTF_8));
- }
-
- @Test
- public void importEmlFileToMailboxShouldNotImportEmlFileWithWrongPathToGivenMailbox() throws Exception {
- Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "name"),
- UID_VALIDITY);
- mapperFactory.createMailboxMapper(session).save(mailbox);
- String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
- mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER, "name", "wrong_path" + emlpath);
-
- assertThat(mapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0);
- Iterator<MailboxMessage> iterator = mapperFactory.getMessageMapper(session).findInMailbox(mailbox,
- MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
- assertThat(iterator.hasNext()).isFalse();
- }
-
-
- @Test(expected = NullPointerException.class)
- public void deleteMailboxShouldThrowOnNullNamespace() {
- mailboxManagerManagement.deleteMailbox(null, "a", "a");
- }
-
- @Test(expected = NullPointerException.class)
- public void deleteMailboxShouldThrowOnNullUser() {
- mailboxManagerManagement.deleteMailbox("a", null, "a");
- }
-
- @Test(expected = NullPointerException.class)
- public void deleteMailboxShouldThrowOnNullName() {
- mailboxManagerManagement.deleteMailbox("a", "a", null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void deleteMailboxShouldThrowOnEmptyNamespace() {
- mailboxManagerManagement.deleteMailbox("", "a", "a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void deleteMailboxShouldThrowOnEmptyUser() {
- mailboxManagerManagement.deleteMailbox("a", "", "a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void deleteMailboxShouldThrowOnEmptyName() {
- mailboxManagerManagement.deleteMailbox("a", "a", "");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-adapter/src/test/resources/eml/frnog.eml
----------------------------------------------------------------------
diff --git a/server/container/mailbox-adapter/src/test/resources/eml/frnog.eml b/server/container/mailbox-adapter/src/test/resources/eml/frnog.eml
deleted file mode 100644
index ed3ec46..0000000
--- a/server/container/mailbox-adapter/src/test/resources/eml/frnog.eml
+++ /dev/null
@@ -1,17 +0,0 @@
-Message-ID: <556D7ED7.2090108>
-Date: Tue, 2 Jun 2015 12:00:55 +0200
-From: sender <se...@domain.com>
-MIME-Version: 1.0
-To: <li...@james.org>
-Content-Type: text/plain; charset="utf-8"; format=flowed
-Content-Transfer-Encoding: 8bit
-
-Bonjour
-
-
-Je cherche un partenaire.
-
-Merci d'avance !
-
-
-Cordialement,
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/pom.xml b/server/container/mailbox-jmx/pom.xml
new file mode 100644
index 0000000..32152f9
--- /dev/null
+++ b/server/container/mailbox-jmx/pom.xml
@@ -0,0 +1,93 @@
+<?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>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>james-server-mailbox-jmx</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Apache James :: Server :: Mailbox :: JMX</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-api</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>apache-james-mailbox-memory</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>james-server-util</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java
new file mode 100644
index 0000000..7769bc3
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.copier.MailboxCopier;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * {@link MailboxCopier} support via JMX
+ */
+public class MailboxCopierManagement implements MailboxCopierManagementMBean {
+
+ /**
+ * The Logger.
+ */
+ private static final Logger log = LoggerFactory.getLogger(MailboxCopierManagement.class.getName());
+
+ private MailboxCopier copier;
+ private MailboxManagerResolver resolver;
+
+ @Inject
+ public void setMailboxCopier(@Named("mailboxcopier") MailboxCopier copier) {
+ this.copier = copier;
+ }
+
+ @Inject
+ public void setMailboxManagerResolver(MailboxManagerResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ @Override
+ public Map<String, String> getMailboxManagerBeans() {
+ Map<String, String> bMap = new HashMap<>();
+ Map<String, MailboxManager> beans = resolver.getMailboxManagerBeans();
+
+ for (Map.Entry<String, MailboxManager> entry : beans.entrySet()) {
+ String name = entry.getValue().getClass().getName();
+ bMap.put(entry.getKey(), name);
+ }
+
+ return bMap;
+ }
+
+ @Override
+ public void copy(String srcBean, String dstBean) throws Exception {
+ if (srcBean.equals(dstBean)) {
+ throw new IllegalArgumentException("srcBean and dstBean can not have the same name!");
+ }
+ try {
+ copier.copyMailboxes(resolver.resolveMailboxManager(srcBean), resolver.resolveMailboxManager(dstBean));
+ } catch (MailboxManagerResolverException | MailboxException | IOException e) {
+ log.error("An exception occured during the copy process", e);
+ throw new Exception(e.getMessage());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java
new file mode 100644
index 0000000..e60e78d
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagementMBean.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.Map;
+
+/**
+ * Allow to copy {@link MailboxManager} contents from one to the other via JMX
+ */
+public interface MailboxCopierManagementMBean {
+
+ /**
+ * Return a {@link Map} which contains the bean name of the registered
+ * {@link MailboxManager} instances as keys and the classname of them as
+ * values
+ *
+ * @return managers
+ */
+ Map<String, String> getMailboxManagerBeans();
+
+ /**
+ * Copy from srcBean to dstBean all messages
+ *
+ * @param srcBean
+ * @param dstBean
+ * @throws Exception
+ * if copying failed
+ */
+ void copy(String srcBean, String dstBean) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
new file mode 100644
index 0000000..79d68db
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
@@ -0,0 +1,221 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.io.Closeable;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.util.MDCBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Preconditions;
+
+/**
+ * JMX managmenent for Mailboxes
+ */
+public class MailboxManagerManagement extends StandardMBean implements MailboxManagerManagementMBean {
+ private static final Logger LOGGER = LoggerFactory.getLogger(MailboxManagerManagement.class);
+
+ private MailboxManager mailboxManager;
+
+ @Inject
+ public void setMailboxManager(@Named("mailboxmanager") MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
+ }
+
+ public MailboxManagerManagement() throws NotCompliantMBeanException {
+ super(MailboxManagerManagementMBean.class);
+ }
+
+ @Override
+ public boolean deleteMailboxes(String username) {
+ checkString(username, "Username");
+ MailboxSession session = null;
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "deleteMailboxes")
+ .addContext("concernedUser", username)
+ .build()) {
+ session = mailboxManager.createSystemSession(username);
+ mailboxManager.startProcessingRequest(session);
+ List<MailboxMetaData> mList = retrieveAllUserMailboxes(session);
+ for (MailboxMetaData aMList : mList) {
+ mailboxManager.deleteMailbox(aMList.getPath(), session);
+ }
+ return true;
+ } catch (MailboxException e) {
+ LOGGER.error("Error while remove mailboxes for user {}", username, e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ closeSession(session);
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> listMailboxes(String username) {
+ checkString(username, "Username");
+ List<String> boxes = new ArrayList<>();
+ MailboxSession session = null;
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "listMailboxes")
+ .addContext("concernedUser", username)
+ .build()) {
+ session = mailboxManager.createSystemSession(username);
+ mailboxManager.startProcessingRequest(session);
+ List<MailboxMetaData> mList = retrieveAllUserMailboxes(session);
+ boxes = mList.stream()
+ .map(aMList -> aMList.getPath().getName())
+ .sorted()
+ .collect(Guavate.toImmutableList());
+ } catch (MailboxException e) {
+ LOGGER.error("Error list mailboxes for user {}", username, e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ closeSession(session);
+ }
+ return boxes;
+ }
+
+ @Override
+ public MailboxId createMailbox(String namespace, String user, String name) {
+ checkMailboxArguments(namespace, user, name);
+ MailboxSession session = null;
+ MailboxPath mailboxPath = new MailboxPath(namespace, user, name);
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "createMailbox")
+ .addContext("mailboxPath", mailboxPath.asString())
+ .build()) {
+ session = mailboxManager.createSystemSession(user);
+ mailboxManager.startProcessingRequest(session);
+ return mailboxManager.createMailbox(mailboxPath, session)
+ .orElseThrow(() -> new MailboxException("mailbox name is probably empty"));
+ } catch (Exception e) {
+ LOGGER.error("Unable to create mailbox", e);
+ throw new RuntimeException(e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ @Override
+ public void deleteMailbox(String namespace, String user, String name) {
+ checkMailboxArguments(namespace, user, name);
+ MailboxSession session = null;
+ MailboxPath mailboxPath = new MailboxPath(namespace, user, name);
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "deleteMailbox")
+ .addContext("mailboxPath", mailboxPath.asString())
+ .build()) {
+ session = mailboxManager.createSystemSession(user);
+ mailboxManager.startProcessingRequest(session);
+ mailboxManager.deleteMailbox(mailboxPath, session);
+ } catch (Exception e) {
+ LOGGER.error("Unable to create mailbox", e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ @Override
+ public void importEmlFileToMailbox(String namespace, String user, String name, String emlPath) {
+ checkMailboxArguments(namespace, user, name);
+ checkString(emlPath, "email file path name");
+
+ MailboxSession session = null;
+ MailboxPath mailboxPath = new MailboxPath(namespace, user, name);
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "importEmlFileToMailbox")
+ .addContext("mailboxPath", mailboxPath.asString())
+ .addContext("emlPath", emlPath)
+ .build()) {
+ session = mailboxManager.createSystemSession(user);
+ mailboxManager.startProcessingRequest(session);
+ MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, session);
+ InputStream emlFileAsStream = new FileInputStream(emlPath);
+ messageManager.appendMessage(MessageManager.AppendCommand.builder()
+ .recent()
+ .build(emlFileAsStream), session);
+ } catch (Exception e) {
+ LOGGER.error("Unable to create mailbox", e);
+ } finally {
+ closeSession(session);
+ }
+ }
+
+ private void closeSession(MailboxSession session) {
+ if (session != null) {
+ mailboxManager.endProcessingRequest(session);
+ try {
+ mailboxManager.logout(session, true);
+ } catch (MailboxException e) {
+ LOGGER.error("Can not log session out", e);
+ }
+ }
+ }
+
+ private List<MailboxMetaData> retrieveAllUserMailboxes(MailboxSession session) throws MailboxException {
+ return mailboxManager.search(
+ MailboxQuery.privateMailboxesBuilder(session)
+ .matchesAllMailboxNames()
+ .build(),
+ session);
+ }
+
+ private void checkMailboxArguments(String namespace, String user, String name) {
+ checkString(namespace, "mailbox path namespace");
+ checkString(user, "mailbox path user");
+ checkString(name, "mailbox name");
+ }
+
+ private void checkString(String argument, String role) {
+ Preconditions.checkNotNull(argument, "Provided " + role + " should not be null.");
+ Preconditions.checkArgument(!argument.equals(""), "Provided " + role + " should not be empty.");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
new file mode 100644
index 0000000..ca96dca
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.List;
+
+import org.apache.james.mailbox.model.MailboxId;
+
+/**
+ * JMX MBean for Mailbox management
+ */
+public interface MailboxManagerManagementMBean {
+
+ /**
+ * Delete all Mailboxes which belong to the user
+ *
+ * @param username
+ * @return successful
+ */
+ boolean deleteMailboxes(String username);
+
+ /**
+ * List all mailboxes for a user
+ *
+ * @param username
+ * @return mailboxes
+ */
+ List<String> listMailboxes(String username);
+
+ /**
+ * Create a mailbox
+ * @param namespace Namespace of the created mailbox
+ * @param user User of the created mailbox
+ * @param name Name of the created mailbox
+ */
+ MailboxId createMailbox(String namespace, String user, String name);
+
+ /**
+ * Delete the given mailbox
+ *
+ * @param namespace Namespace of the mailbox to delete
+ * @param user User the mailbox to delete belongs to
+ * @param name Name of the mailbox to delete
+ */
+ void deleteMailbox(String namespace, String user, String name);
+
+ /**
+ * Import Eml File to the given mailbox
+ *
+ * @param namespace
+ * Namespace of the mailbox to import email file
+ * @param user
+ * User the mailbox to import email file belongs to
+ * @param name
+ * Name of the mailbox to import email file
+ * @param emlpath
+ * Name of the email file of this URL
+ */
+ void importEmlFileToMailbox(String namespace, String user, String name, String emlpath);
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java
new file mode 100644
index 0000000..46c2088
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolver.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.Map;
+
+import org.apache.james.mailbox.MailboxManager;
+
+public interface MailboxManagerResolver {
+
+ MailboxManager resolveMailboxManager(String mailboxManagerClassName);
+
+ Map<String, MailboxManager> getMailboxManagerBeans();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java
new file mode 100644
index 0000000..d80f3ca
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+public class MailboxManagerResolverException extends RuntimeException {
+
+ public MailboxManagerResolverException() {
+ super();
+ }
+
+ public MailboxManagerResolverException(Throwable cause) {
+ super(cause);
+ }
+
+ public MailboxManagerResolverException(String message) {
+ super(message);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
new file mode 100644
index 0000000..a2bed78
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagement.java
@@ -0,0 +1,207 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.SerializableQuota;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
+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.util.MDCBuilder;
+
+import com.github.fge.lambdas.Throwing;
+
+public class QuotaManagement implements QuotaManagementMBean {
+
+ private final QuotaManager quotaManager;
+ private final MaxQuotaManager maxQuotaManager;
+ private final QuotaRootResolver quotaRootResolver;
+
+ @Inject
+ public QuotaManagement(QuotaManager quotaManager, MaxQuotaManager maxQuotaManager, QuotaRootResolver quotaRootResolver) {
+ this.quotaManager = quotaManager;
+ this.maxQuotaManager = maxQuotaManager;
+ this.quotaRootResolver = quotaRootResolver;
+ }
+
+ @Override
+ public String getQuotaRoot(String namespace, String user, String name) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getQuotaRoot")
+ .build()) {
+ return quotaRootResolver.getQuotaRoot(new MailboxPath(namespace, user, name)).getValue();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getMaxMessageCount")
+ .build()) {
+ return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxMessage(quotaRootResolver.fromString(quotaRoot)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getMaxStorage")
+ .build()) {
+ return SerializableQuotaValue.valueOf(maxQuotaManager.getMaxStorage(quotaRootResolver.fromString(quotaRoot)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuotaValue<QuotaCount> getGlobalMaxMessageCount() throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getGlobalMaxMessageCount")
+ .build()) {
+ return SerializableQuotaValue.valueOf(maxQuotaManager.getGlobalMaxMessage());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuotaValue<QuotaSize> getGlobalMaxStorage() throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getGlobalMaxStorage")
+ .build()) {
+ return SerializableQuotaValue.valueOf(maxQuotaManager.getGlobalMaxStorage());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "setMaxMessageCount")
+ .build()) {
+ maxMessageCount.toValue(QuotaCount::count, QuotaCount.unlimited())
+ .ifPresent(
+ Throwing.consumer((QuotaCount value) ->
+ maxQuotaManager.setMaxMessage(quotaRootResolver.fromString(quotaRoot), value))
+ .sneakyThrow());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "setMaxStorage")
+ .build()) {
+ maxSize.toValue(QuotaSize::size, QuotaSize.unlimited())
+ .ifPresent(
+ Throwing.consumer((QuotaSize value) ->
+ maxQuotaManager.setMaxStorage(quotaRootResolver.fromString(quotaRoot), value))
+ .sneakyThrow());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setGlobalMaxMessageCount(SerializableQuotaValue<QuotaCount> maxGlobalMessageCount) {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "setGlobalMaxMessageCount")
+ .build()) {
+ maxGlobalMessageCount
+ .toValue(QuotaCount::count, QuotaCount.unlimited())
+ .ifPresent(Throwing.consumer(maxQuotaManager::setGlobalMaxMessage).sneakyThrow());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void setGlobalMaxStorage(SerializableQuotaValue<QuotaSize> maxGlobalSize) {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "setGlobalMaxStorage")
+ .build()) {
+ maxGlobalSize
+ .toValue(QuotaSize::size, QuotaSize.unlimited())
+ .ifPresent(Throwing.consumer(maxQuotaManager::setGlobalMaxStorage).sneakyThrow());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuota<QuotaCount> getMessageCountQuota(String quotaRoot) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getMessageCountQuota")
+ .build()) {
+ return SerializableQuota.newInstance(quotaManager.getMessageQuota(quotaRootResolver.fromString(quotaRoot)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "getStorageQuota")
+ .build()) {
+ return SerializableQuota.newInstance(quotaManager.getStorageQuota(quotaRootResolver.fromString(quotaRoot)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
new file mode 100644
index 0000000..36ae9d1
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/QuotaManagementMBean.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.SerializableQuota;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
+
+public interface QuotaManagementMBean {
+ String getQuotaRoot(String namespace, String user, String name) throws MailboxException;
+
+ SerializableQuota<QuotaCount> getMessageCountQuota(String quotaRoot) throws MailboxException;
+
+ SerializableQuota<QuotaSize> getStorageQuota(String quotaRoot) throws MailboxException;
+
+ SerializableQuotaValue<QuotaCount> getMaxMessageCount(String quotaRoot) throws MailboxException;
+
+ SerializableQuotaValue<QuotaSize> getMaxStorage(String quotaRoot) throws MailboxException;
+
+ SerializableQuotaValue<QuotaCount> getGlobalMaxMessageCount() throws MailboxException;
+
+ SerializableQuotaValue<QuotaSize> getGlobalMaxStorage() throws MailboxException;
+
+ void setMaxMessageCount(String quotaRoot, SerializableQuotaValue<QuotaCount> maxMessageCount) throws MailboxException;
+
+ void setMaxStorage(String quotaRoot, SerializableQuotaValue<QuotaSize> maxSize) throws MailboxException;
+
+ void setGlobalMaxMessageCount(SerializableQuotaValue<QuotaCount> maxGlobalMessageCount) throws MailboxException;
+
+ void setGlobalMaxStorage(SerializableQuotaValue<QuotaSize> maxGlobalSize) throws MailboxException;
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
new file mode 100644
index 0000000..c5110a8
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagement.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.util.MDCBuilder;
+
+public class ReIndexerManagement implements ReIndexerManagementMBean {
+
+ private ReIndexer reIndexer;
+
+ @Inject
+ public void setReIndexer(@Named("reindexer") ReIndexer reIndexer) {
+ this.reIndexer = reIndexer;
+ }
+
+ @Override
+ public void reIndex(String namespace, String user, String name) throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "reIndex")
+ .build()) {
+ reIndexer.reIndex(new MailboxPath(namespace, user, name));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void reIndex() throws MailboxException {
+ try (Closeable closeable =
+ MDCBuilder.create()
+ .addContext(MDCBuilder.PROTOCOL, "CLI")
+ .addContext(MDCBuilder.ACTION, "reIndex")
+ .build()) {
+ reIndexer.reIndex();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java
new file mode 100644
index 0000000..ec923ae
--- /dev/null
+++ b/server/container/mailbox-jmx/src/main/java/org/apache/james/adapter/mailbox/ReIndexerManagementMBean.java
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import org.apache.james.mailbox.exception.MailboxException;
+
+public interface ReIndexerManagementMBean {
+
+ void reIndex(String namespace, String user, String name) throws MailboxException;
+
+ void reIndex() throws MailboxException;
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
new file mode 100644
index 0000000..39520e7
--- /dev/null
+++ b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java
@@ -0,0 +1,308 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Iterator;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MailboxManagementTest {
+
+ public static final String USER = "user";
+ public static final int UID_VALIDITY = 10;
+ public static final int LIMIT = 1;
+
+ private MailboxManagerManagement mailboxManagerManagement;
+ private MailboxSessionMapperFactory mapperFactory;
+ private MailboxSession session;
+
+ @Before
+ public void setUp() throws Exception {
+ StoreMailboxManager mailboxManager = new InMemoryIntegrationResources()
+ .createMailboxManager(new SimpleGroupMembershipResolver());
+ mapperFactory = mailboxManager.getMapperFactory();
+
+ mailboxManagerManagement = new MailboxManagerManagement();
+ mailboxManagerManagement.setMailboxManager(mailboxManager);
+ session = mailboxManager.createSystemSession("TEST");
+ }
+
+ @Test
+ public void deleteMailboxesShouldDeleteMailboxes() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test
+ public void deleteMailboxesShouldDeleteInbox() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test
+ public void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test
+ public void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
+ }
+
+ @Test
+ public void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
+ }
+
+ @Test
+ public void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, ""), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void deleteMailboxesShouldThrowOnNullUserName() throws Exception {
+ mailboxManagerManagement.deleteMailboxes(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deleteMailboxesShouldThrowOnEmptyUserName() throws Exception {
+ mailboxManagerManagement.deleteMailboxes("");
+ }
+
+ @Test
+ public void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY));
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailboxes(USER);
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test
+ public void createMailboxShouldCreateAMailbox() throws Exception {
+ mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+ assertThat(mapperFactory.createMailboxMapper(session).list()).hasSize(1);
+ assertThat(mapperFactory.createMailboxMapper(session).findMailboxByPath(MailboxPath.forUser(USER, "name"))).isNotNull();
+ }
+
+ @Test
+ public void createMailboxShouldThrowIfMailboxAlreadyExists() throws Exception {
+ MailboxPath path = MailboxPath.forUser(USER, "name");
+ Mailbox mailbox = new SimpleMailbox(path, UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+
+ assertThatThrownBy(() -> mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"))
+ .isInstanceOf(RuntimeException.class)
+ .hasCauseInstanceOf(MailboxExistsException.class);
+ }
+
+ @Test
+ public void createMailboxShouldNotCreateAdditionalMailboxesIfMailboxAlreadyExists() throws Exception {
+ MailboxPath path = MailboxPath.forUser(USER, "name");
+ Mailbox mailbox = new SimpleMailbox(path, UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createMailboxShouldThrowOnNullNamespace() {
+ mailboxManagerManagement.createMailbox(null, "a", "a");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createMailboxShouldThrowOnNullUser() {
+ mailboxManagerManagement.createMailbox("a", null, "a");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void createMailboxShouldThrowOnNullName() {
+ mailboxManagerManagement.createMailbox("a", "a", null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createMailboxShouldThrowOnEmptyNamespace() {
+ mailboxManagerManagement.createMailbox("", "a", "a");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createMailboxShouldThrowOnEmptyUser() {
+ mailboxManagerManagement.createMailbox("a", "", "a");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createMailboxShouldThrowOnEmptyName() {
+ mailboxManagerManagement.createMailbox("a", "a", "");
+ }
+
+ @Test
+ public void listMailboxesShouldReturnUserMailboxes() throws Exception {
+ Mailbox mailbox1 = new SimpleMailbox(new MailboxPath("#top", USER, "name1"), UID_VALIDITY);
+ Mailbox mailbox2 = new SimpleMailbox(MailboxPath.forUser(USER, "name2"), UID_VALIDITY);
+ Mailbox mailbox3 = new SimpleMailbox(MailboxPath.forUser("other_user", "name3"), UID_VALIDITY);
+ Mailbox mailbox4 = new SimpleMailbox(MailboxPath.forUser(USER, "name4"), UID_VALIDITY);
+ Mailbox mailbox5 = new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY);
+ Mailbox mailbox6 = new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.toto"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox1);
+ mapperFactory.createMailboxMapper(session).save(mailbox2);
+ mapperFactory.createMailboxMapper(session).save(mailbox3);
+ mapperFactory.createMailboxMapper(session).save(mailbox4);
+ mapperFactory.createMailboxMapper(session).save(mailbox5);
+ mapperFactory.createMailboxMapper(session).save(mailbox6);
+ assertThat(mailboxManagerManagement.listMailboxes(USER)).containsOnly("name2", "name4", "INBOX", "INBOX.toto");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void listMailboxesShouldThrowOnNullUserName() {
+ mailboxManagerManagement.listMailboxes(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void listMailboxesShouldThrowOnEmptyUserName() {
+ mailboxManagerManagement.listMailboxes("");
+ }
+
+ @Test
+ public void deleteMailboxShouldDeleteGivenMailbox() throws Exception {
+ mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY));
+ mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+ assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty();
+ }
+
+ @Test
+ public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+ }
+
+ @Test
+ public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+ }
+
+ @Test
+ public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name");
+ assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox);
+ }
+
+ @Test
+ public void importEmlFileToMailboxShouldImportEmlFileToGivenMailbox() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "name"),
+ UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
+ mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER, "name", emlpath);
+
+ assertThat(mapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(1);
+ Iterator<MailboxMessage> iterator = mapperFactory.getMessageMapper(session).findInMailbox(mailbox,
+ MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+ MailboxMessage mailboxMessage = iterator.next();
+
+ assertThat(IOUtils.toString(new FileInputStream(new File(emlpath)), StandardCharsets.UTF_8))
+ .isEqualTo(IOUtils.toString(mailboxMessage.getFullContent(), StandardCharsets.UTF_8));
+ }
+
+ @Test
+ public void importEmlFileToMailboxShouldNotImportEmlFileWithWrongPathToGivenMailbox() throws Exception {
+ Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "name"),
+ UID_VALIDITY);
+ mapperFactory.createMailboxMapper(session).save(mailbox);
+ String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile();
+ mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER, "name", "wrong_path" + emlpath);
+
+ assertThat(mapperFactory.getMessageMapper(session).countMessagesInMailbox(mailbox)).isEqualTo(0);
+ Iterator<MailboxMessage> iterator = mapperFactory.getMessageMapper(session).findInMailbox(mailbox,
+ MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+ assertThat(iterator.hasNext()).isFalse();
+ }
+
+
+ @Test(expected = NullPointerException.class)
+ public void deleteMailboxShouldThrowOnNullNamespace() {
+ mailboxManagerManagement.deleteMailbox(null, "a", "a");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void deleteMailboxShouldThrowOnNullUser() {
+ mailboxManagerManagement.deleteMailbox("a", null, "a");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void deleteMailboxShouldThrowOnNullName() {
+ mailboxManagerManagement.deleteMailbox("a", "a", null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deleteMailboxShouldThrowOnEmptyNamespace() {
+ mailboxManagerManagement.deleteMailbox("", "a", "a");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deleteMailboxShouldThrowOnEmptyUser() {
+ mailboxManagerManagement.deleteMailbox("a", "", "a");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void deleteMailboxShouldThrowOnEmptyName() {
+ mailboxManagerManagement.deleteMailbox("a", "a", "");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/mailbox-jmx/src/test/resources/eml/frnog.eml
----------------------------------------------------------------------
diff --git a/server/container/mailbox-jmx/src/test/resources/eml/frnog.eml b/server/container/mailbox-jmx/src/test/resources/eml/frnog.eml
new file mode 100644
index 0000000..ed3ec46
--- /dev/null
+++ b/server/container/mailbox-jmx/src/test/resources/eml/frnog.eml
@@ -0,0 +1,17 @@
+Message-ID: <556D7ED7.2090108>
+Date: Tue, 2 Jun 2015 12:00:55 +0200
+From: sender <se...@domain.com>
+MIME-Version: 1.0
+To: <li...@james.org>
+Content-Type: text/plain; charset="utf-8"; format=flowed
+Content-Transfer-Encoding: 8bit
+
+Bonjour
+
+
+Je cherche un partenaire.
+
+Merci d'avance !
+
+
+Cordialement,
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/container/spring/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index 00fc175..a4cf595 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -73,6 +73,10 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>james-server-mailbox-jmx</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>james-server-mailetcontainer-api</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 7b25899..766ff2b 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -50,6 +50,7 @@
<module>container/jetty</module>
<module>container/lifecycle-api</module>
<module>container/mailbox-adapter</module>
+ <module>container/mailbox-jmx</module>
<module>container/metrics/metrics-es-reporter</module>
<module>container/spring</module>
<module>container/util</module>
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 4315648..415f58c 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -66,8 +66,8 @@ import org.apache.james.mailbox.model.MailboxACL.Right;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.probe.ACLProbe;
import org.apache.james.mailbox.store.probe.QuotaProbe;
import org.apache.james.mime4j.dom.Message;
@@ -84,6 +84,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+
import io.restassured.RestAssured;
public abstract class GetMailboxesMethodTest {
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
index ceae1b3..5895a75 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
@@ -42,7 +42,7 @@ import org.apache.james.core.quota.QuotaSize;
import org.apache.james.jmap.api.access.AccessToken;
import org.apache.james.mailbox.DefaultMailboxes;
import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.probe.MailboxProbe;
import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.modules.QuotaProbesImpl;
@@ -54,6 +54,7 @@ import org.junit.Before;
import org.junit.Test;
import com.google.common.base.Strings;
+
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
index a3bf893..c7c3e4f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
@@ -52,7 +52,7 @@ import org.apache.james.mailbox.DefaultMailboxes;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.probe.MailboxProbe;
import org.apache.james.mailbox.store.probe.QuotaProbe;
import org.apache.james.modules.MailboxProbeImpl;
@@ -65,6 +65,7 @@ import org.junit.Before;
import org.junit.Test;
import com.google.common.collect.Iterables;
+
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
http://git-wip-us.apache.org/repos/asf/james-project/blob/1be65de5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index f49a9b4..ea604ab 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -91,8 +91,8 @@ import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageId;
import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
import org.apache.james.mailbox.store.probe.ACLProbe;
import org.apache.james.mailbox.store.probe.MailboxProbe;
import org.apache.james.mailbox.store.probe.QuotaProbe;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org