@Test public void testQueryAllMailboxes() throws Exception { user.setApiToken("validToken"); user.save(); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/create/temporaryMail/" + user.getApiToken() + "/queryallmails@xcmailr.test/11"); assertTrue(result.contains("<div id=\"createdMail\">")); user = User.getById(user.getId()); List<MBox> mailBoxes = user.getBoxes(); assertTrue(mailBoxes.size() == 1); final MBox tempMBox = mailBoxes.get(0); createMail(tempMBox); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/mails?format=html"); assertTrue(result.contains("WARNING: Emails will be available for only 10 minutes upon receipt and deleted afterwards.")); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/mails?format=json"); assertTrue(result.equals("{\"total\":1,\"rows\":[]}")); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/mails?format=json&offset=0&limit=1"); final JsonNode node = new ObjectMapper().readTree(result); assertTrue(node.isObject()); assertEquals(1, node.get("total").asInt()); final JsonNode rows = node.get("rows"); assertTrue(rows.isArray()); assertEquals(1, rows.size()); final JsonNode firstRow = rows.get(0); assertTrue(firstRow.isObject()); assertEquals("queryallmails@xcmailr.test", firstRow.get("mailAddress").asText()); assertEquals("someone@notyou.net", firstRow.get("sender").asText()); assertEquals("No Subject", firstRow.get("subject").asText()); assertEquals(1546300800, firstRow.get("receivedTime").asLong()); assertEquals("", firstRow.get("textContent").asText()); assertEquals("", firstRow.get("htmlContent").asText()); assertEquals(0, firstRow.get("attachments").size()); assertTrue(firstRow.get("downloadToken").isNull()); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/mails?format=csv"); assertTrue(result.contains(NinjaConstant.I18N_NINJA_SYSTEM_BAD_REQUEST_TEXT_DEFAULT.replace("''", "&#39;"))); result = ninjaTestBrowser.makeRequest(ninjaTestServer.getBaseUrl() + "/mails?format=json&search=something"); assertTrue(result.equals("{\"total\":1,\"rows\":[]}")); }
@FilterWith(SecureFilter.class) public Result queryAllMailboxes(Context context, @Param("offset") final Integer offset, @Param("limit") final Integer limit, @Param("sort") String sort, @Param("order") String order, @Param("search") String search) throws Exception { final String formatParameter = context.getParameter("format", "html").toLowerCase(); if ("html".equals(formatParameter)) { return Results.html(); } else if ("json".equals(formatParameter)) { final int iOffset = offset == null ? 0 : Math.max(0, offset); final int iLimit = limit == null ? 0 : Math.max(limit, 1); sort = getOrderColumn(sort); order = getOrderDirection(order); final User user = context.getAttribute("user", User.class); final List<?> mailboxIds = Ebean.find(MBox.class).where().eq("usr_id", user.getId()).findIds(); final List<Mail> mails = Ebean.find(Mail.class).where().in("mailbox_id", mailboxIds) .orderBy(sort + " " + order).findList(); final List<MailboxEntry> matches = new ArrayList<>(); for (Mail mail : mails) { final MailboxEntry mailboxEntry = new MailboxEntry(mail.getMailbox().getFullAddress(), mail); if (StringUtils.isBlank(search) || mailboxEntry.matchesSearchPhrase(search)) { matches.add(mailboxEntry); } } final int nbMatches = matches.size(); final List<MailboxEntry> result; if (iOffset >= nbMatches || iLimit == 0) { result = Collections.emptyList(); } else { result = matches.subList(iOffset, Math.min(iOffset + iLimit, nbMatches)); } return Results.json().render("rows", result).render("total", mails.size()); } else { return ninja.getBadRequestResult(context, null); } }
BoxHandler { @FilterWith(SecureFilter.class) public Result queryAllMailboxes(Context context, @Param("offset") final Integer offset, @Param("limit") final Integer limit, @Param("sort") String sort, @Param("order") String order, @Param("search") String search) throws Exception { final String formatParameter = context.getParameter("format", "html").toLowerCase(); if ("html".equals(formatParameter)) { return Results.html(); } else if ("json".equals(formatParameter)) { final int iOffset = offset == null ? 0 : Math.max(0, offset); final int iLimit = limit == null ? 0 : Math.max(limit, 1); sort = getOrderColumn(sort); order = getOrderDirection(order); final User user = context.getAttribute("user", User.class); final List<?> mailboxIds = Ebean.find(MBox.class).where().eq("usr_id", user.getId()).findIds(); final List<Mail> mails = Ebean.find(Mail.class).where().in("mailbox_id", mailboxIds) .orderBy(sort + " " + order).findList(); final List<MailboxEntry> matches = new ArrayList<>(); for (Mail mail : mails) { final MailboxEntry mailboxEntry = new MailboxEntry(mail.getMailbox().getFullAddress(), mail); if (StringUtils.isBlank(search) || mailboxEntry.matchesSearchPhrase(search)) { matches.add(mailboxEntry); } } final int nbMatches = matches.size(); final List<MailboxEntry> result; if (iOffset >= nbMatches || iLimit == 0) { result = Collections.emptyList(); } else { result = matches.subList(iOffset, Math.min(iOffset + iLimit, nbMatches)); } return Results.json().render("rows", result).render("total", mails.size()); } else { return ninja.getBadRequestResult(context, null); } } }
BoxHandler { @FilterWith(SecureFilter.class) public Result queryAllMailboxes(Context context, @Param("offset") final Integer offset, @Param("limit") final Integer limit, @Param("sort") String sort, @Param("order") String order, @Param("search") String search) throws Exception { final String formatParameter = context.getParameter("format", "html").toLowerCase(); if ("html".equals(formatParameter)) { return Results.html(); } else if ("json".equals(formatParameter)) { final int iOffset = offset == null ? 0 : Math.max(0, offset); final int iLimit = limit == null ? 0 : Math.max(limit, 1); sort = getOrderColumn(sort); order = getOrderDirection(order); final User user = context.getAttribute("user", User.class); final List<?> mailboxIds = Ebean.find(MBox.class).where().eq("usr_id", user.getId()).findIds(); final List<Mail> mails = Ebean.find(Mail.class).where().in("mailbox_id", mailboxIds) .orderBy(sort + " " + order).findList(); final List<MailboxEntry> matches = new ArrayList<>(); for (Mail mail : mails) { final MailboxEntry mailboxEntry = new MailboxEntry(mail.getMailbox().getFullAddress(), mail); if (StringUtils.isBlank(search) || mailboxEntry.matchesSearchPhrase(search)) { matches.add(mailboxEntry); } } final int nbMatches = matches.size(); final List<MailboxEntry> result; if (iOffset >= nbMatches || iLimit == 0) { result = Collections.emptyList(); } else { result = matches.subList(iOffset, Math.min(iOffset + iLimit, nbMatches)); } return Results.json().render("rows", result).render("total", mails.size()); } else { return ninja.getBadRequestResult(context, null); } }  }
BoxHandler { @FilterWith(SecureFilter.class) public Result queryAllMailboxes(Context context, @Param("offset") final Integer offset, @Param("limit") final Integer limit, @Param("sort") String sort, @Param("order") String order, @Param("search") String search) throws Exception { final String formatParameter = context.getParameter("format", "html").toLowerCase(); if ("html".equals(formatParameter)) { return Results.html(); } else if ("json".equals(formatParameter)) { final int iOffset = offset == null ? 0 : Math.max(0, offset); final int iLimit = limit == null ? 0 : Math.max(limit, 1); sort = getOrderColumn(sort); order = getOrderDirection(order); final User user = context.getAttribute("user", User.class); final List<?> mailboxIds = Ebean.find(MBox.class).where().eq("usr_id", user.getId()).findIds(); final List<Mail> mails = Ebean.find(Mail.class).where().in("mailbox_id", mailboxIds) .orderBy(sort + " " + order).findList(); final List<MailboxEntry> matches = new ArrayList<>(); for (Mail mail : mails) { final MailboxEntry mailboxEntry = new MailboxEntry(mail.getMailbox().getFullAddress(), mail); if (StringUtils.isBlank(search) || mailboxEntry.matchesSearchPhrase(search)) { matches.add(mailboxEntry); } } final int nbMatches = matches.size(); final List<MailboxEntry> result; if (iOffset >= nbMatches || iLimit == 0) { result = Collections.emptyList(); } else { result = matches.subList(iOffset, Math.min(iOffset + iLimit, nbMatches)); } return Results.json().render("rows", result).render("total", mails.size()); } else { return ninja.getBadRequestResult(context, null); } }  @FilterWith(SecureFilter.class) Result deleteBoxDialog(); @FilterWith(SecureFilter.class) Result editBoxDialog(); @FilterWith(SecureFilter.class) Result newDateDialog(); @FilterWith(SecureFilter.class) Result showAngularBoxOverview(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonData(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonProcess(Context context, @JSR303Validation MBox addBoxDialogData, Validation validation); @FilterWith(JsonSecureFilter.class) Result bulkDeleteBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkDisableBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkEnablePossibleBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkNewDate(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkResetBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result deleteBoxByJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result editBoxJson(Context context, @PathParam("id") Long boxId, @JSR303Validation MBox mailboxFormData,
                              Validation validation); @FilterWith(JsonSecureFilter.class) Result expireBoxJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result jsonBox(Context context); @FilterWith(JsonSecureFilter.class) Result jsonDomainList(Context context); @FilterWith(JsonSecureFilter.class) Result resetBoxCounterProcessXhr(@PathParam("id") Long boxId, Context context); @FilterWith(SecureFilter.class) Result showMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showActiveMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showSelectedMailsAsTextList(@Param("jsonObj") String inputList, Context context); Result createTemporaryMailAddress(@PathParam("token") String apiToken,
                                             @PathParam("mailAddress") String desiredMailAddress,
                                             @PathParam("validTime") String validTime, Context context); Result queryMailbox(@PathParam("token") String apiToken, @PathParam("mailAddress") String mailAddress,
                               Context context); @FilterWith(SecureFilter.class) Result queryAllMailboxes(Context context, @Param("offset") final Integer offset,
                                    @Param("limit") final Integer limit, @Param("sort") String sort,
                                    @Param("order") String order, @Param("search") String search); @FilterWith(SecureFilter.class) Result downloadMailAttachment(Context context, @PathParam("downloadToken") String downloadToken,
                                         @PathParam("filename") String filename); }
BoxHandler { @FilterWith(SecureFilter.class) public Result queryAllMailboxes(Context context, @Param("offset") final Integer offset, @Param("limit") final Integer limit, @Param("sort") String sort, @Param("order") String order, @Param("search") String search) throws Exception { final String formatParameter = context.getParameter("format", "html").toLowerCase(); if ("html".equals(formatParameter)) { return Results.html(); } else if ("json".equals(formatParameter)) { final int iOffset = offset == null ? 0 : Math.max(0, offset); final int iLimit = limit == null ? 0 : Math.max(limit, 1); sort = getOrderColumn(sort); order = getOrderDirection(order); final User user = context.getAttribute("user", User.class); final List<?> mailboxIds = Ebean.find(MBox.class).where().eq("usr_id", user.getId()).findIds(); final List<Mail> mails = Ebean.find(Mail.class).where().in("mailbox_id", mailboxIds) .orderBy(sort + " " + order).findList(); final List<MailboxEntry> matches = new ArrayList<>(); for (Mail mail : mails) { final MailboxEntry mailboxEntry = new MailboxEntry(mail.getMailbox().getFullAddress(), mail); if (StringUtils.isBlank(search) || mailboxEntry.matchesSearchPhrase(search)) { matches.add(mailboxEntry); } } final int nbMatches = matches.size(); final List<MailboxEntry> result; if (iOffset >= nbMatches || iLimit == 0) { result = Collections.emptyList(); } else { result = matches.subList(iOffset, Math.min(iOffset + iLimit, nbMatches)); } return Results.json().render("rows", result).render("total", mails.size()); } else { return ninja.getBadRequestResult(context, null); } }  @FilterWith(SecureFilter.class) Result deleteBoxDialog(); @FilterWith(SecureFilter.class) Result editBoxDialog(); @FilterWith(SecureFilter.class) Result newDateDialog(); @FilterWith(SecureFilter.class) Result showAngularBoxOverview(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonData(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonProcess(Context context, @JSR303Validation MBox addBoxDialogData, Validation validation); @FilterWith(JsonSecureFilter.class) Result bulkDeleteBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkDisableBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkEnablePossibleBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkNewDate(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkResetBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result deleteBoxByJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result editBoxJson(Context context, @PathParam("id") Long boxId, @JSR303Validation MBox mailboxFormData,
                              Validation validation); @FilterWith(JsonSecureFilter.class) Result expireBoxJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result jsonBox(Context context); @FilterWith(JsonSecureFilter.class) Result jsonDomainList(Context context); @FilterWith(JsonSecureFilter.class) Result resetBoxCounterProcessXhr(@PathParam("id") Long boxId, Context context); @FilterWith(SecureFilter.class) Result showMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showActiveMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showSelectedMailsAsTextList(@Param("jsonObj") String inputList, Context context); Result createTemporaryMailAddress(@PathParam("token") String apiToken,
                                             @PathParam("mailAddress") String desiredMailAddress,
                                             @PathParam("validTime") String validTime, Context context); Result queryMailbox(@PathParam("token") String apiToken, @PathParam("mailAddress") String mailAddress,
                               Context context); @FilterWith(SecureFilter.class) Result queryAllMailboxes(Context context, @Param("offset") final Integer offset,
                                    @Param("limit") final Integer limit, @Param("sort") String sort,
                                    @Param("order") String order, @Param("search") String search); @FilterWith(SecureFilter.class) Result downloadMailAttachment(Context context, @PathParam("downloadToken") String downloadToken,
                                         @PathParam("filename") String filename);  }