protected void processMessageRanges(final ImapSession session, final MessageManager mailbox, final List<MessageRange> ranges, final FetchData fetch, final boolean useUids, final MailboxSession mailboxSession, final Responder responder) throws MailboxException {
final FetchResponseBuilder builder = new FetchResponseBuilder(new EnvelopeBuilder(session.getLog()));
FetchGroup resultToFetch = getFetchGroup(fetch);
for (int i = 0; i < ranges.size(); i++) {
MessageResultIterator messages = mailbox.getMessages(ranges.get(i), resultToFetch, mailboxSession);
while (messages.hasNext()) {
final MessageResult result = messages.next();
try {
final FetchResponse response = builder.build(fetch, result, mailbox, session, useUids);
responder.respond(response);
} catch (MessageRangeException e) {
// we can't for whatever reason find the message so
// just skip it and log it to debug
if (session.getLog().isDebugEnabled()) {
session.getLog().debug("Unable to find message with uid " + result.getUid(), e);
}
} catch (MailboxException e) {
// we can't for whatever reason find parse all requested parts of the message. This may because it was deleted while try to access the parts.
// So we just skip it
//
// See IMAP-347
if (session.getLog().isDebugEnabled()) {
session.getLog().debug("Unable to fetch message with uid " + result.getUid() + ", so skip it", e);
}
}
}
// Throw the exception if we received one
if (messages.getException() != null) {
throw messages.getException();
}
}
}