try {
final MessageManager mailbox = getSelectedMailbox(session);
final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
int expunged = 0;
MetaData mdata = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
if (!mdata.isWriteable()) {
no(command, tag, responder, HumanReadableText.MAILBOX_IS_READ_ONLY);
} else {
IdRange[] ranges = request.getUidSet();
if (ranges == null) {
expunged = expunge(mailbox, MessageRange.all(), session, mailboxSession);
} else {
// Handle UID EXPUNGE which is part of UIDPLUS
// See http://tools.ietf.org/html/rfc4315
for (int i = 0; i < ranges.length; i++) {
MessageRange mRange = messageRange(session.getSelected(), ranges[i], true);
if (mRange != null) {
expunged += expunge(mailbox, mRange, session, mailboxSession);
}
}
}
unsolicitedResponses(session, responder, false);
// Check if QRESYNC was enabled and at least one message was expunged. If so we need to respond with an OK response that contain the HIGHESTMODSEQ
//
// See RFC5162 3.3 EXPUNGE Command 3.5. UID EXPUNGE Command
if (EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC) && expunged > 0) {
okComplete(command, tag, ResponseCode.highestModSeq(mdata.getHighestModSeq()), responder);
} else {
okComplete(command, tag, responder);
}
}
} catch (MessageRangeException e) {