@Override
  public MessageResult next() {
    if (hasNext()) {
      final Message<Id> message = next.next();
      MessageResult result;
      try {
        result = ResultUtils.loadMessageResult(message, group);
        cursor = result.getUid();
      } catch (MailboxException e) {
        result = new UnloadedMessageResult<Id>(message, e);
      }

      cursor++;
      // move the start UID behind the last fetched message UID if needed
      if (hasNext()) {
        if (cursor > to) {
          done = true;
        }
      }
      return result;
    }
    throw new NoSuchElementException();
  }
 public int compareTo(MessageResult that) {
   // Java 1.5 return (int) Math.signum(uid - that.getUid());
   long diff = uid - that.getUid();
   return (int) diff == 0 ? 0 : diff > 0 ? 1 : -1;
 }