Skip to content

Commit

Permalink
Issue #89 : Handle search terms with parenthesis
Browse files Browse the repository at this point in the history
Note: Search support is still limited to simple terms - see issue #20
  • Loading branch information
marcelmay committed Aug 5, 2015
1 parent b768d26 commit 1acb351
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void doProcess(ImapRequestLineReader request,
response.commandComplete(this);
}


/**
* @see ImapCommand#getName
*/
Expand Down Expand Up @@ -118,7 +119,13 @@ public SearchTerm searchTerm(ImapRequestLineReader request)
// FLAG SEEN ALL
if (null == b) {
try {
SearchKey key = SearchKey.valueOf(sb.toString());
String keyValue = sb.toString();
// Parentheses?
if(keyValue.charAt(0)=='('
&& keyValue.charAt(keyValue.length()-1)==')' ) {
keyValue = keyValue.substring(1,keyValue.length()-1);
}
SearchKey key = SearchKey.valueOf(keyValue);
if (SearchKey.NOT == key) {
negated = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
*/
public enum SearchKey {
ALL(),
ANSWERED,
ANSWERED(),
BCC(1),
CC(1),
DELETED(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public void testSearch() throws Exception {
imapMessages = imapFolder.search(new NotTerm(new HeaderTerm("Message-ID", id)));
assertTrue(imapMessages.length == 1);
assertTrue(imapMessages[0] == m0);

// Search
NotTerm notAnswered = new NotTerm(new FlagTerm(new Flags(Flags.Flag.ANSWERED), true));
NotTerm notDeleted = new NotTerm(new FlagTerm(new Flags(Flags.Flag.DELETED), true));
NotTerm notSeen = new NotTerm(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
SearchTerm searchTerm = new AndTerm(new AndTerm(new AndTerm(notAnswered, notDeleted), notSeen),
new NotTerm(new FromTerm(new InternetAddress("from2@localhost"))));
imapMessages = imapFolder.search(searchTerm);
assertTrue(imapMessages.length == 1);
assertTrue(imapMessages[0] == m1);

} finally {
store.close();
}
Expand Down

0 comments on commit 1acb351

Please sign in to comment.