@Override public String getIdentifier() throws IOException { try { mailboxManager.startProcessingRequest(session); long validity = manager.getMetaData(false, session, MessageManager.MetaData.FetchGroup.NO_COUNT) .getUidValidity(); return Long.toString(validity); } catch (MailboxException e) { throw new IOException("Unable to retrieve indentifier for mailbox", e); } finally { mailboxManager.endProcessingRequest(session); } }
@Override public MailboxACL retrieveRights(MailboxPath mailboxPath) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); return mailboxManager.getMailbox(mailboxPath, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); } }
@Override public void enable(ImapMessage message, Responder responder, ImapSession session, String capability) throws EnableException { if (EnableProcessor.getEnabledCapabilities(session).contains(capability) == false) { SelectedMailbox sm = session.getSelected(); // Send a HIGHESTMODSEQ response if the there was a select mailbox before and the client just enabled // QRESYNC or CONDSTORE // // See http://www.dovecot.org/list/dovecot/2008-March/029561.html if (capability.equalsIgnoreCase(ImapConstants.SUPPORTS_CONDSTORE)|| capability.equalsIgnoreCase(ImapConstants.SUPPORTS_QRESYNC)) { try { MetaData metaData = null; boolean send = false; if (sm != null) { MessageManager mailbox = getSelectedMailbox(session); metaData = mailbox.getMetaData(false, ImapSessionUtils.getMailboxSession(session), FetchGroup.NO_COUNT); send= true; } condstoreEnablingCommand(session, responder, metaData, send); } catch (MailboxException e) { throw new EnableException("Unable to enable " + capability, e); } } } }
@Override public void enable(ImapMessage message, Responder responder, ImapSession session, String capability) throws EnableException { if (EnableProcessor.getEnabledCapabilities(session).contains(capability) == false) { SelectedMailbox sm = session.getSelected(); // Send a HIGHESTMODSEQ response if the there was a select mailbox before and the client just enabled // QRESYNC or CONDSTORE // // See http://www.dovecot.org/list/dovecot/2008-March/029561.html if (capability.equalsIgnoreCase(ImapConstants.SUPPORTS_CONDSTORE) || capability.equalsIgnoreCase(ImapConstants.SUPPORTS_QRESYNC)) { try { MetaData metaData = null; boolean send = false; if (sm != null) { MessageManager mailbox = getSelectedMailbox(session); metaData = mailbox.getMetaData(false, ImapSessionUtils.getMailboxSession(session), FetchGroup.NO_COUNT); send = true; } condstoreEnablingCommand(session, responder, metaData, send); } catch (MailboxException e) { throw new EnableException("Unable to enable " + capability, e); } } } }
protected void doProcess(CloseRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { MessageManager mailbox = getSelectedMailbox(session); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) { mailbox.expunge(MessageRange.all(), mailboxSession); session.deselect(); // Don't send HIGHESTMODSEQ when close. Like correct in the ERRATA of RFC5162 // // See http://www.rfc-editor.org/errata_search.php?rfc=5162 okComplete(command, tag, responder); } } catch (MailboxException e) { if (session.getLog().isInfoEnabled()) { session.getLog().info("Close failed for mailbox " + session.getSelected().getPath() , e); } no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } } }
@Override protected void doProcess(CloseRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { MessageManager mailbox = getSelectedMailbox(session); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) { mailbox.expunge(MessageRange.all(), mailboxSession); session.deselect(); // Don't send HIGHESTMODSEQ when close. Like correct in the ERRATA of RFC5162 // // See http://www.rfc-editor.org/errata_search.php?rfc=5162 okComplete(command, tag, responder); } } catch (MailboxException e) { LOGGER.error("Close failed for mailbox {}", session.getSelected().getPath(), e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
/** * Utility method to assert the number of mailboxes and messages per mailbox * are the ones expected. * * @throws MailboxException * @throws BadCredentialsException */ private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession("manager"); mailboxManager.startProcessingRequest(mailboxSession); List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession); assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT); for (MailboxPath mailboxPath: mailboxPathList) { MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession); assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor); } mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }
/** * Utility method to assert the number of mailboxes and messages per mailbox * are the ones expected. * * @throws MailboxException * @throws BadCredentialsException */ private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession("manager"); mailboxManager.startProcessingRequest(mailboxSession); List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession); assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT); for (MailboxPath mailboxPath: mailboxPathList) { MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession); assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor); } mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }
@Test public void eventShouldDoNothingWhenMailboxACLUpdatedButNoLookupRight() throws Exception { storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Administer) .asReplacement(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldDoNothingWhenEmptyNewRights() throws Exception { storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights() .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldDoNothingWhenMailboxACLButNoLookupRight() throws Exception { storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Administer) .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldUpdateAllNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeMailboxManager.renameMailbox(GRAND_CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1.sub2"), mailboxSession); MailboxACL parentActualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); MailboxACL childActualACL = storeMailboxManager.getMailbox(childMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(parentActualACL.getEntries()) .contains(lookupEntry); assertThat(childActualACL.getEntries()) .contains(lookupEntry); }
@Test public void eventShouldUpdateParentWhenMailboxACLAddLookupRight() throws Exception { storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Lookup) .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .hasSize(2) .contains(lookupEntry); }
@Test public void eventShouldDoNothingWhenNegativeACLEntry() throws Exception { EntryKey negativeUserKey = EntryKey.createUserEntryKey(SHARED_USER, true); storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(negativeUserKey) .rights(Right.Lookup) .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .hasSize(1) .doesNotContainKeys(negativeUserKey); } }
@Test public void eventShouldNotUpdateNewParentWhenRenameMailboxWhichDoesContainLookupRight() throws Exception { Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldUpdateAllParentWhenMailboxACLUpdateLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeRightManager.setRights( GRAND_CHILD_MAILBOX, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))), mailboxSession); MailboxACL actualParentACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); MailboxACL actualChildACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualParentACL.getEntries()) .contains(lookupEntry); assertThat(actualChildACL.getEntries()) .contains(lookupEntry); }
@Test public void eventShouldUpdateNewParentWhenRenameMailboxWhichContainLookupRight() throws Exception { Mailbox childMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(childMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(childMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeMailboxManager.renameMailbox(CHILD_MAILBOX, MailboxPath.forUser(OWNER_USER, "shared1.sub1New"), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId1, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .contains(lookupEntry); }
@Test public void eventShouldDoNothingWhenNewACLIsTheSameAsTheOldOne() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup)))); storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Lookup) .asAddition(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldDoNothingWhenMailboxACLRemoveLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write, Right.Lookup)))); storeRightManager.applyRightsCommand( GRAND_CHILD_MAILBOX, MailboxACL.command() .key(SHARED_USER_KEY) .rights(Right.Lookup) .asRemoval(), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .doesNotContainKeys(SHARED_USER_KEY); }
@Test public void eventShouldUpdateParentWhenMailboxACLUpdateLookupRight() throws Exception { Mailbox grandChildMailbox = mailboxMapper.getMailboxMapper(mailboxSession).findMailboxById(grandChildMailboxId); mailboxMapper.getMailboxMapper(mailboxSession).setACL(grandChildMailbox, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Write)))); storeRightManager.setRights( GRAND_CHILD_MAILBOX, new MailboxACL( new Entry(SHARED_USER_KEY, new Rfc4314Rights(Right.Lookup))), mailboxSession); MailboxACL actualACL = storeMailboxManager.getMailbox(parentMailboxId, mailboxSession) .getMetaData(RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT) .getACL(); assertThat(actualACL.getEntries()) .hasSize(2) .contains(lookupEntry); }