Skip to content

Commit

Permalink
James-1920 Make move to trash like move to any other mailbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc DUZAN committed Jan 26, 2017
1 parent f2d4d61 commit 52367e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
Expand Up @@ -2048,7 +2048,7 @@ public void updateShouldWorkWithFlagsAndMailboxUpdate() throws Exception {
}

@Test
public void moveToTrashIsNotYetSupported() throws Exception {
public void setMessagesShouldWorkForMoveToTrash() throws Exception {
String trashId = jmapServer.serverProbe().getMailbox("#private", USERNAME, "trash").getMailboxId().serialize();

ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
Expand All @@ -2074,10 +2074,11 @@ public void moveToTrashIsNotYetSupported() throws Exception {
.when()
.post("/jmap")
.then()
.log().ifValidationFails()
.statusCode(200)
.body(NAME, equalTo("error"))
.body(ARGUMENTS + ".type", equalTo("Not yet implemented"));
.log().ifValidationFails()
.body(NAME, equalTo("messagesSet"))
.body(ARGUMENTS + ".updated[0]", equalTo(messageToMoveId))
.body(ARGUMENTS + ".updated", hasSize(1));
}

@Test
Expand Down
Expand Up @@ -28,14 +28,11 @@
import javax.inject.Inject;
import javax.mail.Flags;

import org.apache.commons.lang.NotImplementedException;
import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
import org.apache.james.jmap.model.MessageProperties;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.jmap.model.UpdateMessagePatch;
import org.apache.james.jmap.model.mailbox.Role;
import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
Expand Down Expand Up @@ -80,6 +77,7 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
this.systemMailboxesProvider = systemMailboxesProvider;
}

@Override
public SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession) {
SetMessagesResponse.Builder responseBuilder = SetMessagesResponse.builder();
request.buildUpdatePatches(updatePatchConverter).forEach( (id, patch) -> {
Expand Down Expand Up @@ -112,7 +110,7 @@ private void update(MessageId messageId, UpdateMessagePatch updateMessagePatch,
} catch (MailboxException e) {
handleMessageUpdateException(messageId, builder, e);
}

}

private Stream<MailboxException> updateFlags(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession, MessageResult messageResult) {
Expand All @@ -133,25 +131,10 @@ private void setInMailboxes(MessageId messageId, UpdateMessagePatch updateMessag
.map(mailboxId -> mailboxIdFactory.fromString(mailboxId))
.collect(Guavate.toImmutableList());

if (isMoveToTrash(mailboxSession, mailboxIds)) {
throw new NotImplementedException("Do not support move to trash");
}

messageIdManager.setInMailboxes(messageId, mailboxIds, mailboxSession);
}
}

private boolean isMoveToTrash(MailboxSession mailboxSession, List<MailboxId> mailboxIds) throws MailboxException {
try {
return mailboxIds.size() == 1
&& mailboxIds.get(0)
.equals(systemMailboxesProvider.findMailbox(Role.TRASH, mailboxSession).getId());
} catch (MailboxRoleNotFoundException e) {
LOGGER.debug("Unable to find Trash mailbox for user: " + mailboxSession.getUser().getUserName(), e);
return false;
}
}

private void addMessageIdNotFoundToResponse(MessageId messageId, SetMessagesResponse.Builder builder) {
builder.notUpdated(ImmutableMap.of(messageId,
SetError.builder()
Expand Down

0 comments on commit 52367e7

Please sign in to comment.