}
List<MessageRange> ranges = MessageRange.toRanges(idList);
idRanges = new IdRange[ranges.size()];
for (int i = 0 ; i <ranges.size(); i++) {
MessageRange range = ranges.get(i);
idRanges[i] = new IdRange(range.getUidFrom(), range.getUidTo());
}
boolean esearch = false;
for (int i = 0; i < resultOptions.size(); i++) {
if (SearchResultOption.SAVE != resultOptions.get(i)) {
esearch = true;
break;
}
}
if (esearch) {
long min = -1;
long max = -1;
long count = ids.length;
if (ids.length > 0) {
min = ids[0];
max = ids[ids.length -1];
}
// Save the sequence-set for later usage. This is part of SEARCHRES
if (resultOptions.contains(SearchResultOption.SAVE)) {
if (resultOptions.contains(SearchResultOption.ALL) || resultOptions.contains(SearchResultOption.COUNT)) {
// if the options contain ALL or COUNT we need to save the complete sequence-set
SearchResUtil.saveSequenceSet(session, idRanges);
} else {
List<IdRange> savedRanges = new ArrayList<IdRange>();
if (resultOptions.contains(SearchResultOption.MIN)) {
// Store the MIN
savedRanges.add(new IdRange(min));
}
if (resultOptions.contains(SearchResultOption.MAX)) {
// Store the MAX
savedRanges.add(new IdRange(max));
}
SearchResUtil.saveSequenceSet(session, savedRanges.toArray(new IdRange[0]));
}
}
response = new ESearchResponse(min, max, count, idRanges, tag, useUids, resultOptions);