181 lines
2.6 KiB
PHP
181 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Deblan\MailClient;
|
|
|
|
/**
|
|
* Class Criteria
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class Criteria
|
|
{
|
|
/**
|
|
* @const string
|
|
*/
|
|
const ALL = "ALL";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const ANSWERED = "ANSWERED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const BCC = "BCC";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const BEFORE = "BEFORE";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const BODY = "BODY";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const CC = "CC";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const DELETED = "DELETED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const FLAGGED = "FLAGGED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const FROM = "FROM";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const KEYWORD = "KEYWORD";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const INGOING = "NEW";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const OLD = "OLD";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const ON = "ON";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const RECENT = "RECENT";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const SEEN = "SEEN";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const SINCE = "SINCE";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const SUBJECT = "SUBJECT";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const TEXT = "TEXT";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const TO = "TO";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const UNANSWERED = "UNANSWERED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const UNDELETED = "UNDELETED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const UNFLAGGED = "UNFLAGGED";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const UNKEYWORD = "UNKEYWORD";
|
|
|
|
/**
|
|
* @const string
|
|
*/
|
|
const UNSEEN = "UNSEEN";
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $filters = [];
|
|
|
|
/**
|
|
* Create a new instance of Criteria
|
|
*
|
|
* @return Criteria
|
|
*/
|
|
public static function create()
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
/**
|
|
* Append a filter
|
|
*
|
|
* @return Criteria
|
|
* @param string $criteria
|
|
* @param string $value
|
|
*/
|
|
public function filterBy($criteria, $value = null)
|
|
{
|
|
$filter = $criteria;
|
|
|
|
$in = in_array(
|
|
$criteria,
|
|
[self::UNKEYWORD, self::TEXT, self::SINCE, self::SUBJECT, self::ON, self::KEYWORD, self::FROM, self::CC, self::BEFORE, self::BCC]
|
|
);
|
|
|
|
if ($in) {
|
|
$filter.= ' "'.str_replace('"', '\\"', (string) $value).'"';
|
|
}
|
|
|
|
$this->filters[] = $filter;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get a valid string for filtering
|
|
*
|
|
* @return string
|
|
*/
|
|
public function build()
|
|
{
|
|
return implode(' ', $this->filters);
|
|
}
|
|
}
|