Skip to content

Commit

Permalink
Add search test and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Jan 4, 2015
1 parent 2fda77a commit a8f73b2
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 65 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ foreach ($messages as $message) {
}
```

#### Searching for Messages

```php
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Email\To;
use Ddeboer\Imap\Search\Text\Body;

$search = new SearchExpression();
$search->addCondition(new To('[email protected]'))
->addCondition(new Body('contents'))
;

$messages = $mailbox->getMessages($search);
```

#### Message Properties and Operations

Get message number and unique [message id](http://en.wikipedia.org/wiki/Message-ID)
in the form <...>:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Represents a condition that can be used in a search expression.
*/
abstract class Condition
abstract class AbstractCondition
{
/**
* Converts the condition to a string that can be sent to the IMAP server.
Expand Down
5 changes: 3 additions & 2 deletions src/Search/Date.php → src/Search/Date/AbstractDate.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace Ddeboer\Imap\Search;
namespace Ddeboer\Imap\Search\Date;

use DateTime;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a date condition.
*/
abstract class Date extends Condition
abstract class AbstractDate extends AbstractCondition
{
/**
* Format for dates to be sent to the IMAP server.
Expand Down
4 changes: 1 addition & 3 deletions src/Search/Date/After.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Ddeboer\Imap\Search\Date;

use Ddeboer\Imap\Search\Date;

/**
* Represents a date after condition. Messages must have a date after the
* specified date in order to match the condition.
*/
class After extends Date
class After extends AbstractDate
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 1 addition & 3 deletions src/Search/Date/Before.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Ddeboer\Imap\Search\Date;

use Ddeboer\Imap\Search\Date;

/**
* Represents a date before condition. Messages must have a date before the
* specified date in order to match the condition.
*/
class Before extends Date
class Before extends AbstractDate
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 1 addition & 3 deletions src/Search/Date/On.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Ddeboer\Imap\Search\Date;

use Ddeboer\Imap\Search\Date;

/**
* Represents a date on condition. Messages must have a date matching the
* specified date in order to match the condition.
*/
class On extends Date
class On extends AbstractDate
{
/**
* Returns the keyword that the condition represents.
Expand Down
6 changes: 4 additions & 2 deletions src/Search/Email.php → src/Search/Email/AbstractEmail.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace Ddeboer\Imap\Search;
namespace Ddeboer\Imap\Search\Email;

use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an email condition.
*/
abstract class Email extends Condition
abstract class AbstractEmail extends AbstractCondition
{
/**
* Email address for the condition.
Expand Down
4 changes: 1 addition & 3 deletions src/Search/Email/FromAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Ddeboer\Imap\Search\Email;

use Ddeboer\Imap\Search\Email;

/**
* Represents a "From" email address condition. Messages must have been sent
* from the specified email address in order to match the condition.
*/
class FromAddress extends Email
class FromAddress extends AbstractEmail
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 1 addition & 3 deletions src/Search/Email/To.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Ddeboer\Imap\Search\Email;

use Ddeboer\Imap\Search\Email;

/**
* Represents a "To" email address condition. Messages must have been addressed
* to the specified recipient (along with any others) in order to match the
* condition.
*/
class To extends Email
class To extends AbstractEmail
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Answered.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an ANSWERED flag condition. Messages must have the \\ANSWERED flag
* set in order to match the condition.
*/
class Answered extends Condition
class Answered extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Flagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a FLAGGED flag condition. Messages must have the \\FLAGGED flag
* (i.e. urgent or important) set in order to match the condition.
*/
class Flagged extends Condition
class Flagged extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an RECENT flag condition. Messages must have the \\RECENT flag
* set in order to match the condition.
*/
class Recent extends Condition
class Recent extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Seen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an SEEN flag condition. Messages must have the \\SEEN flag
* set in order to match the condition.
*/
class Seen extends Condition
class Seen extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Unanswered.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an UNANSWERED flag condition. Messages must not have the
* \\ANSWERED flag set in order to match the condition.
*/
class Unanswered extends Condition
class Unanswered extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Unflagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a UNFLAGGED flag condition. Messages must no have the \\FLAGGED
* flag (i.e. urgent or important) set in order to match the condition.
*/
class Unflagged extends Condition
class Unflagged extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/Flag/Unseen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\Flag;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an UNSEEN flag condition. Messages must not have the \\SEEN flag
* set in order to match the condition.
*/
class Unseen extends Condition
class Unseen extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/LogicalOperator/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\LogicalOperator;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an ALL operator. Messages must match all conditions following this
* operator in order to match the expression.
*/
class All extends Condition
class All extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/LogicalOperator/OrConditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\LogicalOperator;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an OR operator. Messages only need to match one of the conditions
* after this operator to match the expression.
*/
class OrConditions extends Condition
class OrConditions extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/State/Deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\State;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a DELETED condition. Messages must have been marked for deletion
* but not yet expunged in order to match the condition.
*/
class Deleted extends Condition
class Deleted extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/State/NewMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Ddeboer\Imap\Search\State;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a NEW condition. Only new messages will match this condition.
*/
class NewMessage extends Condition
class NewMessage extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/State/Old.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Ddeboer\Imap\Search\State;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents an OLD condition. Only old messages will match this condition.
*/
class Old extends Condition
class Old extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
4 changes: 2 additions & 2 deletions src/Search/State/Undeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ddeboer\Imap\Search\State;

use Ddeboer\Imap\Search\Condition;
use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a UNDELETED condition. Messages must not have been marked for
* deletion in order to match the condition.
*/
class Undeleted extends Condition
class Undeleted extends AbstractCondition
{
/**
* Returns the keyword that the condition represents.
Expand Down
6 changes: 4 additions & 2 deletions src/Search/Text.php → src/Search/Text/AbstractText.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

namespace Ddeboer\Imap\Search;
namespace Ddeboer\Imap\Search\Text;

use Ddeboer\Imap\Search\AbstractCondition;

/**
* Represents a text based condition. Text based conditions use a contains
* restriction.
*/
abstract class Text extends Condition
abstract class AbstractText extends AbstractCondition
{
/**
* Text to be used for the condition.
Expand Down
2 changes: 0 additions & 2 deletions src/Search/Text/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Ddeboer\Imap\Search\Text;

use Ddeboer\Imap\Search\Text;

/**
* Represents a body text contains condition. Messages must have a body
* containing the specified text in order to match the condition.
Expand Down
2 changes: 0 additions & 2 deletions src/Search/Text/Keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Ddeboer\Imap\Search\Text;

use Ddeboer\Imap\Search\Text;

/**
* Represents a keyword text contains condition. Messages must have a keyword
* matching the specified text in order to match the condition.
Expand Down
2 changes: 0 additions & 2 deletions src/Search/Text/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Ddeboer\Imap\Search\Text;

use Ddeboer\Imap\Search\Text;

/**
* Represents a subject contains condition. Messages must have a subject
* containing the specified text in order to match the condition.
Expand Down
Loading

0 comments on commit a8f73b2

Please sign in to comment.