search flags added

This commit is contained in:
Clivern 2017-08-12 01:25:32 +02:00
commit b0fef24df4
28 changed files with 844 additions and 8 deletions

View file

@ -5,6 +5,8 @@
namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Search Class
*
@ -21,12 +23,12 @@ class Search
/**
* Add Condition
*
* @param string $condition
* @param Condition $condition
* @return Search
*/
public function addCondition($condition)
public function addCondition(Condition $condition)
{
$this->conditions[] = $condition;
$this->conditions[] = (string) $condition;
return $this;
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* All Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class All implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "ALL";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Answered Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Answered implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "ANSWERED";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* BCC Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class BCC implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "BCC \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Before Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Before implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "BEFORE \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Body Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Body implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "BODY \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* CC Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class CC implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "CC \"{$this->data}\"";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Deleted Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Deleted implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "DELETED";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Flagged Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Flagged implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "FLAGGED";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* From Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class From implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "FROM \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Keyword Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Keyword implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "KEYWORD \"{$this->data}\"";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* New Flag Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class NewFlag implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "NEW";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Old Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Old implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "OLD";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* On Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class On implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "ON \"{$this->data}\"";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* All Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Recent implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "RECENT";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Seen Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Seen implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "SEEN";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Since Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Since implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "SINCE \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Subject Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Subject implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "SUBJECT \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* Text Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class Text implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "TEXT \"{$this->data}\"";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* To Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class To implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "TO \"{$this->data}\"";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* UnAnswered Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class UnAnswered implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "UNANSWERED";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* UnDeleted Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class UnDeleted implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "UNDELETED";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* UnFlagged Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class UnFlagged implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "UNFLAGGED";
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* UnKeyword Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class UnKeyword implements Condition
{
/**
* @var string
*/
protected $data;
/**
* Class Constructor
*
* @param string $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "UNKEYWORD \"{$this->data}\"";
}
}

View file

@ -0,0 +1,26 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition;
/**
* UnSeen Class
*
* @package Clivern\Imap\Core\Search\Condition
*/
class UnSeen implements Condition
{
/**
* Query String
*
* @return string
*/
public function __toString()
{
return "UNSEEN";
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* @author clivern <hello@clivern.com>
*/
namespace Clivern\Imap\Core\Search\Contract;
/**
* Condition Interface
*
* @package Clivern\Imap\Core\Search\Contract
*/
interface Condition
{
public function __toString();
}

View file

@ -75,7 +75,7 @@ class MailBox
* Get message ids
*
* @param Search $search
* @return MessageIterator|Message[]
* @return MessageIterator
*/
public function getMessages(Search $search = null)
{

View file

@ -8,12 +8,14 @@ class SearchTest extends TestCase
public function testConditionBuilder()
{
$search = new \Clivern\Imap\Core\Search();
$search->addCondition('RECENT')->addCondition('BCC "string"')->addCondition('NEW');
$search->addCondition(new \Clivern\Imap\Core\Search\Condition\To("hello@clivern.com"))
->addCondition(new \Clivern\Imap\Core\Search\Condition\BCC("hello@clivern.com"))
->addCondition(new \Clivern\Imap\Core\Search\Condition\NewFlag());
$this->assertEquals($search->getConditions(), [
'RECENT',
'BCC "string"',
'TO "hello@clivern.com"',
'BCC "hello@clivern.com"',
'NEW'
]);
$this->assertEquals((string) $search, 'RECENT BCC "string" NEW');
$this->assertEquals((string) $search, 'TO "hello@clivern.com" BCC "hello@clivern.com" NEW');
}
}