public MessageUid previous() { if (this.compareTo(MIN_VALUE) > 0) { return new MessageUid(uid - 1); } return MIN_VALUE; }
private boolean isLastUid(MessageUid uid) { Optional<MessageUid> lastUid = getLastUid(); return !lastUid.isPresent() || lastUid.get().compareTo(uid) < 0; }
public UidRange(MessageUid minValue, MessageUid messageUid) { if (minValue.compareTo(messageUid) > 0) { throw new IllegalArgumentException("LowVal must be <= HighVal"); } this.range = MessageRange.range(minValue, messageUid); }
@Override public int compareTo(MessageResult that) { return uid.compareTo(that.getUid()); }
@Override public boolean hasNext() { if (cursor.compareTo(to) > 0) { return false; } if (next == null || !next.hasNext()) { try { readBatch(); } catch (MailboxException e) { this.exception = e; return false; } } return next.hasNext(); }
@Override public int compareTo(MessageResult that) { return this.getUid().compareTo(that.getUid()); }
@Override public int compareTo(MailboxMessage other) { return this.getUid().compareTo(other.getUid()); }
@Override public int compare(MailboxMessage o1, MailboxMessage o2) { return o1.getUid().compareTo(o2.getUid()); }
/** * Return true if the uid is within the range */ public boolean includes(MessageUid uid) { switch (type) { case ALL: return true; case FROM: if (getUidFrom().compareTo(uid) <= 0) { return true; } return false; case RANGE: if (getUidFrom().compareTo(uid) <= 0 && getUidTo().compareTo(uid) >= 0) { return true; } return false; case ONE: if (getUidFrom().equals(uid)) { return true; } return false; default: return false; } }
case RANGE: start = range.getUidFrom(); if (start.equals(MessageUid.MAX_VALUE) || start.compareTo(selected.getFirstUid().orElse(MessageUid.MIN_VALUE)) < 0) { start = selected.getFirstUid().orElse(MessageUid.MIN_VALUE); if (end.equals(MessageUid.MAX_VALUE) || end.compareTo(selected.getLastUid().orElse(MessageUid.MAX_VALUE)) > 0) { end = selected.getLastUid().orElse(MessageUid.MAX_VALUE); case FROM: start = range.getUidFrom(); if (start.equals(MessageUid.MAX_VALUE) || start.compareTo(selected.getFirstUid().orElse(MessageUid.MIN_VALUE)) < 0) { start = selected.getFirstUid().orElse(MessageUid.MIN_VALUE);
} else if (highVal.equals(MessageUid.MAX_VALUE) && selected.getLastUid().orElse(MessageUid.MIN_VALUE).compareTo(lowVal) < 0) {
/** * Constructs an inclusive ranges of messages. The parameters will be * checked and {@link #from(long)} used where appropriate. * * @param from * first message UID * @param to * last message UID */ public static MessageRange range(MessageUid from, MessageUid to) { if (to.equals(MessageUid.MAX_VALUE) || to.compareTo(from) < 0) { return from(from); } else if (from.equals(to)) { // from and to is the same so no need to construct a real range return one(from); } else { return new MessageRange(Type.RANGE, from, to); } }
while (from.compareTo(to) <= 0) { vanishedUids.add(from); from = from.next();
if (low.compareTo(last) < 0) { throw new DecodingException(HumanReadableText.INVALID_MESSAGESET, "Sequence-set must be in ascending order"); } else {
/** * Return a {@link MessageRange} for the given values. If the MessageRange * can not be generated a {@link MailboxException} will get thrown */ protected MessageRange messageRange(SelectedMailbox selected, IdRange range, boolean useUids) throws MessageRangeException { long lowVal = range.getLowVal(); long highVal = range.getHighVal(); if (useUids == false) { return msnRangeToMessageRange(selected, lowVal, highVal); } else { if (selected.existsCount() <= 0) { return null; } // Take care of "*" and "*:*" values by return the last message in // the mailbox. See IMAP-289 MessageUid lastUid = selected.getLastUid().orElse(MessageUid.MIN_VALUE); if (lowVal == Long.MAX_VALUE && highVal == Long.MAX_VALUE) { return MessageRange.one(lastUid); } else if (highVal == Long.MAX_VALUE && lastUid.compareTo(MessageUid.of(lowVal)) < 0) { // Sequence uid ranges which use *:<uid-higher-then-last-uid> // MUST return at least the highest uid in the mailbox // See IMAP-291 return MessageRange.one(lastUid); } return MessageRange.range(MessageUid.of(lowVal), MessageUid.of(highVal)); } }