protected void addFlagsResponses(final ImapSession session, final SelectedMailbox selected, final ImapProcessor.Responder responder, boolean useUid, MessageRange messageSet, MessageManager mailbox, MailboxSession mailboxSession) throws MailboxException {
final MessageResultIterator it = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL, mailboxSession);
while (it.hasNext()) {
MessageResult mr = it.next();
final long uid = mr.getUid();
int msn = selected.msn(uid);
if (msn == SelectedMailbox.NO_SUCH_MESSAGE) {
if (session.getLog().isDebugEnabled()) {
session.getLog().debug("No message found with uid " + uid + " in the uid<->msn mapping for mailbox " + selected.getPath().getFullName(mailboxSession.getPathDelimiter()) +" , this may be because it was deleted by a concurrent session. So skip it..");
}
// skip this as it was not found in the mapping
//
// See IMAP-346
continue;
}
boolean qresyncEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC);
boolean condstoreEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_CONDSTORE);
final Flags flags = mr.getFlags();
final Long uidOut;
if (useUid || qresyncEnabled) {
uidOut = uid;
} else {
uidOut = null;
}
if (selected.isRecent(uid)) {
flags.add(Flags.Flag.RECENT);
} else {
flags.remove(Flags.Flag.RECENT);
}
final FetchResponse response;
// Check if we also need to return the MODSEQ in the response. This is true if CONDSTORE or
// if QRESYNC was enabled, and the mailbox supports the permant storage of mod-sequences
if ((condstoreEnabled || qresyncEnabled) && mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isModSeqPermanent()) {
response = new FetchResponse(msn, flags, uidOut, mr.getModSeq(), null, null, null, null, null, null);
} else {
response = new FetchResponse(msn, flags, uidOut, null, null, null, null, null, null, null);
}
responder.respond(response);
}