Documentation

Horde_Imap_Client_Search_Query
in package
implements Serializable

Abstraction of the IMAP4rev1 search criteria (see RFC 3501 [6.4.4]).

Allows translation between abstracted search criteria and a generated IMAP search criteria string suitable for sending to a remote IMAP server.

Tags
author

Michael Slusarz slusarz@horde.org

category

Horde

copyright

2008-2017 Horde LLC

license

http://www.horde.org/licenses/lgpl21 LGPL 2.1

Interfaces, Classes, Traits and Enums

Serializable

Table of Contents

DATE_BEFORE  = 'BEFORE'
Constants for dateSearch()
DATE_ON  = 'ON'
DATE_SINCE  = 'SINCE'
INTERVAL_OLDER  = 'OLDER'
Constants for intervalSearch()
INTERVAL_YOUNGER  = 'YOUNGER'
VERSION  = 3
Serialized version.
$_charset  : string
The charset of the search strings. All text strings must be in this charset. By default, this is 'US-ASCII' (see RFC 3501 [6.4.4]).
$_search  : array<string|int, mixed>
The list of search params.
__serialize()  : array<string|int, mixed>
__toString()  : mixed
String representation: The IMAP search string.
__unserialize()  : mixed
andSearch()  : mixed
AND queries - the contents of this query will be AND'ed (in its entirety) with the contents of EACH of the queries passed in. All AND'd queries must share the same charset as this query.
build()  : array<string|int, mixed>
Builds an IMAP4rev1 compliant search string.
charset()  : mixed
Sets the charset of the search text.
dateSearch()  : mixed
Search for messages within a date range.
dateTimeSearch()  : mixed
Search for messages within a date and time range.
flag()  : mixed
Search for a flag/keywords.
flagSearch()  : bool
Determines if flags are a part of the search.
headerText()  : mixed
Search for text in the header of a message.
ids()  : mixed
Search for messages within a given UID range. Only one message range can be specified per query.
intervalSearch()  : mixed
Search for messages within a given interval. Only one interval of each type can be specified per search query. If the IMAP server supports the WITHIN extension (RFC 5032), it will be used. Otherwise, the search query will be dynamically created using IMAP4rev1 search terms.
modseq()  : mixed
Search for messages modified since a specific moment. The IMAP server must support the CONDSTORE extension (RFC 7162) for this query to be used.
newMsgs()  : mixed
Search for either new messages (messages that have the '\Recent' flag but not the '\Seen' flag) or old messages (messages that do not have the '\Recent' flag). If new messages are searched, this will clear any '\Recent' or '\Unseen' flag searches. If old messages are searched, this will clear any '\Recent' flag search.
orSearch()  : mixed
OR a query - the contents of this query will be OR'ed (in its entirety) with the contents of EACH of the queries passed in. All OR'd queries must share the same charset as this query. All contents of any single query will be AND'ed together.
previousSearch()  : mixed
Use the results from the previous SEARCH command. The IMAP server must support the SEARCHRES extension (RFC 5182) for this query to be used.
serialize()  : string
Serialization.
size()  : mixed
Search for messages smaller/larger than a certain size.
text()  : mixed
Search for text in either the entire message, or just the body.
unserialize()  : mixed
Unserialization.
_addFuzzy()  : mixed
Adds fuzzy modifier to search keys.
_buildAndOr()  : bool
Builds the AND/OR query.

Constants

DATE_BEFORE

Constants for dateSearch()

public mixed DATE_BEFORE = 'BEFORE'

DATE_ON

public mixed DATE_ON = 'ON'

DATE_SINCE

public mixed DATE_SINCE = 'SINCE'

INTERVAL_OLDER

Constants for intervalSearch()

public mixed INTERVAL_OLDER = 'OLDER'

INTERVAL_YOUNGER

public mixed INTERVAL_YOUNGER = 'YOUNGER'

VERSION

Serialized version.

public mixed VERSION = 3

Properties

$_charset

The charset of the search strings. All text strings must be in this charset. By default, this is 'US-ASCII' (see RFC 3501 [6.4.4]).

protected string $_charset = \null

The list of search params.

protected array<string|int, mixed> $_search = array()

Methods

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__toString()

String representation: The IMAP search string.

public __toString() : mixed
Return values
mixed

__unserialize()

public __unserialize(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Return values
mixed

andSearch()

AND queries - the contents of this query will be AND'ed (in its entirety) with the contents of EACH of the queries passed in. All AND'd queries must share the same charset as this query.

public andSearch(mixed $queries) : mixed
Parameters
$queries : mixed

A query, or an array of queries, to AND with the current query.

Return values
mixed

build()

Builds an IMAP4rev1 compliant search string.

public build([Horde_Imap_Client_Base $exts = array() ]) : array<string|int, mixed>
Parameters
$exts : Horde_Imap_Client_Base = array()

The server object this query will be run on (@since 2.24.0), a Horde_Imap_Client_Data_Capability object (@since 2.24.0), or the list of extensions present on the server (@deprecated). If null, all extensions are assumed to be available.

Tags
todo

Change default of $exts to null.

throws
Horde_Imap_Client_Data_Format_Exception
throws
Horde_Imap_Client_Exception_NoSupportExtension
Return values
array<string|int, mixed>

An array with these elements:

  • charset: (string) The charset of the search string. If null, no text strings appear in query.
  • exts: (array) The list of IMAP extensions used to create the string.
  • query: (Horde_Imap_Client_Data_Format_List) The IMAP search command.

charset()

Sets the charset of the search text.

public charset(string $charset[, bool $convert = true ]) : mixed
Parameters
$charset : string

The charset to use for the search.

$convert : bool = true

Convert existing text values?

Tags
throws
Horde_Imap_Client_Exception_SearchCharset
Return values
mixed

dateSearch()

Search for messages within a date range.

public dateSearch(mixed $date, string $range[, bool $header = true ][, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$date : mixed

DateTime or Horde_Date object.

$range : string

Either:

  • Horde_Imap_Client_Search_Query::DATE_BEFORE
  • Horde_Imap_Client_Search_Query::DATE_ON
  • Horde_Imap_Client_Search_Query::DATE_SINCE
$header : bool = true

If true, search using the date in the message headers. If false, search using the internal IMAP date (usually arrival time).

$not : bool = false

If true, do a 'NOT' search of the range.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

dateTimeSearch()

Search for messages within a date and time range.

public dateTimeSearch(mixed $date, string $range[, bool $header = true ][, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$date : mixed

DateTime or Horde_Date object.

$range : string

Either:

  • Horde_Imap_Client_Search_Query::DATE_BEFORE
  • Horde_Imap_Client_Search_Query::DATE_ON
  • Horde_Imap_Client_Search_Query::DATE_SINCE
$header : bool = true

If true, search using the date in the message headers. If false, search using the internal IMAP date (usually arrival time).

$not : bool = false

If true, do a 'NOT' search of the range.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

flag()

Search for a flag/keywords.

public flag(string $name[, bool $set = true ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$name : string

The flag or keyword name.

$set : bool = true

If true, search for messages that have the flag set. If false, search for messages that do not have the flag set.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

flagSearch()

Determines if flags are a part of the search.

public flagSearch() : bool
Return values
bool

True if search query involves flags.

headerText()

Search for text in the header of a message.

public headerText(string $header, string $text[, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$header : string

The header field.

$text : string

The search text.

$not : bool = false

If true, do a 'NOT' search of $text.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

ids()

Search for messages within a given UID range. Only one message range can be specified per query.

public ids(Horde_Imap_Client_Ids $ids[, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$ids : Horde_Imap_Client_Ids

The list of UIDs to search.

$not : bool = false

If true, do a 'NOT' search of the UIDs.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

intervalSearch()

Search for messages within a given interval. Only one interval of each type can be specified per search query. If the IMAP server supports the WITHIN extension (RFC 5032), it will be used. Otherwise, the search query will be dynamically created using IMAP4rev1 search terms.

public intervalSearch(int $interval, string $range[, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$interval : int

Seconds from the present.

$range : string

Either:

  • Horde_Imap_Client_Search_Query::INTERVAL_OLDER
  • Horde_Imap_Client_Search_Query::INTERVAL_YOUNGER
$not : bool = false

If true, do a 'NOT' search.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

modseq()

Search for messages modified since a specific moment. The IMAP server must support the CONDSTORE extension (RFC 7162) for this query to be used.

public modseq(int $value[, string $name = null ][, string $type = null ][, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$value : int

The mod-sequence value.

$name : string = null

The entry-name string.

$type : string = null

Either 'shared', 'priv', or 'all'. Defaults to 'all'

$not : bool = false

If true, do a 'NOT' search.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

newMsgs()

Search for either new messages (messages that have the '\Recent' flag but not the '\Seen' flag) or old messages (messages that do not have the '\Recent' flag). If new messages are searched, this will clear any '\Recent' or '\Unseen' flag searches. If old messages are searched, this will clear any '\Recent' flag search.

public newMsgs([bool $newmsgs = true ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$newmsgs : bool = true

If true, searches for new messages. Else, search for old messages.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

orSearch()

OR a query - the contents of this query will be OR'ed (in its entirety) with the contents of EACH of the queries passed in. All OR'd queries must share the same charset as this query. All contents of any single query will be AND'ed together.

public orSearch(mixed $queries) : mixed
Parameters
$queries : mixed

A query, or an array of queries, to OR with the current query.

Return values
mixed

previousSearch()

Use the results from the previous SEARCH command. The IMAP server must support the SEARCHRES extension (RFC 5182) for this query to be used.

public previousSearch([bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$not : bool = false

If true, don't match the previous query.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

serialize()

Serialization.

public serialize() : string
Return values
string

Serialized data.

size()

Search for messages smaller/larger than a certain size.

public size(int $size[, bool $larger = false ][, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$size : int

The size (in bytes).

$larger : bool = false

Search for messages larger than $size?

$not : bool = false

If true, do a 'NOT' search of $text.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Tags
todo:

Remove $not for 3.0

Return values
mixed

text()

Search for text in either the entire message, or just the body.

public text(string $text[, bool $bodyonly = true ][, bool $not = false ][, array<string|int, mixed> $opts = array() ]) : mixed
Parameters
$text : string

The search text.

$bodyonly : bool = true

If true, only search in the body of the message. If false, also search in the headers.

$not : bool = false

If true, do a 'NOT' search of $text.

$opts : array<string|int, mixed> = array()

Additional options:

  • fuzzy: (boolean) If true, perform a fuzzy search. The IMAP server MUST support RFC 6203.
Return values
mixed

unserialize()

Unserialization.

public unserialize(string $data) : mixed
Parameters
$data : string

Serialized data.

Tags
throws
Exception
Return values
mixed

_addFuzzy()

Adds fuzzy modifier to search keys.

protected _addFuzzy(bool $add, array<string|int, mixed> &$temp) : mixed
Parameters
$add : bool

Add the fuzzy modifier?

$temp : array<string|int, mixed>

Temporary build data.

Tags
throws
Horde_Imap_Client_Exception_NoSupport_Extension
Return values
mixed

_buildAndOr()

Builds the AND/OR query.

protected _buildAndOr(string $type, array<string|int, mixed> $data, string &$charset, array<string|int, mixed> &$exts_used, Horde_Imap_Client_Data_Format_List &$cmds) : bool
Parameters
$type : string

'AND' or 'OR'.

$data : array<string|int, mixed>

Query data.

$charset : string

Search charset.

$exts_used : array<string|int, mixed>

IMAP extensions used.

$cmds : Horde_Imap_Client_Data_Format_List

Command list.

Return values
bool

True if query might return results.

Search results