private void highestModSeq(Responder responder, MetaData metaData, SelectedMailbox selected) {
   final StatusResponse untaggedOk;
   if (metaData.isModSeqPermanent()) {
     final long highestModSeq = metaData.getHighestModSeq();
     untaggedOk =
         statusResponseFactory.untaggedOk(
             HumanReadableText.HIGHEST_MOD_SEQ, ResponseCode.highestModSeq(highestModSeq));
   } else {
     untaggedOk =
         statusResponseFactory.untaggedOk(HumanReadableText.NO_MOD_SEQ, ResponseCode.noModSeq());
   }
   responder.respond(untaggedOk);
 }
  private MessageManager.MetaData selectMailbox(MailboxPath mailboxPath, ImapSession session)
      throws MailboxException {
    final MailboxManager mailboxManager = getMailboxManager();
    final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
    final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);

    final SelectedMailbox sessionMailbox;
    final SelectedMailbox currentMailbox = session.getSelected();
    if (currentMailbox == null || !currentMailbox.getPath().equals(mailboxPath)) {

      // QRESYNC EXTENSION
      //
      // Response with the CLOSE return-code when the currently selected mailbox is closed
      // implicitly using the SELECT/EXAMINE command on another mailbox
      //
      // See rfc5162 3.7. CLOSED Response Code
      if (currentMailbox != null) {
        getStatusResponseFactory()
            .untaggedOk(HumanReadableText.QRESYNC_CLOSED, ResponseCode.closed());
      }
      session.selected(new SelectedMailboxImpl(getMailboxManager(), session, mailboxPath));

      sessionMailbox = session.getSelected();

    } else {
      // TODO: Check if we need to handle CONDSTORE there too
      sessionMailbox = currentMailbox;
    }
    final MessageManager.MetaData metaData =
        mailbox.getMetaData(
            !openReadOnly, mailboxSession, MessageManager.MetaData.FetchGroup.FIRST_UNSEEN);
    addRecent(metaData, sessionMailbox);
    return metaData;
  }
  private boolean unseen(
      Responder responder, MessageUid firstUnseen, SelectedMailbox selected, MailboxSession session)
      throws MailboxException {
    if (firstUnseen != null) {
      final MessageUid unseenUid = firstUnseen;
      int msn = selected.msn(unseenUid);

      if (msn == SelectedMailbox.NO_SUCH_MESSAGE) {
        if (session.getLog().isDebugEnabled()) {
          session
              .getLog()
              .debug(
                  "No message found with uid "
                      + unseenUid
                      + " in mailbox "
                      + selected.getPath().getFullName(session.getPathDelimiter()));
        }
        return false;
      }

      final StatusResponse untaggedOk =
          statusResponseFactory.untaggedOk(HumanReadableText.unseen(msn), ResponseCode.unseen(msn));
      responder.respond(untaggedOk);
    }
    return true;
  }
 private void taggedOk(
     Responder responder,
     String tag,
     ImapCommand command,
     MetaData metaData,
     HumanReadableText text) {
   final boolean writeable = metaData.isWriteable() && !openReadOnly;
   final ResponseCode code;
   if (writeable) {
     code = ResponseCode.readWrite();
   } else {
     code = ResponseCode.readOnly();
   }
   final StatusResponse taggedOk = statusResponseFactory.taggedOk(tag, command, text, code);
   responder.respond(taggedOk);
 }
 private void uidNext(Responder responder, MessageManager.MetaData metaData)
     throws MailboxException {
   final MessageUid uid = metaData.getUidNext();
   final StatusResponse untaggedOk =
       statusResponseFactory.untaggedOk(HumanReadableText.UIDNEXT, ResponseCode.uidNext(uid));
   responder.respond(untaggedOk);
 }
 private void uidValidity(Responder responder, MessageManager.MetaData metaData)
     throws MailboxException {
   final long uidValidity = metaData.getUidValidity();
   final StatusResponse untaggedOk =
       statusResponseFactory.untaggedOk(
           HumanReadableText.UID_VALIDITY, ResponseCode.uidValidity(uidValidity));
   responder.respond(untaggedOk);
 }