You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/08/06 03:19:31 UTC

[james-project] branch master updated (660f183 -> 9327cd9)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 660f183  JAMES-3624 RFC 8887 (JMAP over WebSocket) Request needs property 'id' (is 'requestId')
     new 3a97764  JAMES-3105 [REFACTORING] Using the MailboxCounter.empty static method
     new eeff96f  JAMES-3621 Mailbox webadmin routes - messageCount
     new 997bb57  JAMES-3621 Mailbox webadmin routes - unseenMessageCount
     new 9327cd9  JAMES-3621 Mailbox webadmin routes - Document - messageCount & unseenMessageCount

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../pages/distributed/operate/webadmin.adoc        |  36 ++++
 .../james/mailbox/model/MailboxCounters.java       |   8 +
 .../apache/james/mailbox/MailboxManagerTest.java   |   6 +-
 .../james/mailbox/model/MailboxCountersTest.java   |   6 +-
 .../cassandra/mail/CassandraMailboxCounterDAO.java |  10 +-
 .../cassandra/mail/CassandraMessageMapper.java     |   6 +-
 .../mail/CassandraMailboxCounterDAOTest.java       |  18 +-
 .../james/mailbox/store/StoreMailboxManager.java   |  14 +-
 .../james/mailbox/store/StoreMessageManager.java   |  12 +-
 .../james/jmap/draft/model/MailboxFactoryTest.java |  12 +-
 .../james/webadmin/routes/UserMailboxesRoutes.java |  83 +++++++
 .../webadmin/service/UserMailboxesService.java     |  14 ++
 .../webadmin/routes/UserMailboxesRoutesTest.java   | 238 ++++++++++++++++++++-
 src/site/markdown/server/manage-webadmin.md        |  37 ++++
 14 files changed, 424 insertions(+), 76 deletions(-)

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


[james-project] 03/04: JAMES-3621 Mailbox webadmin routes - unseenMessageCount

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 997bb5776ce445da47bda4c3af7f99c5d95d636f
Author: Tung TRAN <vt...@linagora.com>
AuthorDate: Mon Aug 2 17:40:26 2021 +0700

    JAMES-3621 Mailbox webadmin routes - unseenMessageCount
---
 .../james/webadmin/routes/UserMailboxesRoutes.java |  43 ++++++-
 .../webadmin/service/UserMailboxesService.java     |   8 ++
 .../webadmin/routes/UserMailboxesRoutesTest.java   | 136 +++++++++++++++++++++
 3 files changed, 186 insertions(+), 1 deletion(-)

diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
index ec25b8f..a20ae30 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
@@ -91,6 +91,7 @@ public class UserMailboxesRoutes implements Routes {
     public static final String USER_MAILBOXES_BASE = USERS_BASE + Constants.SEPARATOR + USER_NAME + Constants.SEPARATOR + MAILBOXES;
     public static final String SPECIFIC_MAILBOX = USER_MAILBOXES_BASE + Constants.SEPARATOR + MAILBOX_NAME;
     public static final String MESSAGE_COUNT_PATH = SPECIFIC_MAILBOX + "/messageCount";
+    public static final String UNSEEN_MESSAGE_COUNT_PATH = SPECIFIC_MAILBOX + "/unseenMessageCount";
 
     private final UserMailboxesService userMailboxesService;
     private final JsonTransformer jsonTransformer;
@@ -132,6 +133,8 @@ public class UserMailboxesRoutes implements Routes {
 
         reIndexMailboxesRoute()
             .ifPresent(route -> service.post(USER_MAILBOXES_BASE, route, jsonTransformer));
+
+        unseenMessageCount();
     }
 
     @GET
@@ -355,7 +358,7 @@ public class UserMailboxesRoutes implements Routes {
     })
     @ApiOperation(value = "Counting emails in a given mailbox.")
     @ApiResponses(value = {
-        @ApiResponse(code = HttpStatus.OK_200, message = "The number emails in a given mailbox", response = String.class),
+        @ApiResponse(code = HttpStatus.OK_200, message = "The number emails in a given mailbox", response = Long.class),
         @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
         @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
         @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Invalid get on user mailboxes"),
@@ -384,4 +387,42 @@ public class UserMailboxesRoutes implements Routes {
             }
         });
     }
+
+    @GET
+    @Path("/{mailboxName}/unseenMessageCount")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+        @ApiImplicitParam(required = true, dataType = "string", name = "mailboxName", paramType = "path")
+    })
+    @ApiOperation(value = "Counting unseen emails in a given mailbox.")
+    @ApiResponses(value = {
+        @ApiResponse(code = HttpStatus.OK_200, message = "The number unseen emails in a given mailbox", response = Long.class),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
+        @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Invalid get on user mailboxes"),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
+    })
+    public void unseenMessageCount() {
+        service.get(UNSEEN_MESSAGE_COUNT_PATH, (request, response) -> {
+            try {
+                return userMailboxesService.unseenMessageCount(getUsernameParam(request), new MailboxName(request.params(MAILBOX_NAME)));
+            } catch (IllegalStateException | MailboxNotFoundException e) {
+                LOGGER.info("Invalid get on user mailbox", e);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.NOT_FOUND)
+                    .message("Invalid get on user mailboxes")
+                    .cause(e)
+                    .haltError();
+            } catch (IllegalArgumentException | MailboxNameException e) {
+                LOGGER.info("Attempt to test existence of an invalid mailbox", e);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to test existence of an invalid mailbox")
+                    .cause(e)
+                    .haltError();
+            }
+        });
+    }
 }
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
index 395bf71..4a839d4 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
@@ -114,6 +114,14 @@ public class UserMailboxesService {
         return mailboxManager.getMailbox(MailboxPath.forUser(username, mailboxName.asString()), mailboxSession).getMessageCount(mailboxSession);
     }
 
+    public long unseenMessageCount(Username username, MailboxName mailboxName) throws UsersRepositoryException, MailboxException {
+        usernamePreconditions(username);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+        return mailboxManager.getMailbox(MailboxPath.forUser(username, mailboxName.asString()), mailboxSession)
+            .getMailboxCounters(mailboxSession)
+            .getUnseen();
+    }
+
     private Stream<MailboxPath> listChildren(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
         return listUserMailboxes(mailboxSession)
             .map(MailboxMetaData::getPath)
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 0ecaefc..4fc7201 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -23,6 +23,7 @@ import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.when;
 import static io.restassured.RestAssured.with;
 import static io.restassured.http.ContentType.JSON;
+import static javax.mail.Flags.Flag.SEEN;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 import static org.apache.james.webadmin.routes.UserMailboxesRoutes.USERS_BASE;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -978,6 +979,141 @@ class UserMailboxesRoutesTest {
                 .containsEntry("message", "Invalid get on user mailboxes")
                 .containsEntry("details", String.format("#private:%s:%s can not be found", USERNAME.asString(), MAILBOX_NAME));
         }
+
+        @Test
+        void getUnseenMessageCountShouldReturnZeroWhenMailBoxEmpty() {
+            with()
+                .put(MAILBOX_NAME);
+
+            String response = when()
+                .get(MAILBOX_NAME + "/unseenMessageCount")
+            .then()
+                .statusCode(OK_200)
+                .extract()
+                .body().asString();
+
+            assertThat(response)
+                .isEqualTo("0");
+        }
+
+        @Test
+        void getUnseenMessageCountShouldReturnZeroWhenMailBoxDoNotHaveAnyUnSeenEmail() {
+            with()
+                .put(MAILBOX_NAME);
+
+            MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, MAILBOX_NAME);
+            MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+
+            IntStream.range(0, 10)
+                .forEach(index -> {
+                    try {
+                        mailboxManager.getMailbox(mailboxPath, systemSession)
+                            .appendMessage(
+                                MessageManager.AppendCommand.builder()
+                                    .withFlags(new Flags(SEEN))
+                                    .build("header: value\r\n\r\nbody"),
+                                systemSession);
+                    } catch (MailboxException e) {
+                        LOGGER.warn("Error when append message " + e);
+                    }
+                });
+
+            String response = when()
+                .get(MAILBOX_NAME + "/unseenMessageCount")
+            .then()
+                .statusCode(OK_200)
+                .extract()
+                .body().asString();
+
+            assertThat(response)
+                .isEqualTo("0");
+        }
+
+        @Test
+        void getUnseenMessageCountShouldReturnNumberOfUnSeenEmails() {
+            with()
+                .put(MAILBOX_NAME);
+
+            MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, MAILBOX_NAME);
+            MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+
+            IntStream.range(0, 5)
+                .forEach(index -> {
+                    try {
+                        mailboxManager.getMailbox(mailboxPath, systemSession)
+                            .appendMessage(
+                                MessageManager.AppendCommand.builder()
+                                    .withFlags(new Flags(SEEN))
+                                    .build("header: value\r\n\r\nbody"),
+                                systemSession);
+                    } catch (MailboxException e) {
+                        LOGGER.warn("Error when append message " + e);
+                    }
+                });
+
+            IntStream.range(0, 10)
+                .forEach(index -> {
+                    try {
+                        mailboxManager.getMailbox(mailboxPath, systemSession)
+                            .appendMessage(
+                                MessageManager.AppendCommand.builder()
+                                    .build("header: value\r\n\r\nbody"),
+                                systemSession);
+                    } catch (MailboxException e) {
+                        LOGGER.warn("Error when append message " + e);
+                    }
+                });
+
+            String response = when()
+                .get(MAILBOX_NAME + "/unseenMessageCount")
+            .then()
+                .statusCode(OK_200)
+                .extract()
+                .body().asString();
+
+            assertThat(response)
+                .isEqualTo("10");
+        }
+
+        @Test
+        void getUnseenMessageCountShouldReturnErrorWhenUserIsNotFound() throws UsersRepositoryException {
+            when(usersRepository.contains(USERNAME)).thenReturn(false);
+
+            Map<String, Object> errors = when()
+                .get(MAILBOX_NAME + "/unseenMessageCount")
+            .then()
+                .statusCode(NOT_FOUND_404)
+                .contentType(JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", NOT_FOUND_404)
+                .containsEntry("type", ERROR_TYPE_NOTFOUND)
+                .containsEntry("message", "Invalid get on user mailboxes")
+                .containsEntry("details", "User does not exist");
+        }
+
+        @Test
+        void getUnseenMessageCountShouldReturnErrorWhenMailboxDoesNotExist() {
+            Map<String, Object> errors = when()
+                .get(MAILBOX_NAME + "/unseenMessageCount")
+            .then()
+                .statusCode(NOT_FOUND_404)
+                .contentType(JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", NOT_FOUND_404)
+                .containsEntry("type", ERROR_TYPE_NOTFOUND)
+                .containsEntry("message", "Invalid get on user mailboxes")
+                .containsEntry("details", String.format("#private:%s:%s can not be found", USERNAME.asString(), MAILBOX_NAME));
+        }
     }
 
     @Nested

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


[james-project] 02/04: JAMES-3621 Mailbox webadmin routes - messageCount

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit eeff96fe3914133c0e4298d7de8eab24e178506d
Author: Tung TRAN <vt...@linagora.com>
AuthorDate: Mon Aug 2 17:12:58 2021 +0700

    JAMES-3621 Mailbox webadmin routes - messageCount
---
 .../james/webadmin/routes/UserMailboxesRoutes.java | 42 ++++++++++
 .../webadmin/service/UserMailboxesService.java     |  6 ++
 .../webadmin/routes/UserMailboxesRoutesTest.java   | 96 ++++++++++++++++++++++
 3 files changed, 144 insertions(+)

diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
index 781f6ed..ec25b8f 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
@@ -36,6 +36,7 @@ import javax.ws.rs.Produces;
 
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.exception.MailboxNameException;
+import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.task.TaskManager;
 import org.apache.james.webadmin.Constants;
@@ -89,6 +90,7 @@ public class UserMailboxesRoutes implements Routes {
     public static final String USERS_BASE = "/users";
     public static final String USER_MAILBOXES_BASE = USERS_BASE + Constants.SEPARATOR + USER_NAME + Constants.SEPARATOR + MAILBOXES;
     public static final String SPECIFIC_MAILBOX = USER_MAILBOXES_BASE + Constants.SEPARATOR + MAILBOX_NAME;
+    public static final String MESSAGE_COUNT_PATH = SPECIFIC_MAILBOX + "/messageCount";
 
     private final UserMailboxesService userMailboxesService;
     private final JsonTransformer jsonTransformer;
@@ -126,6 +128,8 @@ public class UserMailboxesRoutes implements Routes {
 
         defineDeleteUserMailboxes();
 
+        messageCount();
+
         reIndexMailboxesRoute()
             .ifPresent(route -> service.post(USER_MAILBOXES_BASE, route, jsonTransformer));
     }
@@ -342,4 +346,42 @@ public class UserMailboxesRoutes implements Routes {
             }
         });
     }
+
+    @GET
+    @Path("/{mailboxName}/messageCount")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = true, dataType = "string", name = "username", paramType = "path"),
+        @ApiImplicitParam(required = true, dataType = "string", name = "mailboxName", paramType = "path")
+    })
+    @ApiOperation(value = "Counting emails in a given mailbox.")
+    @ApiResponses(value = {
+        @ApiResponse(code = HttpStatus.OK_200, message = "The number emails in a given mailbox", response = String.class),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
+        @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
+        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Invalid get on user mailboxes"),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
+    })
+    public void messageCount() {
+        service.get(MESSAGE_COUNT_PATH, (request, response) -> {
+            try {
+                return userMailboxesService.messageCount(getUsernameParam(request), new MailboxName(request.params(MAILBOX_NAME)));
+            } catch (IllegalStateException | MailboxNotFoundException e) {
+                LOGGER.info("Invalid get on user mailbox", e);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.NOT_FOUND_404)
+                    .type(ErrorType.NOT_FOUND)
+                    .message("Invalid get on user mailboxes")
+                    .cause(e)
+                    .haltError();
+            } catch (IllegalArgumentException | MailboxNameException e) {
+                LOGGER.info("Attempt to test existence of an invalid mailbox", e);
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.BAD_REQUEST_400)
+                    .type(ErrorType.INVALID_ARGUMENT)
+                    .message("Attempt to test existence of an invalid mailbox")
+                    .cause(e)
+                    .haltError();
+            }
+        });
+    }
 }
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
index 10f45c2..395bf71 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java
@@ -108,6 +108,12 @@ public class UserMailboxesService {
             .forEach(Throwing.consumer(path -> deleteMailbox(mailboxSession, path)));
     }
 
+    public long messageCount(Username username, MailboxName mailboxName) throws UsersRepositoryException, MailboxException {
+        usernamePreconditions(username);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+        return mailboxManager.getMailbox(MailboxPath.forUser(username, mailboxName.asString()), mailboxSession).getMessageCount(mailboxSession);
+    }
+
     private Stream<MailboxPath> listChildren(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
         return listUserMailboxes(mailboxSession)
             .map(MailboxMetaData::getPath)
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 12f2a1d..0ecaefc 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -49,6 +49,7 @@ import java.time.ZonedDateTime;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.IntStream;
 
 import javax.mail.Flags;
 
@@ -102,6 +103,7 @@ import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.task.Hostname;
 import org.apache.james.task.MemoryTaskManager;
 import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.dto.WebAdminUserReindexingTaskAdditionalInformationDTO;
@@ -119,6 +121,8 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -128,6 +132,8 @@ import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 class UserMailboxesRoutesTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(UserMailboxesRoutesTest.class);
+
     public static MailboxMetaData testMetadata(MailboxPath path, MailboxId mailboxId, char delimiter) {
         return new MailboxMetaData(path, mailboxId, delimiter, MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NONE, new MailboxACL(),
             MailboxCounters.empty(mailboxId));
@@ -180,6 +186,8 @@ class UserMailboxesRoutesTest {
     @Nested
     class NormalBehaviour {
 
+        private MailboxManager mailboxManager;
+
         @BeforeEach
         void setUp() throws Exception {
             InMemoryMailboxManager mailboxManager = InMemoryIntegrationResources.defaultResources().getMailboxManager();
@@ -188,6 +196,7 @@ class UserMailboxesRoutesTest {
             Mockito.when(searchIndex.deleteAll(any(), any())).thenReturn(Mono.empty());
 
             createServer(mailboxManager, mailboxManager.getMapperFactory(), new InMemoryId.Factory(), searchIndex);
+            this.mailboxManager = mailboxManager;
         }
 
         @Test
@@ -882,6 +891,93 @@ class UserMailboxesRoutesTest {
                     .containsKeys("mailboxId")
                     .containsEntry("mailboxName", MAILBOX_NAME));
         }
+
+        @Test
+        void getMessageCountShouldReturnZeroWhenMailBoxEmpty() {
+            with()
+                .put(MAILBOX_NAME);
+
+            String response = when()
+                .get(MAILBOX_NAME + "/messageCount")
+            .then()
+                .statusCode(OK_200)
+                .extract()
+                .body().asString();
+
+            assertThat(response)
+                .isEqualTo("0");
+        }
+
+        @Test
+        void getMessageCountShouldReturnTotalEmailsInMailBox() {
+            with()
+                .put(MAILBOX_NAME);
+
+            MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, MAILBOX_NAME);
+            MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+
+            IntStream.range(0, 10)
+                .forEach(index -> {
+                    try {
+                        mailboxManager.getMailbox(mailboxPath, systemSession)
+                            .appendMessage(
+                                MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
+                                systemSession);
+                    } catch (MailboxException e) {
+                        LOGGER.warn("Error when append message " + e);
+                    }
+                });
+
+            String response = when()
+                .get(MAILBOX_NAME + "/messageCount")
+            .then()
+                .statusCode(OK_200)
+                .extract()
+                .body().asString();
+
+            assertThat(response)
+                .isEqualTo("10");
+        }
+
+        @Test
+        void getMessageCountShouldReturnErrorWhenUserIsNotFound() throws UsersRepositoryException {
+            when(usersRepository.contains(USERNAME)).thenReturn(false);
+
+            Map<String, Object> errors = when()
+                .get(MAILBOX_NAME + "/messageCount")
+            .then()
+                .statusCode(NOT_FOUND_404)
+                .contentType(JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", NOT_FOUND_404)
+                .containsEntry("type", ERROR_TYPE_NOTFOUND)
+                .containsEntry("message", "Invalid get on user mailboxes")
+                .containsEntry("details", "User does not exist");
+        }
+
+        @Test
+        void getMessageCountShouldReturnErrorWhenMailboxDoesNotExist() {
+            Map<String, Object> errors = when()
+                .get(MAILBOX_NAME + "/messageCount")
+            .then()
+                .statusCode(NOT_FOUND_404)
+                .contentType(JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getMap(".");
+
+            assertThat(errors)
+                .containsEntry("statusCode", NOT_FOUND_404)
+                .containsEntry("type", ERROR_TYPE_NOTFOUND)
+                .containsEntry("message", "Invalid get on user mailboxes")
+                .containsEntry("details", String.format("#private:%s:%s can not be found", USERNAME.asString(), MAILBOX_NAME));
+        }
     }
 
     @Nested

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


[james-project] 01/04: JAMES-3105 [REFACTORING] Using the MailboxCounter.empty static method

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3a97764cad178cf39e4031516ec4542eb355e105
Author: Tung TRAN <vt...@linagora.com>
AuthorDate: Mon Aug 2 12:47:08 2021 +0700

    JAMES-3105 [REFACTORING] Using the MailboxCounter.empty static method
---
 .../apache/james/mailbox/model/MailboxCounters.java    |  8 ++++++++
 .../org/apache/james/mailbox/MailboxManagerTest.java   |  6 +-----
 .../james/mailbox/model/MailboxCountersTest.java       |  6 +-----
 .../cassandra/mail/CassandraMailboxCounterDAO.java     | 10 +---------
 .../mailbox/cassandra/mail/CassandraMessageMapper.java |  6 +-----
 .../cassandra/mail/CassandraMailboxCounterDAOTest.java | 18 +++---------------
 .../james/mailbox/store/StoreMailboxManager.java       | 14 ++------------
 .../james/mailbox/store/StoreMessageManager.java       | 12 ++----------
 .../james/jmap/draft/model/MailboxFactoryTest.java     | 12 ++----------
 .../james/webadmin/routes/UserMailboxesRoutesTest.java |  6 +-----
 10 files changed, 22 insertions(+), 76 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
index 854264d..0f136d4 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
@@ -80,6 +80,14 @@ public class MailboxCounters {
         return mailboxId -> count -> unseen -> new Builder.FinalStage(count, unseen, mailboxId);
     }
 
+    public static MailboxCounters empty(MailboxId mailboxId) {
+        return MailboxCounters.builder()
+            .mailboxId(mailboxId)
+            .count(0)
+            .unseen(0)
+            .build();
+    }
+
     private final MailboxId mailboxId;
     private final long count;
     private final long unseen;
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 4cce073..81e8c5c 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -1524,11 +1524,7 @@ public abstract class MailboxManagerTest<T extends MailboxManager> {
                 .getMailboxCounters(session2);
 
             assertThat(mailboxCounters)
-                .isEqualTo(MailboxCounters.builder()
-                    .mailboxId(mailboxIdInbox1.get())
-                    .count(0)
-                    .unseen(0)
-                    .build());
+                .isEqualTo(MailboxCounters.empty(mailboxIdInbox1.get()));
         }
 
         @Test
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
index d08b988..2105c96 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
@@ -43,11 +43,7 @@ class MailboxCountersTest {
                 .unseen(0)
                 .build()
                 .sanitize())
-            .isEqualTo(MailboxCounters.builder()
-                .mailboxId(MAILBOX_ID)
-                .count(0)
-                .unseen(0)
-                .build());
+            .isEqualTo(MailboxCounters.empty(MAILBOX_ID));
     }
 
     @Test
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
index 8c04502..0f1c242 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
@@ -118,7 +118,7 @@ public class CassandraMailboxCounterDAO {
         CassandraId mailboxId = (CassandraId) counters.getMailboxId();
 
         return retrieveMailboxCounters(mailboxId)
-            .defaultIfEmpty(emptyCounters(mailboxId))
+            .defaultIfEmpty(MailboxCounters.empty(mailboxId))
             .flatMap(storedCounters -> {
                 if (storedCounters.equals(counters)) {
                     return Mono.empty();
@@ -128,14 +128,6 @@ public class CassandraMailboxCounterDAO {
             });
     }
 
-    private MailboxCounters emptyCounters(CassandraId mailboxId) {
-        return MailboxCounters.builder()
-            .mailboxId(mailboxId)
-            .count(0)
-            .unseen(0)
-            .build();
-    }
-
     public Mono<Void> add(MailboxCounters counters) {
         CassandraId mailboxId = (CassandraId) counters.getMailboxId();
         return cassandraAsyncExecutor.executeVoid(
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 7e5f6ae..5f30513 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -165,11 +165,7 @@ public class CassandraMessageMapper implements MessageMapper {
 
     public Mono<MailboxCounters> readMailboxCounters(CassandraId mailboxId) {
         return mailboxCounterDAO.retrieveMailboxCounters(mailboxId)
-            .defaultIfEmpty(MailboxCounters.builder()
-                .mailboxId(mailboxId)
-                .count(0)
-                .unseen(0)
-                .build());
+            .defaultIfEmpty(MailboxCounters.empty(mailboxId));
     }
 
     private void readRepair(Mailbox mailbox, MailboxCounters counters) {
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
index e00c0e0..cf83c2f 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
@@ -242,11 +242,7 @@ class CassandraMailboxCounterDAOTest {
         testee.decrementUnseenAndCount(MAILBOX_ID).block();
 
         assertThat(testee.retrieveMailboxCounters(MAILBOX_ID).block())
-            .isEqualTo(MailboxCounters.builder()
-                .mailboxId(MAILBOX_ID)
-                .count(0)
-                .unseen(0)
-                .build());
+            .isEqualTo(MailboxCounters.empty(MAILBOX_ID));
     }
 
     @Test
@@ -259,11 +255,7 @@ class CassandraMailboxCounterDAOTest {
 
     @Test
     void resetCountersShouldNoopWhenZeroAndNoData() {
-        MailboxCounters counters = MailboxCounters.builder()
-            .mailboxId(MAILBOX_ID)
-            .count(0)
-            .unseen(0)
-            .build();
+        MailboxCounters counters = MailboxCounters.empty(MAILBOX_ID);
 
         testee.resetCounters(counters).block();
 
@@ -273,11 +265,7 @@ class CassandraMailboxCounterDAOTest {
 
     @Test
     void resetCountersShouldNoopWhenZeroAndZeroData() {
-        MailboxCounters counters = MailboxCounters.builder()
-            .mailboxId(MAILBOX_ID)
-            .count(0)
-            .unseen(0)
-            .build();
+        MailboxCounters counters = MailboxCounters.empty(MAILBOX_ID);
 
         testee.incrementUnseen(MAILBOX_ID).block();
         testee.decrementUnseen(MAILBOX_ID).block();
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index cf6816a..0c16ab3 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -697,24 +697,14 @@ public class StoreMailboxManager implements MailboxManager {
         Map<MailboxPath, Boolean> parentMap = parentMap(mailboxes, session);
         return mailboxFlux -> mailboxFlux
                 .map(Throwing.<Mailbox, MailboxMetaData>function(
-                    mailbox -> toMailboxMetadata(session, parentMap, mailbox, MailboxCounters
-                        .builder()
-                        .mailboxId(mailbox.getMailboxId())
-                        .count(0)
-                        .unseen(0)
-                        .build()))
+                    mailbox -> toMailboxMetadata(session, parentMap, mailbox, MailboxCounters.empty(mailbox.getMailboxId())))
                     .sneakyThrow());
     }
 
     private Mono<MailboxCounters> retrieveCounters(MessageMapper messageMapper, Mailbox mailbox, MailboxSession session) {
         return messageMapper.getMailboxCountersReactive(mailbox)
             .filter(Throwing.<MailboxCounters>predicate(counter -> storeRightManager.hasRight(mailbox, Right.Read, session)).sneakyThrow())
-            .switchIfEmpty(Mono.just(MailboxCounters
-                .builder()
-                .mailboxId(mailbox.getMailboxId())
-                .count(0)
-                .unseen(0)
-                .build()));
+            .switchIfEmpty(Mono.just(MailboxCounters.empty(mailbox.getMailboxId())));
     }
 
     private Flux<Mailbox> searchMailboxes(MailboxQuery mailboxQuery, MailboxSession session, Right right) {
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index a67b551..b0ce1b3 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -224,11 +224,7 @@ public class StoreMessageManager implements MessageManager {
         if (storeRightManager.hasRight(mailbox, MailboxACL.Right.Read, mailboxSession)) {
             return mapperFactory.createMessageMapper(mailboxSession).getMailboxCounters(mailbox);
         }
-        return MailboxCounters.builder()
-            .mailboxId(mailbox.getMailboxId())
-            .count(0)
-            .unseen(0)
-            .build();
+        return MailboxCounters.empty(mailbox.getMailboxId());
     }
 
 
@@ -237,11 +233,7 @@ public class StoreMessageManager implements MessageManager {
         if (storeRightManager.hasRight(mailbox, MailboxACL.Right.Read, mailboxSession)) {
             return mapperFactory.createMessageMapper(mailboxSession).getMailboxCountersReactive(mailbox);
         }
-        return Mono.just(MailboxCounters.builder()
-            .mailboxId(mailbox.getMailboxId())
-            .count(0)
-            .unseen(0)
-            .build());
+        return Mono.just(MailboxCounters.empty(mailbox.getMailboxId()));
     }
 
     /**
diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
index e2ee241..74cf8b0 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/MailboxFactoryTest.java
@@ -182,11 +182,7 @@ public class MailboxFactoryTest {
         Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath,
             Optional.of(ImmutableList.of(new MailboxMetaData(parentMailboxPath, parentId, DELIMITER,
                 MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NONE, new MailboxACL(),
-                MailboxCounters.builder()
-                    .mailboxId(parentId)
-                    .count(0)
-                    .unseen(0)
-                    .build()))),
+                MailboxCounters.empty(parentId)))),
             mailboxSession).block();
         assertThat(id).contains(parentId);
     }
@@ -223,11 +219,7 @@ public class MailboxFactoryTest {
                 MailboxMetaData.Children.NO_INFERIORS,
                 MailboxMetaData.Selectability.NONE,
                 MailboxACL.EMPTY,
-                MailboxCounters.builder()
-                    .mailboxId(preLoadedId)
-                    .count(0)
-                    .unseen(0)
-                    .build()))))
+                MailboxCounters.empty(preLoadedId)))))
             .build()
             .block();
 
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
index 5b26333..12f2a1d 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
@@ -130,11 +130,7 @@ import reactor.core.publisher.Mono;
 class UserMailboxesRoutesTest {
     public static MailboxMetaData testMetadata(MailboxPath path, MailboxId mailboxId, char delimiter) {
         return new MailboxMetaData(path, mailboxId, delimiter, MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NONE, new MailboxACL(),
-            MailboxCounters.builder()
-                .mailboxId(mailboxId)
-                .count(0)
-                .unseen(0)
-                .build());
+            MailboxCounters.empty(mailboxId));
     }
 
     private static final Username USERNAME = Username.of("username");

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


[james-project] 04/04: JAMES-3621 Mailbox webadmin routes - Document - messageCount & unseenMessageCount

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9327cd96a442751df83e1745ebd7ca75f9b5c2ea
Author: Tung TRAN <vt...@linagora.com>
AuthorDate: Mon Aug 2 18:04:32 2021 +0700

    JAMES-3621 Mailbox webadmin routes - Document - messageCount & unseenMessageCount
---
 .../pages/distributed/operate/webadmin.adoc        | 36 +++++++++++++++++++++
 .../james/webadmin/routes/UserMailboxesRoutes.java |  4 +--
 src/site/markdown/server/manage-webadmin.md        | 37 ++++++++++++++++++++++
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/docs/modules/servers/pages/distributed/operate/webadmin.adoc b/docs/modules/servers/pages/distributed/operate/webadmin.adoc
index 4674540..d7be9d1 100644
--- a/docs/modules/servers/pages/distributed/operate/webadmin.adoc
+++ b/docs/modules/servers/pages/distributed/operate/webadmin.adoc
@@ -1322,6 +1322,42 @@ Warning: While we have been trying to reduce the inconsistency window to
 a maximum (by keeping track of ongoing events), concurrent changes done
 during the reIndexing might be ignored.
 
+=== Counting emails
+
+....
+curl -XGET http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/messageCount
+....
+
+Will return the total count of messages within the mailbox of that user.
+
+Resource name `usernameToBeUsed` should be an existing user.
+
+Resource name `mailboxName` should not be empty, nor contain `% *` characters, nor starting with `#`.
+
+Response codes:
+
+* 200: The number of emails in a given mailbox
+* 400: Invalid mailbox name
+* 404: Invalid get on user mailboxes. The `usernameToBeUsed` or `mailboxName` does not exit'
+
+=== Counting unseen emails
+
+....
+curl -XGET http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/unseenMessageCount
+....
+
+Will return the total count of unseen messages within the mailbox of that user.
+
+Resource name `usernameToBeUsed` should be an existing user.
+
+Resource name `mailboxName` should not be empty, nor contain `% *` characters, nor starting with `#`.
+
+Response codes:
+
+* 200: The number of unseen emails in a given mailbox
+* 400: Invalid mailbox name
+* 404: Invalid get on user mailboxes. The `usernameToBeUsed` or `mailboxName` does not exit'
+
 === Subscribing a user to all of its mailboxes
 
 ....
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
index a20ae30..092c2c6 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
@@ -358,7 +358,7 @@ public class UserMailboxesRoutes implements Routes {
     })
     @ApiOperation(value = "Counting emails in a given mailbox.")
     @ApiResponses(value = {
-        @ApiResponse(code = HttpStatus.OK_200, message = "The number emails in a given mailbox", response = Long.class),
+        @ApiResponse(code = HttpStatus.OK_200, message = "The number of emails in a given mailbox", response = Long.class),
         @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
         @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
         @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Invalid get on user mailboxes"),
@@ -396,7 +396,7 @@ public class UserMailboxesRoutes implements Routes {
     })
     @ApiOperation(value = "Counting unseen emails in a given mailbox.")
     @ApiResponses(value = {
-        @ApiResponse(code = HttpStatus.OK_200, message = "The number unseen emails in a given mailbox", response = Long.class),
+        @ApiResponse(code = HttpStatus.OK_200, message = "The number of unseen emails in a given mailbox", response = Long.class),
         @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Invalid mailbox name"),
         @ApiResponse(code = HttpStatus.UNAUTHORIZED_401, message = "Unauthorized. The user is not authenticated on the platform"),
         @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "Invalid get on user mailboxes"),
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 00b69a5..936f82c 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -990,6 +990,8 @@ by an admin to ensure Cassandra message consistency.
  - [Exporting user mailboxes](#Exporting_user_mailboxes)
  - [ReIndexing a user mails](#ReIndexing_a_user_mails)
  - [Recomputing User JMAP fast message view projection](#Recomputing_User_JMAP_fast_message_view_projection)
+ - [Counting emails](#Counting_emails)
+ - [Counting unseen emails](#Couting_unseen_emails)
 
 ### Creating a mailbox
 
@@ -1167,6 +1169,41 @@ Warning: Canceling this task should be considered unsafe as it will leave the cu
 Warning: While we have been trying to reduce the inconsistency window to a maximum (by keeping track of ongoing events),
 concurrent changes done during the reIndexing might be ignored.
 
+### Counting emails
+
+```bash
+curl -XGET http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/messageCount
+```
+
+Will return the total count of messages within the mailbox of that user.
+
+Resource name `usernameToBeUsed` should be an existing user.    
+Resource name `mailboxName` should not be empty, nor contain `% *` characters, nor starting with `#`.
+
+Response codes:
+
+- 200: The number of emails in a given mailbox
+- 400: Invalid mailbox name
+- 404: Invalid get on user mailboxes. The `usernameToBeUsed` or `mailboxName` does not exit'
+
+### Counting unseen emails
+
+```bash
+curl -XGET http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/unseenMessageCount
+```
+
+Will return the total count of unseen messages within the mailbox of that user.
+
+Resource name `usernameToBeUsed` should be an existing user.    
+Resource name `mailboxName` should not be empty, nor contain `% *` characters, nor starting with `#`.
+
+Response codes:
+
+- 200: The number of unseen emails in a given mailbox
+- 400: Invalid mailbox name
+- 404: Invalid get on user mailboxes. The `usernameToBeUsed` or `mailboxName` does not exit'
+
+
 ### Subscribing a user to all of its mailboxes
  
 ```

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