final boolean useUids = request.isUseUids();
final long unchangedSince = request.getUnchangedSince();
ImapCommand imapCommand = command;
try {
final MessageManager mailbox = getSelectedMailbox(session);
final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
final Flags flags = request.getFlags();
if (unchangedSince != -1) {
MetaData metaData = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
if (metaData.isModSeqPermanent() == false) {
// Check if the mailbox did not support modsequences. If so return a tagged bad response.
// See RFC4551 3.1.2. NOMODSEQ Response Code
taggedBad(command, tag, responder, HumanReadableText.NO_MOD_SEQ);
return;
} else if (unchangedSince == 0){
Flags.Flag[] systemFlags = flags.getSystemFlags();
if (systemFlags != null && systemFlags.length != 0) {
// we need to return all sequences as failed when using a UNCHANGEDSINCE 0 and the request specify a SYSTEM flags
//
// See RFC4551 3.2. STORE and UID STORE Command;
//
// Use of UNCHANGEDSINCE with a modification sequence of 0 always
// fails if the metadata item exists. A system flag MUST always be
// considered existent, whether it was set or not.
final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idSet));
responder.respond(response);
return;
}
}
}
final List<Long> failed = new ArrayList<Long>();
final List<String> userFlags = Arrays.asList(flags.getUserFlags());
for (int i = 0; i < idSet.length; i++) {
final SelectedMailbox selected = session.getSelected();
MessageRange messageSet = messageRange(selected, idSet[i], useUids);
if (messageSet != null) {
if (unchangedSince != -1) {
// Ok we have a CONDSTORE option so use the CONDSTORE_COMMAND
imapCommand = CONDSTORE_COMMAND;
List<Long> uids = new ArrayList<Long>();
MessageResultIterator results = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL, mailboxSession);
while(results.hasNext()) {
MessageResult r = results.next();
long uid = r.getUid();
boolean fail = false;