@Test public void listMails_withLastMatchOnly() throws Exception { HttpResponse response = apiClient.listMails(mailboxAddress, true); RestApiTestUtils.validateStatusCode(response, 200); MailData[] mailDatas = RestApiTestUtils.getResponseBodyAs(response, MailData[].class); Assert.assertEquals(1, mailDatas.length); Assert.assertEquals(mailWithAttachments.getSubject(), mailDatas[0].subject); }
public Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) throws Exception { final boolean lastMatch = context.getParameterAs("lastMatch", boolean.class, false); final Pattern senderPattern = createPatternFromParameter("from", context); final Pattern subjectPattern = createPatternFromParameter("subject", context); final Pattern plainTextPattern = createPatternFromParameter("textContent", context); final Pattern htmlTextPattern = createPatternFromParameter("htmlContent", context); final Pattern headerPattern = createPatternFromParameter("mailHeader", context); final Validation validation = context.getValidation(); if (validation.hasViolations()) { return ApiResults.badRequest(validation.getViolations()); } final MBox mailbox = MBox.getByAddress(mailboxAddress); if (mailbox == null) { return ApiResults.notFound(); } if (mailbox.getUsr().getId() != userId) { return ApiResults.forbidden("mailboxAddress", "Mailbox belongs to another user."); } return findAndFilterMails(mailbox, context, lastMatch, senderPattern, subjectPattern, plainTextPattern, htmlTextPattern, headerPattern); }
MailApiController extends AbstractApiController { public Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) throws Exception { final boolean lastMatch = context.getParameterAs("lastMatch", boolean.class, false); final Pattern senderPattern = createPatternFromParameter("from", context); final Pattern subjectPattern = createPatternFromParameter("subject", context); final Pattern plainTextPattern = createPatternFromParameter("textContent", context); final Pattern htmlTextPattern = createPatternFromParameter("htmlContent", context); final Pattern headerPattern = createPatternFromParameter("mailHeader", context); final Validation validation = context.getValidation(); if (validation.hasViolations()) { return ApiResults.badRequest(validation.getViolations()); } final MBox mailbox = MBox.getByAddress(mailboxAddress); if (mailbox == null) { return ApiResults.notFound(); } if (mailbox.getUsr().getId() != userId) { return ApiResults.forbidden("mailboxAddress", "Mailbox belongs to another user."); } return findAndFilterMails(mailbox, context, lastMatch, senderPattern, subjectPattern, plainTextPattern, htmlTextPattern, headerPattern); } }
MailApiController extends AbstractApiController { public Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) throws Exception { final boolean lastMatch = context.getParameterAs("lastMatch", boolean.class, false); final Pattern senderPattern = createPatternFromParameter("from", context); final Pattern subjectPattern = createPatternFromParameter("subject", context); final Pattern plainTextPattern = createPatternFromParameter("textContent", context); final Pattern htmlTextPattern = createPatternFromParameter("htmlContent", context); final Pattern headerPattern = createPatternFromParameter("mailHeader", context); final Validation validation = context.getValidation(); if (validation.hasViolations()) { return ApiResults.badRequest(validation.getViolations()); } final MBox mailbox = MBox.getByAddress(mailboxAddress); if (mailbox == null) { return ApiResults.notFound(); } if (mailbox.getUsr().getId() != userId) { return ApiResults.forbidden("mailboxAddress", "Mailbox belongs to another user."); } return findAndFilterMails(mailbox, context, lastMatch, senderPattern, subjectPattern, plainTextPattern, htmlTextPattern, headerPattern); }  }
MailApiController extends AbstractApiController { public Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) throws Exception { final boolean lastMatch = context.getParameterAs("lastMatch", boolean.class, false); final Pattern senderPattern = createPatternFromParameter("from", context); final Pattern subjectPattern = createPatternFromParameter("subject", context); final Pattern plainTextPattern = createPatternFromParameter("textContent", context); final Pattern htmlTextPattern = createPatternFromParameter("htmlContent", context); final Pattern headerPattern = createPatternFromParameter("mailHeader", context); final Validation validation = context.getValidation(); if (validation.hasViolations()) { return ApiResults.badRequest(validation.getViolations()); } final MBox mailbox = MBox.getByAddress(mailboxAddress); if (mailbox == null) { return ApiResults.notFound(); } if (mailbox.getUsr().getId() != userId) { return ApiResults.forbidden("mailboxAddress", "Mailbox belongs to another user."); } return findAndFilterMails(mailbox, context, lastMatch, senderPattern, subjectPattern, plainTextPattern, htmlTextPattern, headerPattern); }  Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress,
                            @Attribute("userId") @DbId final Long userId, final Context context); Result getMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId,
                          final Context context); Result getMailAttachment(@PathParam("mailId") @DbId final Long mailId,
                                    @PathParam("attachmentName") @NotBlank final String attachmentName,
                                    @Attribute("userId") @DbId final Long userId, final Context context); Result deleteMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId,
                             final Context context); }
MailApiController extends AbstractApiController { public Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress, @Attribute("userId") @DbId final Long userId, final Context context) throws Exception { final boolean lastMatch = context.getParameterAs("lastMatch", boolean.class, false); final Pattern senderPattern = createPatternFromParameter("from", context); final Pattern subjectPattern = createPatternFromParameter("subject", context); final Pattern plainTextPattern = createPatternFromParameter("textContent", context); final Pattern htmlTextPattern = createPatternFromParameter("htmlContent", context); final Pattern headerPattern = createPatternFromParameter("mailHeader", context); final Validation validation = context.getValidation(); if (validation.hasViolations()) { return ApiResults.badRequest(validation.getViolations()); } final MBox mailbox = MBox.getByAddress(mailboxAddress); if (mailbox == null) { return ApiResults.notFound(); } if (mailbox.getUsr().getId() != userId) { return ApiResults.forbidden("mailboxAddress", "Mailbox belongs to another user."); } return findAndFilterMails(mailbox, context, lastMatch, senderPattern, subjectPattern, plainTextPattern, htmlTextPattern, headerPattern); }  Result listMails(@Param("mailboxAddress") @Email final String mailboxAddress,
                            @Attribute("userId") @DbId final Long userId, final Context context); Result getMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId,
                          final Context context); Result getMailAttachment(@PathParam("mailId") @DbId final Long mailId,
                                    @PathParam("attachmentName") @NotBlank final String attachmentName,
                                    @Attribute("userId") @DbId final Long userId, final Context context); Result deleteMail(@PathParam("mailId") @DbId final Long mailId, @Attribute("userId") @DbId final Long userId,
                             final Context context);  }