private void closeSession(MailboxSession session) { if (session != null) { mailboxManager.endProcessingRequest(session); try { mailboxManager.logout(session, true); } catch (MailboxException e) { throw new RuntimeException(e); } } }
@Override public void close() throws IOException { try { mailboxManager.logout(session, true); } catch (MailboxException e) { throw new IOException("Unable to close mailbox", e); } finally { mailboxManager.endProcessingRequest(session); } } }
/** * Forces a logout of any mailbox session. * * @param imapSession * not null * @throws MailboxException * when forced logout fails */ private void forceLogout(ImapSession imapSession) throws MailboxException { final MailboxSession session = ImapSessionUtils.getMailboxSession(imapSession); if (session == null) { LOGGER.trace("No mailbox session so no force logout needed"); } else { session.close(); mailboxManager.logout(session, true); } }
private void closeProcessing(MailboxSession session) throws MessagingException { session.close(); try { try { mailboxManager.logout(session, true); } catch (MailboxException e) { throw new MessagingException("Can logout from mailbox", e); } } finally { mailboxManager.endProcessingRequest(session); } }
/** * Forces a logout of any mailbox session. * * @param imapSession * not null * @throws MailboxException * when forced logout fails */ private void forceLogout(ImapSession imapSession) throws MailboxException { final MailboxSession session = ImapSessionUtils.getMailboxSession(imapSession); if (session == null) { if (imapSession.getLog().isTraceEnabled()) { imapSession.getLog().trace("No mailbox session so no force logout needed"); } } else { session.close(); mailboxManager.logout(session, true); } }
@AfterEach void tearDown() throws Exception { mailboxManager.logout(session, false); mailboxManager.endProcessingRequest(session); }
protected void doProcess(LogoutRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { getMailboxManager().logout(mailboxSession, false); session.logout(); bye(responder); okComplete(command, tag, responder); } catch (MailboxException e) { if (session.getLog().isInfoEnabled()) { session.getLog().info("Logout failed", e); } no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } } }
@Override protected void doProcess(LogoutRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { getMailboxManager().logout(mailboxSession, false); session.logout(); bye(responder); okComplete(command, tag, responder); } catch (MailboxException e) { LOGGER.error("Logout failed for user {}", mailboxSession.getUser().getUserName(), e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
mailboxManager.logout(session, true); mailboxManager.endProcessingRequest(session); } catch (MailboxException e) {
@Override public void createMailbox(MailboxPath mailboxPath) throws Exception { MailboxManager mailboxManager = getMailboxManager(); MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); mailboxManager.createMailbox(mailboxPath, mailboxSession); mailboxManager.logout(mailboxSession, true); mailboxManager.endProcessingRequest(mailboxSession); }
private static void provisionUser(MailboxManager mailboxManager, String user) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(user); mailboxManager.startProcessingRequest(mailboxSession); createMailbox(mailboxManager, mailboxSession, MailboxPath.inbox(mailboxSession)); IntStream.range(0, SUB_MAILBOXES_COUNT) .mapToObj(i -> MailboxConstants.INBOX + ".SUB_FOLDER_" + i) .peek(name -> createMailbox(mailboxManager, mailboxSession, MailboxPath.forUser(user, name))) .forEach(name -> createSubSubMailboxes(mailboxManager, mailboxSession, name)); mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }
mailboxManager.logout(mailboxSession, false); } catch (MailboxException e) {
/** * 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); }
manager.logout(session, true); } catch (BadCredentialsException e) { throw new MessagingException("Unable to authenticate to mailbox", e);
@Override public void grantRights(MailboxPath mailboxPath, String userName, MailboxACL.Rfc4314Rights rights) throws Exception { MailboxManager mailboxManager = getMailboxManager(); MailboxSession mailboxSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); mailboxManager.setRights(mailboxPath, MailboxACL.EMPTY.apply(MailboxACL.command() .forUser(userName) .rights(rights) .asAddition()), mailboxManager.createSystemSession(userName)); mailboxManager.logout(mailboxSession, true); mailboxManager.endProcessingRequest(mailboxSession); }