com.openexchange.mail.search
Class SearchTerm<T>

java.lang.Object
  extended by com.openexchange.mail.search.SearchTerm<T>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ANDTerm, BccTerm, BodyTerm, BooleanTerm, CcTerm, FlagTerm, FromTerm, HeaderTerm, NOTTerm, ORTerm, ReceivedDateTerm, SentDateTerm, SizeTerm, SubjectTerm, ToTerm

public abstract class SearchTerm<T>
extends java.lang.Object
implements java.io.Serializable

SearchTerm

Author:
Thorben Betten
See Also:
Serialized Form

Constructor Summary
SearchTerm()
          Initializes a new SearchTerm
 
Method Summary
abstract  void addMailField(java.util.Collection<MailField> col)
          Adds the addressed MailField to specified collection
 boolean containsWildcard()
          Checks if this search term's pattern contains wildcard characters '*' and '?'
 SearchTerm<?> filter(java.lang.Class<? extends SearchTerm>[] filter)
          Generates a search term with the unsupported search terms specified through filter removed.
 SearchTerm<?> filter(java.util.Set<java.lang.Class<? extends SearchTerm>> filterSet)
          Generates a search term with the unsupported search terms specified through filter removed.
abstract  javax.mail.search.SearchTerm getJavaMailSearchTerm()
          Generates the corresponding JavaMail instance of SearchTerm from this search term
abstract  javax.mail.search.SearchTerm getNonWildcardJavaMailSearchTerm()
          Generates the corresponding instance of SearchTerm from this search term without any wildcard characters.
abstract  T getPattern()
          Gets the pattern to which the expression should match.
 boolean isAscii()
          Checks if this search term's pattern only consists of ASCII 7 bit characters.
abstract  boolean matches(MailMessage mailMessage)
          Checks if specified mail message matches this search term
abstract  boolean matches(javax.mail.Message msg)
          Checks if given message matches this search term
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SearchTerm

public SearchTerm()
Initializes a new SearchTerm

Method Detail

getPattern

public abstract T getPattern()
Gets the pattern to which the expression should match.

Returns:
The pattern

addMailField

public abstract void addMailField(java.util.Collection<MailField> col)
Adds the addressed MailField to specified collection

Parameters:
col - The collection which gathers addressed fields

matches

public abstract boolean matches(javax.mail.Message msg)
                         throws MailException
Checks if given message matches this search term

Parameters:
msg - The message to check
Returns:
true if message matches this search term; otherwise false
Throws:
MailException - If check fails

matches

public abstract boolean matches(MailMessage mailMessage)
                         throws MailException
Checks if specified mail message matches this search term

Parameters:
mailMessage - The mail message to check
Returns:
true if specified mail message matches this search term; otherwise false
Throws:
MailException - If checking mail message against search term fails

getJavaMailSearchTerm

public abstract javax.mail.search.SearchTerm getJavaMailSearchTerm()
Generates the corresponding JavaMail instance of SearchTerm from this search term

Returns:
The corresponding instance of SearchTerm

getNonWildcardJavaMailSearchTerm

public abstract javax.mail.search.SearchTerm getNonWildcardJavaMailSearchTerm()
Generates the corresponding instance of SearchTerm from this search term without any wildcard characters.

This is useful to preselect possible positives and to manually filtering out false positives.

Returns:
The corresponding instance of SearchTerm without any wildcard characters.
See Also:
containsWildcard()

filter

public SearchTerm<?> filter(java.lang.Class<? extends SearchTerm>[] filter)
Generates a search term with the unsupported search terms specified through filter removed.

For each search term contained in this search term the following rule is applied:

  1. If search term is an instance of ORTerm or ANDTerm replace the unsupported with:
  2. If search term is supported, return the search term itself
  3. Otherwise replace with BooleanTerm.FALSE

Note: Only a shallow copy is generated; meaning further working on this search term may influence return value's search term.

Parameters:
filter - An array containing unsupported classes of SearchTerm to filter against
Returns:
A new search term with the unsupported search terms removed

filter

public SearchTerm<?> filter(java.util.Set<java.lang.Class<? extends SearchTerm>> filterSet)
Generates a search term with the unsupported search terms specified through filter removed.

For each search term contained in this search term the following rule is applied:

  1. If search term is an instance of ORTerm or ANDTerm replace the unsupported with:
  2. If search term is supported, return the search term itself
  3. Otherwise replace with BooleanTerm.FALSE

Note: Only a shallow copy is generated; meaning further working on this search term may influence return value's search term.

Parameters:
filterSet - The filter set containing classes unsupported search terms
Returns:
A new search term with the unsupported search terms removed

isAscii

public boolean isAscii()
Checks if this search term's pattern only consists of ASCII 7 bit characters.

This method implies that this search is some kind of string search term. Returns true if not appropriate.

Returns:
true if search term's pattern only consists of ASCII 7 bit characters; otherwise false

containsWildcard

public boolean containsWildcard()
Checks if this search term's pattern contains wildcard characters '*' and '?'.

This method implies that this search is some kind of string search term. Returns false if not appropriate.

Returns:
true if this search term's pattern contains wildcard characters; otherwise false