Skip to content

Commit

Permalink
Supports singleton in SEARCH command
Browse files Browse the repository at this point in the history
  • Loading branch information
aduprat committed Dec 17, 2014
1 parent f829093 commit 2c77d2a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/icegreen/greenmail/imap/commands/search/Uid.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@ public class Uid implements Criteria {

private final Range<Long> range;

public Uid(String simpleClosedRange) throws ProtocolException {
Iterator<String> split = Splitter.on(':').split(simpleClosedRange).iterator();
public Uid(String uids) throws ProtocolException {
if (!uids.contains(":")) {
range = Range.singleton(Long.parseLong(uids));
} else {
range = simpleClosedRange(uids);
}
}

private Range<Long> simpleClosedRange(String uids) {
Iterator<String> split = Splitter.on(":").split(uids).iterator();
if (!split.hasNext()) {
throw new IllegalStateException(String.format("Not enough values in %s", simpleClosedRange));
throw new IllegalStateException(String.format("Not enough values in %s", uids));
}
long lower = Long.parseLong(split.next());

if (!split.hasNext()) {
throw new IllegalStateException(String.format("Not enough values in %s", simpleClosedRange));
throw new IllegalStateException(String.format("Not enough values in %s", uids));
}
long higher = higher(split.next());

range = Range.closed(lower, higher);
return Range.closed(lower, higher);
}

private long higher(String value) {
Expand Down

0 comments on commit 2c77d2a

Please sign in to comment.