private QueryBuilder convertHeader(SearchQuery.HeaderCriterion headerCriterion) { return headerOperatorConverterMap.get(headerCriterion.getOperator().getClass()) .apply( headerCriterion.getHeaderName().toLowerCase(Locale.US), headerCriterion.getOperator()); }
/** * Creates a filter matching messages whose header value contains the given * value. * * All to-compared Strings MUST BE converted to uppercase before doing so * (this also include the search value) * * @param headerName * name of the header whose value will be compared, not null * @param value * when null or empty the existance of the header will be * checked, otherwise contained value * @return <code>Criterion</code>, not null */ public static Criterion headerContains(String headerName, String value) { if (value == null || value.length() == 0) { return headerExists(headerName); } else { return new HeaderCriterion(headerName, new ContainsOperator(value)); } }
/** * Creates a filter matching messages with the date of the given header * before the given date. If the header's value is not a date then it will * not be included. * * @param headerName * name of the header whose value will be compared, not null * @param date * given date * @param dateResolution * the date resolution, either {@link DateResolution#Year}, * {@link DateResolution#Month}, {@link DateResolution#Day}, * {@link DateResolution#Hour}, {@link DateResolution#Minute} or * {@link DateResolution#Second} * @return <code>Criterion</code>, not null */ public static Criterion headerDateBefore(String headerName, Date date, DateResolution dateResolution) { return new HeaderCriterion(headerName, new DateOperator(DateComparator.BEFORE, date, dateResolution)); }
/** * Creates a filter matching messages with the date of the given header * after the given date. If the header's value is not a date then it will * not be included. * * @param headerName * name of the header whose value will be compared, not null * @param date * given date * @param dateResolution * the date resolution, either {@link DateResolution#Year}, * {@link DateResolution#Month}, {@link DateResolution#Day}, * {@link DateResolution#Hour}, {@link DateResolution#Minute} or * {@link DateResolution#Second} * @return <code>Criterion</code>, not null */ public static Criterion headerDateAfter(String headerName, Date date, DateResolution dateResolution) { return new HeaderCriterion(headerName, new DateOperator(DateComparator.AFTER, date, dateResolution)); }
/** * Creates a filter matching messages with the date of the given header on * the given date. If the header's value is not a date then it will not be * included. * * @param headerName * name of the header whose value will be compared, not null * @param date * given date * @param dateResolution * the date resolution, either {@link DateResolution#Year}, * {@link DateResolution#Month}, {@link DateResolution#Day}, * {@link DateResolution#Hour}, {@link DateResolution#Minute} or * {@link DateResolution#Second} * @return <code>Criterion</code>, not null */ public static Criterion headerDateOn(String headerName, Date date, DateResolution dateResolution) { return new HeaderCriterion(headerName, new DateOperator(DateComparator.ON, date, dateResolution)); }
private boolean matches(SearchQuery.HeaderCriterion criterion, MailboxMessage message) throws MailboxException, IOException { SearchQuery.HeaderOperator operator = criterion.getOperator(); String headerName = criterion.getHeaderName(); if (operator instanceof SearchQuery.DateOperator) { return matches((SearchQuery.DateOperator) operator, headerName, message); } else if (operator instanceof SearchQuery.ContainsOperator) { return matches((SearchQuery.ContainsOperator) operator, headerName, message); } else if (operator instanceof SearchQuery.ExistsOperator) { return exists(headerName, message); } else if (operator instanceof SearchQuery.AddressOperator) { return matchesAddress((SearchQuery.AddressOperator) operator, headerName, message); } else { throw new UnsupportedSearchException(); } }
public HeaderCriterion asHeaderCriterion() { return new HeaderCriterion("Message-ID", new ContainsOperator(messageID)); }
/** * Creates a filter matching messages with a header matching the given name. * * All to-compared Strings MUST BE converted to uppercase before doing so * (this also include the search value) * * @param headerName * name of the header whose value will be compared, not null * @return <code>Criterion</code>, not null */ public static Criterion headerExists(String headerName) { return new HeaderCriterion(headerName, ExistsOperator.exists()); }
/** * Creates a filter matching messages whose Address header contains the * given address. The address header of the message MUST get canonicalized * before try to match it. * * @param type * @param address * @return <code>Criterion</code> */ public static Criterion address(AddressType type, String address) { return new HeaderCriterion(type.name(), new AddressOperator(address)); }