public static String getMailboxId(AccessToken accessToken, Role role) { return getAllMailboxesIds(accessToken).stream() .filter(x -> x.get("role").equalsIgnoreCase(role.serialize())) .map(x -> x.get("id")) .findFirst().get(); }
String bartSentJmapMessageId = bartSendMessageToHomer(); String homerReceivedMessageId = Iterables.getOnlyElement(listMessageIdsForAccount(homerAccessToken)); calmlyAwait.until(() -> !listMessageIdsInMailbox(bartAccessToken, getInboxId(bartAccessToken)).isEmpty()); String bartInboxMessageIds = Iterables.getOnlyElement(listMessageIdsInMailbox(bartAccessToken, getInboxId(bartAccessToken)));
" \"subject\": \"Thank you for joining example.com!\"," + " \"textBody\": \"Hello someone, and thank you for joining example.com!\"," + " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" + " }}" + " }," + .statusCode(200); String outboxId = getMailboxId(accessToken, Role.OUTBOX); assertThat(hasNoMessageIn(bobAccessToken, outboxId)).isTrue();
private String bartSendMessageToHomer() { String messageCreationId = "creationId"; String outboxId = getOutboxId(bartAccessToken); String requestBody = "[" + " [" + .path(ARGUMENTS + ".created." + messageCreationId + ".id"); calmlyAwait.until(() -> !listMessageIdsForAccount(homerAccessToken).isEmpty()); return id;
" \"to\": [{ \"name\": \"Alice\", \"email\": \"" + ALICE + "\"}]," + " \"subject\": \"subject\"," + " \"mailboxIds\": [\"" + getOutboxId(bobAccessToken) + "\"]" + " }}" + " }," + () -> JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, matchedMailbox)); assertThat(JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, inbox)).isFalse();
" \"isDraft\": true," + " \"isForwarded\": true," + " \"mailboxIds\": [\"" + getOutboxId(cedricAccessToken) + "\"]" + " }}" + " }," + .atMost(30, TimeUnit.SECONDS).until(() -> isAnyMessageFoundInRecipientsMailboxes(aliceAccessToken)); given() .header("Authorization", aliceAccessToken.serialize())
" \"isDraft\": true," + " \"isForwarded\": true," + " \"mailboxIds\": [\"" + getDraftId(accessToken) + "\"]" + " }}" + " }," +
@Test public void setMessagesShouldMarkMessageAsForwardWhenIsForwardedPassed() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String serializedMessageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isForwarded\" : true } } }, \"#0\"]]", serializedMessageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId)); }
" \"subject\": \"subject\"," + " \"keywords\": {\"$Answered\": true, \"$Deleted\": true}," + " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" + " }}" + " }," +
" \"subject\": \"subject\"," + " \"keywords\": {\"$Draft\": true}," + " \"mailboxIds\": [\"" + getDraftId(accessToken) + "\", \"" + getOutboxId(accessToken) + "\"]" + " }}" + " }," +
public static String getDraftId(AccessToken accessToken) { return getMailboxId(accessToken, Role.DRAFTS); }
@Test public void configurationShouldBeWellLoaded() throws Exception { jmapServer.getProbe(QuotaProbesImpl.class) .setMaxStorage(MailboxConstants.USER_NAMESPACE + "&" + HOMER, new SerializableQuotaValue<>(QuotaSize.size(100 * 1000))); bartSendMessageToHomer(); // Homer receives a mail big enough to trigger a 10% configured threshold calmlyAwait.atMost(30, TimeUnit.SECONDS) .until(() -> listMessageIdsForAccount(homerAccessToken).size() == 2); bartSendMessageToHomer(); // Homer receives a mail big enough to trigger a 20% configured threshold calmlyAwait.atMost(30, TimeUnit.SECONDS) .until(() -> listMessageIdsForAccount(homerAccessToken).size() == 4); List<String> ids = listMessageIdsForAccount(homerAccessToken); String idString = ids.stream() .map(id -> "\"" + id + "\"") .collect(Collectors.joining(",")); given() .header("Authorization", homerAccessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [" + idString + "]}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .log().ifValidationFails() .body(ARGUMENTS + ".list.textBody", hasItem(containsString("You currently occupy more than 10 % of the total size allocated to you"))) .body(ARGUMENTS + ".list.textBody", hasItem(containsString("You currently occupy more than 20 % of the total size allocated to you"))); }
" {" + " \"update\": { \"" + messageId + "\" : {" + " \"mailboxIds\": [\"" + getInboxId(accessToken) + "\",\"" + getDraftId(accessToken) + "\"]" + " }}" + " }," +
" \"subject\": \"Thank you for joining example.com!\"," + " \"textBody\": \"Hello someone, and thank you for joining example.com!\"," + " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" + " }}" + " }," + .then() .log().ifValidationFails() .spec(getSetMessagesUpdateOKResponseAssertions(jmapMessageId));
" \"to\": [{ \"name\": \"Alice\", \"email\": \"" + ALICE + "\"}]," + " \"subject\": \"subject\"," + " \"mailboxIds\": [\"" + getOutboxId(bobAccessToken) + "\"]" + " }}" + " }," + () -> JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, inbox)); assertThat(JmapCommonRequests.isAnyMessageFoundInRecipientsMailbox(accessToken, matchedMailbox)).isFalse();
" \"isDraft\": true," + " \"isForwarded\": true," + " \"mailboxIds\": [\"" + getOutboxId(cedricAccessToken) + "\"]" + " }}" + " }," + calmlyAwait .pollDelay(Duration.FIVE_HUNDRED_MILLISECONDS) .atMost(30, TimeUnit.SECONDS).until(() -> isAnyMessageFoundInRecipientsMailboxes(bobAccessToken)); given() .header("Authorization", bobAccessToken.serialize())
" \"subject\": \"subject\"," + " \"keywords\": {\"$Flagged\": true}," + " \"mailboxIds\": [\"" + getDraftId(accessToken) + "\"]" + " }}" + " }," +
@Test public void setMessageWithUpdateShouldBeOKWhenKeywordsWithCustomFlagArePassed() throws MailboxException { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME, "mailbox"); ComposedMessageId message = mailboxProbe.appendMessage(USERNAME, USER_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8)), new Date(), false, new Flags()); await(); String messageId = message.getMessageId().serialize(); given() .header("Authorization", accessToken.serialize()) .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"keywords\": {\"$Seen\": true, \"$Unknown\": true} } } }, \"#0\"]]", messageId)) .when() .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .spec(getSetMessagesUpdateOKResponseAssertions(messageId)); }
" \"isDraft\": true," + " \"keywords\": {\"$Answered\": true}," + " \"mailboxIds\": [\"" + getOutboxId(accessToken) + "\"]" + " }}" + " }," +
private void sendAWrongInitialMessage() { String messageCreationId = "creationId"; String outboxId = getOutboxId(bartAccessToken); String requestBody = "[" + " [" + " \"setMessages\"," + " {" + " \"create\": { \"" + messageCreationId + "\" : {" + " \"from\": { \"name\": \"Bob\", \"email\": \"" + BART + "\"}," + " \"to\": [{ \"name\": \"User\", \"email\": \"" + HOMER + "\"}]," + " \"subject\": \"Message with an attachment\"," + " \"textBody\": \"Test body, plain text version\"," + " \"htmlBody\": \"Test <b>body</b>, HTML version\"," + " \"mailboxIds\": [\"" + outboxId + "\"] " + " }}" + " }," + " \"#0\"" + " ]" + "]"; with() .header("Authorization", bartAccessToken.serialize()) .body(requestBody) .post("/jmap") .then() .extract() .body() .path(ARGUMENTS + ".created." + messageCreationId + ".id"); calmlyAwait.until(() -> !listMessageIdsForAccount(homerAccessToken).isEmpty()); }