return result;
}
private SearchQuery.Criterion toCriterion(final SearchKey key, final ImapSession session) throws MessageRangeException {
final int type = key.getType();
final DayMonthYear date = key.getDate();
switch (type) {
case SearchKey.TYPE_ALL:
return SearchQuery.all();
case SearchKey.TYPE_AND:
return and(key.getKeys(), session);
case SearchKey.TYPE_ANSWERED:
return SearchQuery.flagIsSet(Flag.ANSWERED);
case SearchKey.TYPE_BCC:
return SearchQuery.address(AddressType.Bcc, key.getValue());
case SearchKey.TYPE_BEFORE:
return SearchQuery.internalDateBefore(date.toDate(), DateResolution.Day);
case SearchKey.TYPE_BODY:
return SearchQuery.bodyContains(key.getValue());
case SearchKey.TYPE_CC:
return SearchQuery.address(AddressType.Cc, key.getValue());
case SearchKey.TYPE_DELETED:
return SearchQuery.flagIsSet(Flag.DELETED);
case SearchKey.TYPE_DRAFT:
return SearchQuery.flagIsSet(Flag.DRAFT);
case SearchKey.TYPE_FLAGGED:
return SearchQuery.flagIsSet(Flag.FLAGGED);
case SearchKey.TYPE_FROM:
return SearchQuery.address(AddressType.From, key.getValue());
case SearchKey.TYPE_HEADER:
String value = key.getValue();
// Check if header exists if the value is empty. See IMAP-311
if (value == null || value.length() == 0) {
return SearchQuery.headerExists(key.getName());
} else {
return SearchQuery.headerContains(key.getName(), value);
}
case SearchKey.TYPE_KEYWORD:
return SearchQuery.flagIsSet(key.getValue());
case SearchKey.TYPE_LARGER:
return SearchQuery.sizeGreaterThan(key.getSize());
case SearchKey.TYPE_NEW:
return SearchQuery.and(SearchQuery.flagIsSet(Flag.RECENT), SearchQuery.flagIsUnSet(Flag.SEEN));
case SearchKey.TYPE_NOT:
return not(key.getKeys(), session);
case SearchKey.TYPE_OLD:
return SearchQuery.flagIsUnSet(Flag.RECENT);
case SearchKey.TYPE_ON:
return SearchQuery.internalDateOn(date.toDate(), DateResolution.Day);
case SearchKey.TYPE_OR:
return or(key.getKeys(), session);
case SearchKey.TYPE_RECENT:
return SearchQuery.flagIsSet(Flag.RECENT);
case SearchKey.TYPE_SEEN:
return SearchQuery.flagIsSet(Flag.SEEN);
case SearchKey.TYPE_SENTBEFORE:
return SearchQuery.headerDateBefore(ImapConstants.RFC822_DATE, date.toDate(), DateResolution.Day);
case SearchKey.TYPE_SENTON:
return SearchQuery.headerDateOn(ImapConstants.RFC822_DATE, date.toDate(), DateResolution.Day);
case SearchKey.TYPE_SENTSINCE:
// Include the date which is used as search param. See IMAP-293
Criterion onCrit = SearchQuery.headerDateOn(ImapConstants.RFC822_DATE, date.toDate(), DateResolution.Day);
Criterion afterCrit = SearchQuery.headerDateAfter(ImapConstants.RFC822_DATE, date.toDate(), DateResolution.Day);
return SearchQuery.or(onCrit, afterCrit);
case SearchKey.TYPE_SEQUENCE_SET:
return sequence(key.getSequenceNumbers(), session, true);
case SearchKey.TYPE_SINCE:
// Include the date which is used as search param. See IMAP-293
return SearchQuery.or(SearchQuery.internalDateOn(date.toDate(), DateResolution.Day), SearchQuery.internalDateAfter(date.toDate(), DateResolution.Day));
case SearchKey.TYPE_SMALLER:
return SearchQuery.sizeLessThan(key.getSize());
case SearchKey.TYPE_SUBJECT:
return SearchQuery.headerContains(ImapConstants.RFC822_SUBJECT, key.getValue());
case SearchKey.TYPE_TEXT: