@Test public void doneShouldNotMoveMailFromOutboxToSentWhenInvalidMessageIdProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(USERNAME_ATTRIBUTE); mail.setAttribute(messageIdAttribute("invalid")); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroup.FULL_CONTENT, mailboxSession); assertThat(resultIterator).toIterable() .hasSize(1); }
@Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { Optional<?> optionalRawMessageId = retrieveMessageId(); MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get()); Optional<String> username = retrieveUsername(); if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get())); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } }
PostDequeueDecorator extends MailQueueItemDecorator { @Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { Optional<?> optionalRawMessageId = retrieveMessageId(); MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get()); Optional<String> username = retrieveUsername(); if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get())); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } } }
PostDequeueDecorator extends MailQueueItemDecorator { @Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { Optional<?> optionalRawMessageId = retrieveMessageId(); MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get()); Optional<String> username = retrieveUsername(); if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get())); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } } PostDequeueDecorator(MailQueueItem mailQueueItem,
                                MailboxManager mailboxManager,
                                Factory messageIdFactory,
                                MessageIdManager messageIdManager,
                                SystemMailboxesProvider systemMailboxesProvider); }
PostDequeueDecorator extends MailQueueItemDecorator { @Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { Optional<?> optionalRawMessageId = retrieveMessageId(); MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get()); Optional<String> username = retrieveUsername(); if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get())); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } } PostDequeueDecorator(MailQueueItem mailQueueItem,
                                MailboxManager mailboxManager,
                                Factory messageIdFactory,
                                MessageIdManager messageIdManager,
                                SystemMailboxesProvider systemMailboxesProvider); @Override Mail getMail(); @Override void done(boolean success); }
PostDequeueDecorator extends MailQueueItemDecorator { @Override public void done(boolean success) throws MailQueueException { mailQueueItem.done(success); if (success && mandatoryJmapMetaDataIsPresent()) { Optional<?> optionalRawMessageId = retrieveMessageId(); MessageId messageId = messageIdFactory.fromString((String) optionalRawMessageId.get()); Optional<String> username = retrieveUsername(); if (!getMail().getAttribute(IS_DELIVERED.getName()).isPresent()) { try { MailboxSession mailboxSession = mailboxManager.createSystemSession(Username.of(username.get())); moveFromOutboxToSentWithSeenFlag(messageId, mailboxSession); getMail().setAttribute(IS_DELIVERED); } catch (MailShouldBeInOutboxException e) { LOG.info("Message does not exist on Outbox anymore, it could have already been sent", e); } catch (MailboxException e) { throw new MailQueueException(e.getMessage(), e); } } } } PostDequeueDecorator(MailQueueItem mailQueueItem,
                                MailboxManager mailboxManager,
                                Factory messageIdFactory,
                                MessageIdManager messageIdManager,
                                SystemMailboxesProvider systemMailboxesProvider); @Override Mail getMail(); @Override void done(boolean success);  }