Merge pull request #10 from Clivern/feature/ci

Feature/ci
This commit is contained in:
A. F 2019-02-25 19:38:19 +01:00 committed by GitHub
commit 59ff2547e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 2054 additions and 680 deletions

23
phpunit.xml.dist Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php">
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>

View file

@ -1,15 +0,0 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

6
.gitignore vendored
View file

@ -1,5 +1,5 @@
/vendor /vendor
.phpintel/
coverage.clover coverage.clover
build/ .env
index.php .php_cs.cache
build

39
.php_cs.dist Normal file
View file

@ -0,0 +1,39 @@
<?php
$fileHeaderComment = <<<COMMENT
This file is part of the Imap PHP package.
(c) Clivern <hello@clivern.com>
COMMENT;
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;
return PhpCsFixer\Config::create()
->setIndent(" ")
->setLineEnding("\n")
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'no_php4_constructor' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'phpdoc_add_missing_param_annotation' => true,
'ordered_class_elements'=> true,
'phpdoc_types_order' => true,
'logical_operators' => true,
])
->setFinder($finder)
->setCacheFile(__DIR__.'/.php_cs.cache')
;

View file

@ -1,5 +1,4 @@
language: php language: php
dist: precise
php: php:
- 5.6 - 5.6
@ -16,4 +15,4 @@ before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
script: script:
- vendor/bin/phpunit --bootstrap vendor/autoload.php --coverage-text --coverage-clover=coverage.clover - make ci

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2017 A. F Copyright (c) 2017 Cliven
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

57
Makefile Normal file
View file

@ -0,0 +1,57 @@
COMPOSER ?= composer
PHPUNIT_OPTS =
composer:
$(COMPOSER) install
fix:
./vendor/bin/php-cs-fixer fix
fix-diff:
./vendor/bin/php-cs-fixer fix --diff --dry-run -v
test: composer
vendor/bin/phpunit -c .
lint: lint-php phpcs php-cs lint-composer lint-eol
@echo All good.
lint-eol:
@echo "\n==> Validating unix style line endings of files:files"
@! grep -lIUr --color '^M' src/ composer.json composer.lock || ( echo '[ERROR] Above files have CRLF line endings' && exit 1 )
@echo All files have valid line endings
lint-composer:
@echo "\n==> Validating composer.json and composer.lock:"
$(COMPOSER) validate --strict
lint-php:
@echo "\n==> Validating all php files:"
@find src tests -type f -name \*.php | while read file; do php -l "$$file" || exit 1; done
phpcs:
vendor/bin/phpcs
php-cs:
vendor/bin/php-cs-fixer fix --diff --dry-run -v
coverage: composer
vendor/bin/phpunit -c .
ci: composer lint test
@echo "All quality checks passed"
.PHONY: test composer coverage phpcs php-cs lint lint-php ci

View file

@ -2,7 +2,7 @@ Imap
==== ====
:mailbox_with_mail: Access Mailbox Using PHP IMAP. :mailbox_with_mail: Access Mailbox Using PHP IMAP.
*Current Version: 1.0.4* *Current Version: 1.0.5*
[![Build Status](https://travis-ci.org/Clivern/Imap.svg?branch=master)](https://travis-ci.org/Clivern/Imap) [![Build Status](https://travis-ci.org/Clivern/Imap.svg?branch=master)](https://travis-ci.org/Clivern/Imap)
@ -265,6 +265,12 @@ Misc
Changelog Changelog
--------- ---------
Version 1.0.5:
```
Enhance code style.
Automate code fixes and linting.
```
Version 1.0.4: Version 1.0.4:
``` ```
Fix for plain text messages. Fix for plain text messages.

View file

@ -4,7 +4,6 @@
"description": "Access Mailbox Using PHP IMAP", "description": "Access Mailbox Using PHP IMAP",
"keywords": ["clivern", "imap"], "keywords": ["clivern", "imap"],
"license": "MIT", "license": "MIT",
"type": "project",
"homepage": "https://github.com/clivern/imap", "homepage": "https://github.com/clivern/imap",
"authors": [ "authors": [
{ {
@ -17,7 +16,9 @@
"php": ">=5.6.4" "php": ">=5.6.4"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~5.7" "phpunit/phpunit": "~5.7",
"friendsofphp/php-cs-fixer": "^2.14",
"squizlabs/php_codesniffer": "^3.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

1405
composer.lock generated

File diff suppressed because it is too large Load diff

7
phpcs.xml Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset name="MessageBirdCodingStandard">
<description>Imap coding standard.</description>
<file>src</file>
<file>tests</file>
<rule ref="PSR2" />
</ruleset>

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core; namespace Clivern\Imap\Core;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Exception\AuthenticationFailedException; use Clivern\Imap\Core\Exception\AuthenticationFailedException;
/** /**
* Connection Class * Connection Class.
*
* @package Clivern\Imap\Core
*/ */
class Connection class Connection
{ {
/** /**
* @var string * @var string
*/ */
protected $server; protected $server;
/** /**
* @var integer * @var int
*/ */
protected $port; protected $port;
@ -61,7 +60,7 @@ class Connection
protected $timeout; protected $timeout;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $server * @param string $server
* @param string $port * @param string $port
@ -69,9 +68,8 @@ class Connection
* @param string $password * @param string $password
* @param string $flag * @param string $flag
* @param string $folder * @param string $folder
* @return void
*/ */
public function __construct($server, $port, $email, $password, $flag = "/ssl", $folder = "INBOX") public function __construct($server, $port, $email, $password, $flag = '/ssl', $folder = 'INBOX')
{ {
$this->server = $server; $this->server = $server;
$this->port = $port; $this->port = $port;
@ -82,55 +80,59 @@ class Connection
} }
/** /**
* Connect to IMAP Email * Connect to IMAP Email.
*
* @throws AuthenticationFailedException
* *
* @return Connection * @return Connection
* @throws AuthenticationFailedException
*/ */
public function connect() public function connect()
{ {
try { try {
$this->stream = imap_open("{" . $this->server . ":" . $this->port . $this->flag . "}" . $this->folder, $this->email, $this->password); $this->stream = imap_open(
'{'.$this->server.':'.$this->port.$this->flag.'}'.$this->folder,
$this->email,
$this->password
);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new AuthenticationFailedException("Error! Connecting to Imap Email."); throw new AuthenticationFailedException('Error! Connecting to Imap Email.');
} }
return $this; return $this;
} }
public function reconnect($folder = "INBOX") public function reconnect($folder = 'INBOX')
{ {
try { try {
imap_reopen($this->stream, "{" . $this->server . ":" . $this->port . $this->flag . "}" . $folder); imap_reopen($this->stream, '{'.$this->server.':'.$this->port.$this->flag.'}'.$folder);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new AuthenticationFailedException("Error! Connecting to Imap Email."); throw new AuthenticationFailedException('Error! Connecting to Imap Email.');
} }
} }
public function survive($folder = "INBOX") public function survive($folder = 'INBOX')
{ {
if( !$this->ping() || ($this->folder != $folder) ) { if (!$this->ping() || ($this->folder !== $folder)) {
$this->reconnect($folder); $this->reconnect($folder);
} }
} }
/** /**
* Set Timeout * Set Timeout.
* *
* @param string $timeout_type it may be IMAP_OPENTIMEOUT, IMAP_READTIMEOUT, IMAP_WRITETIMEOUT, or IMAP_CLOSETIMEOUT * @param string $timeout_type it may be IMAP_OPENTIMEOUT, IMAP_READTIMEOUT, IMAP_WRITETIMEOUT, or IMAP_CLOSETIMEOUT
* @param integer $timeout time in seconds or -1 * @param int $timeout time in seconds or -1
* @return void
*/ */
public function setTimeout($timeout_type, $timeout) public function setTimeout($timeout_type, $timeout)
{ {
$this->timeout_type = $timeout_type; $this->timeout_type = $timeout_type;
$this->timeout = $timeout; $this->timeout = $timeout;
return (boolean) imap_timeout($timeout_type, $timeout); return (bool) imap_timeout($timeout_type, $timeout);
} }
/** /**
* Get Stream * Get Stream.
* *
* @return mixed * @return mixed
*/ */
@ -140,7 +142,7 @@ class Connection
} }
/** /**
* Get Server * Get Server.
* *
* @return string * @return string
*/ */
@ -150,19 +152,20 @@ class Connection
} }
/** /**
* Check Connection * Check Connection.
* *
* @return boolean * @return bool
*/ */
public function checkConnection() public function checkConnection()
{ {
return (!is_null($this->stream) && imap_ping($this->stream)); return null !== $this->stream && imap_ping($this->stream);
} }
/** /**
* Get Quota * Get Quota.
* *
* @param string $folder * @param string $folder
*
* @return array * @return array
*/ */
public function getQuota($folder = 'INBOX') public function getQuota($folder = 'INBOX')
@ -171,20 +174,21 @@ class Connection
return [ return [
'usage' => (isset($data['usage'])) ? $data['usage'] : false, 'usage' => (isset($data['usage'])) ? $data['usage'] : false,
'limit' => (isset($data['limit'])) ? $data['limit'] : false 'limit' => (isset($data['limit'])) ? $data['limit'] : false,
]; ];
} }
/** /**
* Get Status * Get Status.
* *
* @param string $folder * @param string $folder
* @param string $flag * @param string $flag
*
* @return array * @return array
*/ */
public function getStatus($folder = 'INBOX', $flag = SA_ALL) public function getStatus($folder = 'INBOX', $flag = SA_ALL)
{ {
$data = imap_status($this->stream, "{" . $this->server . "}" . $folder, $flag); $data = imap_status($this->stream, '{'.$this->server.'}'.$folder, $flag);
return [ return [
'flags' => (isset($data->flags)) ? $data->flags : false, 'flags' => (isset($data->flags)) ? $data->flags : false,
@ -192,12 +196,12 @@ class Connection
'recent' => (isset($data->recent)) ? $data->recent : false, 'recent' => (isset($data->recent)) ? $data->recent : false,
'unseen' => (isset($data->unseen)) ? $data->unseen : false, 'unseen' => (isset($data->unseen)) ? $data->unseen : false,
'uidnext' => (isset($data->uidnext)) ? $data->uidnext : false, 'uidnext' => (isset($data->uidnext)) ? $data->uidnext : false,
'uidvalidity' => (isset($data->uidvalidity)) ? $data->uidvalidity : false 'uidvalidity' => (isset($data->uidvalidity)) ? $data->uidvalidity : false,
]; ];
} }
/** /**
* Check MailBox Data * Check MailBox Data.
* *
* @return array * @return array
*/ */
@ -210,22 +214,22 @@ class Connection
'driver' => (isset($data->Driver)) ? $data->Driver : false, 'driver' => (isset($data->Driver)) ? $data->Driver : false,
'mailbox' => (isset($data->Mailbox)) ? $data->Mailbox : false, 'mailbox' => (isset($data->Mailbox)) ? $data->Mailbox : false,
'nmsgs' => (isset($data->Nmsgs)) ? $data->Nmsgs : false, 'nmsgs' => (isset($data->Nmsgs)) ? $data->Nmsgs : false,
'recent' => (isset($data->Recent)) ? $data->Recent : false 'recent' => (isset($data->Recent)) ? $data->Recent : false,
]; ];
} }
/** /**
* Ping Connection * Ping Connection.
* *
* @return boolean * @return bool
*/ */
public function ping() public function ping()
{ {
return (boolean) imap_ping($this->stream); return (bool) imap_ping($this->stream);
} }
/** /**
* Get Errors * Get Errors.
* *
* @return array * @return array
*/ */
@ -233,11 +237,11 @@ class Connection
{ {
$errors = imap_errors(); $errors = imap_errors();
return (is_array($errors)) ? $errors : []; return (\is_array($errors)) ? $errors : [];
} }
/** /**
* Get Alerts * Get Alerts.
* *
* @return array * @return array
*/ */
@ -245,11 +249,11 @@ class Connection
{ {
$alerts = imap_alerts(); $alerts = imap_alerts();
return (is_array($alerts)) ? $alerts : []; return (\is_array($alerts)) ? $alerts : [];
} }
/** /**
* Get Last Error * Get Last Error.
* *
* @return string * @return string
*/ */
@ -261,20 +265,22 @@ class Connection
} }
/** /**
* Disconnect * Disconnect.
* *
* @param integer $flag * @param int $flag
* @return boolean *
* @return bool
*/ */
public function disconnect($flag = \CL_EXPUNGE) public function disconnect($flag = \CL_EXPUNGE)
{ {
if( !is_null($this->stream) && imap_ping($this->stream) ){ if (null !== $this->stream && imap_ping($this->stream)) {
if (imap_close($this->stream, $flag)) { if (imap_close($this->stream, $flag)) {
$this->stream = null; $this->stream = null;
return true; return true;
}else{
return false;
} }
return false;
} }
return false; return false;

View file

@ -1,25 +1,24 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Exception; namespace Clivern\Imap\Core\Exception;
/** /**
* Connection Error Class * Connection Error Class.
*
* @package Clivern\Imap\Core\Exception
*/ */
class AuthenticationFailedException extends \Exception class AuthenticationFailedException extends \Exception
{ {
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $error * @param string $error
*/ */
public function __construct($error = null) public function __construct($error = null)
{ {
parent::__construct(sprintf("Authentication failed with error: %s", $error)); parent::__construct(sprintf('Authentication failed with error: %s', $error));
} }
} }

View file

@ -1,25 +1,24 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Exception; namespace Clivern\Imap\Core\Exception;
/** /**
* Folder Not Exist Error Class * Folder Not Exist Error Class.
*
* @package Clivern\Imap\Core\Exception
*/ */
class FolderNotExistException extends \Exception class FolderNotExistException extends \Exception
{ {
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $folder * @param string $folder
*/ */
public function __construct($folder = null) public function __construct($folder = null)
{ {
parent::__construct(sprintf("Mailbox folder not exist: %s", $folder)); parent::__construct(sprintf('Mailbox folder not exist: %s', $folder));
} }
} }

View file

@ -1,22 +1,21 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Exception; namespace Clivern\Imap\Core\Exception;
/** /**
* Connection Error Class * Connection Error Class.
*
* @package Clivern\Imap\Core\Exception
*/ */
class MessageDeleteException extends \Exception class MessageDeleteException extends \Exception
{ {
/** /**
* Class Constructor * Class Constructor.
* *
* @param integer $message_number * @param int $message_number
*/ */
public function __construct($message_number) public function __construct($message_number)
{ {

View file

@ -1,22 +1,21 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Exception; namespace Clivern\Imap\Core\Exception;
/** /**
* Connection Error Class * Connection Error Class.
*
* @package Clivern\Imap\Core\Exception
*/ */
class MessageDoesNotExistException extends \Exception class MessageDoesNotExistException extends \Exception
{ {
/** /**
* Class Constructor * Class Constructor.
* *
* @param integer $number * @param int $number
* @param string $error * @param string $error
*/ */
public function __construct($number, $error) public function __construct($number, $error)

View file

@ -1,22 +1,21 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Exception; namespace Clivern\Imap\Core\Exception;
/** /**
* Connection Error Class * Connection Error Class.
*
* @package Clivern\Imap\Core\Exception
*/ */
class MessageMoveException extends \Exception class MessageMoveException extends \Exception
{ {
/** /**
* Class Constructor * Class Constructor.
* *
* @param integer $message_number * @param int $message_number
* @param string $mailbox * @param string $mailbox
*/ */
public function __construct($message_number, $mailbox) public function __construct($message_number, $mailbox)

View file

@ -1,20 +1,19 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core; namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Connection;
use Clivern\Imap\Core\Message\Header;
use Clivern\Imap\Core\Message\Action; use Clivern\Imap\Core\Message\Action;
use Clivern\Imap\Core\Message\Attachment; use Clivern\Imap\Core\Message\Attachment;
use Clivern\Imap\Core\Message\Body; use Clivern\Imap\Core\Message\Body;
use Clivern\Imap\Core\Message\Header;
/** /**
* Message Class * Message Class.
*
* @package Clivern\Imap\Core
*/ */
class Message class Message
{ {
@ -44,17 +43,17 @@ class Message
protected $body; protected $body;
/** /**
* @var integer * @var int
*/ */
protected $uid; protected $uid;
/** /**
* @var integer * @var int
*/ */
protected $msg_number; protected $msg_number;
/** /**
* Message Constructor * Message Constructor.
* *
* @param Connection $connection * @param Connection $connection
*/ */
@ -67,9 +66,11 @@ class Message
} }
/** /**
* Set Message Number * Set Message Number.
*
* @param int $id
* @param mixed $msg_number
* *
* @param integer $id
* @return Message * @return Message
*/ */
public function setMsgNo($msg_number) public function setMsgNo($msg_number)
@ -80,9 +81,9 @@ class Message
} }
/** /**
* Get Message Number * Get Message Number.
* *
* @return integer * @return int
*/ */
public function getMsgNo() public function getMsgNo()
{ {
@ -90,9 +91,10 @@ class Message
} }
/** /**
* Set UID * Set UID.
*
* @param int $uid
* *
* @param integer $uid
* @return Message * @return Message
*/ */
public function setUid($uid) public function setUid($uid)
@ -103,9 +105,9 @@ class Message
} }
/** /**
* Get UID * Get UID.
* *
* @return integer * @return int
*/ */
public function getUid() public function getUid()
{ {
@ -113,7 +115,7 @@ class Message
} }
/** /**
* Config Message Number & UID * Config Message Number & UID.
* *
* @return Message * @return Message
*/ */
@ -131,7 +133,7 @@ class Message
} }
/** /**
* Get Message Header Object * Get Message Header Object.
* *
* @return Header * @return Header
*/ */
@ -141,7 +143,7 @@ class Message
} }
/** /**
* Get Message Action Object * Get Message Action Object.
* *
* @return Action * @return Action
*/ */
@ -151,7 +153,7 @@ class Message
} }
/** /**
* Get Message Body Object * Get Message Body Object.
* *
* @return Body * @return Body
*/ */
@ -161,13 +163,13 @@ class Message
} }
/** /**
* Get Message Attachments * Get Message Attachments.
* *
* @return array * @return array
*/ */
public function attachments() public function attachments()
{ {
if( !is_null($this->attachments) ){ if (null !== $this->attachments) {
return $this->attachments; return $this->attachments;
} }
@ -185,16 +187,17 @@ class Message
} }
$this->attachments[$i] = new Attachment($this->connection); $this->attachments[$i] = new Attachment($this->connection);
$this->attachments[$i]->config($this->getMsgNo(), $this->getUid(), $index + 1, $part); $this->attachments[$i]->config($this->getMsgNo(), $this->getUid(), $index + 1, $part);
$i += 1; ++$i;
} }
return $this->attachments; return $this->attachments;
} }
/** /**
* Get Body * Get Body.
*
* @param int $options
* *
* @param integer $options
* @return string * @return string
*/ */
public function getBody($options = 0) public function getBody($options = 0)

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Message; namespace Clivern\Imap\Core\Message;
@ -8,31 +10,27 @@ namespace Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Connection; use Clivern\Imap\Core\Connection;
/** /**
* Action Class * Action Class.
*
* @package Clivern\Imap\Core\Message
*/ */
class Action class Action
{ {
/** /**
* @var Connection * @var Connection
*/ */
protected $connection; protected $connection;
/** /**
* @var integer * @var int
*/ */
protected $message_number; protected $message_number;
/** /**
* @var integer * @var int
*/ */
protected $message_uid; protected $message_uid;
/** /**
* Class Constructor * Class Constructor.
* *
* @param Connection $connection * @param Connection $connection
*/ */
@ -42,10 +40,11 @@ class Action
} }
/** /**
* Config Message * Config Message.
*
* @param int $message_number
* @param int $message_uid
* *
* @param integer $message_number
* @param integer $message_uid
* @return Action * @return Action
*/ */
public function config($message_number, $message_uid) public function config($message_number, $message_uid)
@ -57,22 +56,22 @@ class Action
} }
/** /**
* Delete Message * Delete Message.
* *
* @return boolean * @return bool
*/ */
public function delete() public function delete()
{ {
return (boolean) imap_delete($this->connection->getStream(), $this->message_uid, \FT_UID); return (bool) imap_delete($this->connection->getStream(), $this->message_uid, \FT_UID);
} }
/** /**
* Undelete Message * Undelete Message.
* *
* @return boolean * @return bool
*/ */
public function undelete() public function undelete()
{ {
return (boolean) imap_undelete($this->connection->getStream(), $this->message_uid, \FT_UID); return (bool) imap_undelete($this->connection->getStream(), $this->message_uid, \FT_UID);
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Message; namespace Clivern\Imap\Core\Message;
@ -8,25 +10,22 @@ namespace Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Connection; use Clivern\Imap\Core\Connection;
/** /**
* Attachment Class * Attachment Class.
*
* @package Clivern\Imap\Core\Message
*/ */
class Attachment class Attachment
{ {
/** /**
* @var Connection * @var Connection
*/ */
protected $connection; protected $connection;
/** /**
* @var integer * @var int
*/ */
protected $message_number; protected $message_number;
/** /**
* @var integer * @var int
*/ */
protected $message_uid; protected $message_uid;
@ -36,13 +35,12 @@ class Attachment
protected $attachment; protected $attachment;
/** /**
* @var Object * @var object
*/ */
protected $part; protected $part;
/** /**
* Class Constructor * Class Constructor.
* *
* @param Connection $connection * @param Connection $connection
*/ */
@ -52,12 +50,13 @@ class Attachment
} }
/** /**
* Config Attachment * Config Attachment.
* *
* @param integer $message_number * @param int $message_number
* @param integer $message_uid * @param int $message_uid
* @param integer $attachment_id * @param int $attachment_id
* @param object $part * @param object $part
*
* @return Attachment * @return Attachment
*/ */
public function config($message_number, $message_uid, $attachment_id, $part) public function config($message_number, $message_uid, $attachment_id, $part)
@ -73,10 +72,11 @@ class Attachment
} }
/** /**
* Get Attachment Property * Get Attachment Property.
* *
* @param string $key * @param string $key
* @param boolean $default * @param bool $default
*
* @return mixed * @return mixed
*/ */
public function get($key, $default = false) public function get($key, $default = false)
@ -85,7 +85,7 @@ class Attachment
} }
/** /**
* Get Filename * Get Filename.
* *
* @return mixed * @return mixed
*/ */
@ -95,7 +95,7 @@ class Attachment
} }
/** /**
* Get Extension * Get Extension.
* *
* @return mixed * @return mixed
*/ */
@ -105,7 +105,7 @@ class Attachment
} }
/** /**
* Get Size * Get Size.
* *
* @return mixed * @return mixed
*/ */
@ -115,7 +115,7 @@ class Attachment
} }
/** /**
* Get Encoding * Get Encoding.
* *
* @return mixed * @return mixed
*/ */
@ -125,7 +125,7 @@ class Attachment
} }
/** /**
* Get Bytes * Get Bytes.
* *
* @return mixed * @return mixed
*/ */
@ -135,7 +135,7 @@ class Attachment
} }
/** /**
* Get Plain Body * Get Plain Body.
* *
* @return mixed * @return mixed
*/ */
@ -145,39 +145,42 @@ class Attachment
return $this->get('plain_body'); return $this->get('plain_body');
} }
$this->attachment['plain_body'] = imap_fetchbody($this->connection->getStream(), $this->message_number, $this->attachment['index']); $this->attachment['plain_body'] = imap_fetchbody(
$this->connection->getStream(),
$this->message_number,
$this->attachment['index']
);
return $this->get('plain_body'); return $this->get('plain_body');
} }
/** /**
* Get Body * Get Body.
*
* @throws Exception
* *
* @return mixed * @return mixed
* @throws Exception
*/ */
public function getBody() public function getBody()
{ {
if ($this->get('body')) { if ($this->get('body')) {
return $this->get('body'); return $this->get('body');
} }
switch ($this->getEncoding()) { switch ($this->getEncoding()) {
case 0: // 7BIT
case 1: // 8BIT
case 2: // BINARY case 2: // BINARY
$this->attachment['body'] = $this->getPlainBody(); $this->attachment['body'] = $this->getPlainBody();
return $this->get('body'); return $this->get('body');
case 3: // BASE-64 case 3: // BASE-64
$this->attachment['body'] = base64_decode($this->getPlainBody()); $this->attachment['body'] = base64_decode($this->getPlainBody(), true);
return $this->get('body'); return $this->get('body');
case 4: // QUOTED-PRINTABLE case 4: // QUOTED-PRINTABLE
$this->attachment['body'] = imap_qprint($this->getPlainBody()); $this->attachment['body'] = imap_qprint($this->getPlainBody());
return $this->get('body'); return $this->get('body');
} }
@ -185,27 +188,29 @@ class Attachment
} }
/** /**
* Store File * Store File.
* *
* @param string $path * @param string $path
* @param boolean $file_name * @param bool $file_name
* @return boolean *
* @return bool
*/ */
public function store($path, $file_name = false) public function store($path, $file_name = false)
{ {
$file_name = ($file_name) ? $file_name : "{$this->getFilename()}.{$this->getExtension()}"; $file_name = ($file_name) ? $file_name : "{$this->getFilename()}.{$this->getExtension()}";
$path = rtrim($path, '/') . "/"; $path = rtrim($path, '/').'/';
return (boolean) file_put_contents($path . $file_name, $this->getBody());
return (bool) file_put_contents($path.$file_name, $this->getBody());
} }
/** /**
* Parse Parts * Parse Parts.
* *
* @return boolean * @return bool
*/ */
protected function parseParts() protected function parseParts()
{ {
if( (count($this->attachment) > 2) ){ if ((\count($this->attachment) > 2)) {
return true; return true;
} }
@ -223,19 +228,19 @@ class Attachment
$this->attachment['ifdparameters'] = (isset($this->part->ifdparameters)) ? $this->part->ifdparameters : false; $this->attachment['ifdparameters'] = (isset($this->part->ifdparameters)) ? $this->part->ifdparameters : false;
$this->attachment['ifparameters'] = (isset($this->part->ifparameters)) ? $this->part->ifparameters : false; $this->attachment['ifparameters'] = (isset($this->part->ifparameters)) ? $this->part->ifparameters : false;
if( is_array($this->part->dparameters) ){ if (\is_array($this->part->dparameters)) {
foreach ($this->part->dparameters as $obj) { foreach ($this->part->dparameters as $obj) {
if( in_array(strtolower($obj->attribute), ['filename', 'name']) ){ if (\in_array(mb_strtolower($obj->attribute), ['filename', 'name'], true)) {
$this->attachment[strtolower($obj->attribute)] = pathinfo($obj->value, PATHINFO_FILENAME); $this->attachment[mb_strtolower($obj->attribute)] = pathinfo($obj->value, PATHINFO_FILENAME);
$this->attachment['extension'] = pathinfo($obj->value, PATHINFO_EXTENSION); $this->attachment['extension'] = pathinfo($obj->value, PATHINFO_EXTENSION);
} }
} }
} }
if( is_array($this->part->parameters) ){ if (\is_array($this->part->parameters)) {
foreach ($this->part->parameters as $obj) { foreach ($this->part->parameters as $obj) {
if( in_array(strtolower($obj->attribute), ['filename', 'name']) ){ if (\in_array(mb_strtolower($obj->attribute), ['filename', 'name'], true)) {
$this->attachment[strtolower($obj->attribute)] = pathinfo($obj->value, PATHINFO_FILENAME); $this->attachment[mb_strtolower($obj->attribute)] = pathinfo($obj->value, PATHINFO_FILENAME);
$this->attachment['extension'] = pathinfo($obj->value, PATHINFO_EXTENSION); $this->attachment['extension'] = pathinfo($obj->value, PATHINFO_EXTENSION);
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Message; namespace Clivern\Imap\Core\Message;
@ -8,30 +10,27 @@ namespace Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Connection; use Clivern\Imap\Core\Connection;
/** /**
* Body Class * Body Class.
*
* @package Clivern\Imap\Core\Message
*/ */
class Body class Body
{ {
/** /**
* @var Connection * @var Connection
*/ */
protected $connection; protected $connection;
/** /**
* @var integer * @var int
*/ */
protected $message_number; protected $message_number;
/** /**
* @var integer * @var int
*/ */
protected $message_uid; protected $message_uid;
/** /**
* @var integer * @var int
*/ */
protected $encoding; protected $encoding;
@ -40,9 +39,8 @@ class Body
*/ */
protected $message = ''; protected $message = '';
/** /**
* Class Constructor * Class Constructor.
* *
* @param Connection $connection * @param Connection $connection
*/ */
@ -52,10 +50,11 @@ class Body
} }
/** /**
* Config Body * Config Body.
*
* @param int $message_number
* @param int $message_uid
* *
* @param integer $message_number
* @param integer $message_uid
* @return Body * @return Body
*/ */
public function config($message_number, $message_uid) public function config($message_number, $message_uid)
@ -67,9 +66,10 @@ class Body
} }
/** /**
* Get Message * Get Message.
*
* @param int $option
* *
* @param integer $option
* @return string * @return string
*/ */
public function getMessage($option = 2) public function getMessage($option = 2)
@ -80,16 +80,15 @@ class Body
$structure = imap_fetchstructure($this->connection->getStream(), $this->message_number); $structure = imap_fetchstructure($this->connection->getStream(), $this->message_number);
if (isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) { if (isset($structure->parts) && \is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1]; $part = $structure->parts[1];
$this->message = imap_fetchbody($this->connection->getStream(), $this->message_number, $option); $this->message = imap_fetchbody($this->connection->getStream(), $this->message_number, $option);
$this->encoding = $part->encoding; $this->encoding = $part->encoding;
if($part->encoding == 3) { if (3 === $part->encoding) {
$this->message = imap_base64($this->message); $this->message = imap_base64($this->message);
} elseif($part->encoding == 1) { } elseif (1 === $part->encoding) {
$this->message = imap_8bit($this->message); $this->message = imap_8bit($this->message);
} else { } else {
$this->message = imap_qprint($this->message); $this->message = imap_qprint($this->message);
@ -102,9 +101,9 @@ class Body
} }
/** /**
* Get Encoding * Get Encoding.
* *
* @return integer * @return int
*/ */
public function getEncoding() public function getEncoding()
{ {

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Message; namespace Clivern\Imap\Core\Message;
@ -8,25 +10,22 @@ namespace Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Connection; use Clivern\Imap\Core\Connection;
/** /**
* Header Class * Header Class.
*
* @package Clivern\Imap\Core\Message
*/ */
class Header class Header
{ {
/** /**
* @var Connection * @var Connection
*/ */
protected $connection; protected $connection;
/** /**
* @var integer * @var int
*/ */
protected $message_number; protected $message_number;
/** /**
* @var integer * @var int
*/ */
protected $message_uid; protected $message_uid;
@ -35,9 +34,8 @@ class Header
*/ */
protected $header = []; protected $header = [];
/** /**
* Class Constructor * Class Constructor.
* *
* @param Connection $connection * @param Connection $connection
*/ */
@ -47,10 +45,12 @@ class Header
} }
/** /**
* Config Message * Config Message.
*
* @param int $message_number
* @param int $message_uid
* @param mixed $options
* *
* @param integer $message_number
* @param integer $message_uid
* @return Header * @return Header
*/ */
public function config($message_number, $message_uid, $options = 0) public function config($message_number, $message_uid, $options = 0)
@ -67,35 +67,39 @@ class Header
} }
/** /**
* Get From Header * Get From Header.
* *
* @param string $key * @param string $key
* @param boolean $default * @param bool $default
*
* @return mixed * @return mixed
*/ */
public function get($key, $default = false) public function get($key, $default = false)
{ {
return (isset($this->header[strtolower($key)])) ? $this->header[strtolower($key)] : $default; return (isset($this->header[mb_strtolower($key)])) ? $this->header[mb_strtolower($key)] : $default;
} }
/** /**
* Check if header has key * Check if header has key.
* *
* @param string $key * @param string $key
* @return boolean *
* @return bool
*/ */
public function has($key) public function has($key)
{ {
return (isset($this->header[strtolower($key)])); return isset($this->header[mb_strtolower($key)]);
} }
/** /**
* Parse Address List * Parse Address List.
* *
* @param string $address_string * @param string $address_string
* @param mixed $default_host
*
* @return array * @return array
*/ */
public function parseAddressList($address_string, $default_host = "example.com") public function parseAddressList($address_string, $default_host = 'example.com')
{ {
$address_array = imap_rfc822_parse_adrlist($address_string, $default_host); $address_array = imap_rfc822_parse_adrlist($address_string, $default_host);
$address_list = []; $address_list = [];
@ -105,7 +109,7 @@ class Header
'mailbox' => $val->mailbox, 'mailbox' => $val->mailbox,
'host' => $val->host, 'host' => $val->host,
'personal' => $val->personal, 'personal' => $val->personal,
'adl' => $val->adl 'adl' => $val->adl,
]; ];
} }
@ -113,9 +117,10 @@ class Header
} }
/** /**
* Load Header Data * Load Header Data.
* *
* @param mixed $options * @param mixed $options
*
* @return Header * @return Header
*/ */
protected function load($options = 0) protected function load($options = 0)
@ -129,7 +134,8 @@ class Header
$this->header['date'] = (isset($item_overview->date)) ? $item_overview->date : false; $this->header['date'] = (isset($item_overview->date)) ? $item_overview->date : false;
$this->header['message_id'] = (isset($item_overview->message_id)) ? $item_overview->message_id : false; $this->header['message_id'] = (isset($item_overview->message_id)) ? $item_overview->message_id : false;
$this->header['in_reply_to'] = (isset($item_overview->in_reply_to)) ? $item_overview->in_reply_to : false; $this->header['in_reply_to'] = (isset($item_overview->in_reply_to)) ? $item_overview->in_reply_to : false;
$this->header['references'] = (isset($item_overview->references)) ? explode(" ", $item_overview->references) : false; $this->header['references'] = (isset($item_overview->references)) ?
explode(' ', $item_overview->references) : false;
$this->header['size'] = (isset($item_overview->size)) ? $item_overview->size : false; $this->header['size'] = (isset($item_overview->size)) ? $item_overview->size : false;
$this->header['uid'] = (isset($item_overview->uid)) ? $item_overview->uid : false; $this->header['uid'] = (isset($item_overview->uid)) ? $item_overview->uid : false;
$this->header['msgno'] = (isset($item_overview->msgno)) ? $item_overview->msgno : false; $this->header['msgno'] = (isset($item_overview->msgno)) ? $item_overview->msgno : false;

View file

@ -1,31 +1,28 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core; namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Connection;
use Clivern\Imap\Core\Message\Header;
use Clivern\Imap\Core\Message\Action; use Clivern\Imap\Core\Message\Action;
use Clivern\Imap\Core\Message\Body; use Clivern\Imap\Core\Message\Body;
use Clivern\Imap\Core\Message\Header;
/** /**
* Message Iterator Class * Message Iterator Class.
*
* @package Clivern\Imap\Core
*/ */
class MessageIterator extends \ArrayIterator class MessageIterator extends \ArrayIterator
{ {
/** /**
* @var Connection * @var Connection
*/ */
protected $connection; protected $connection;
/** /**
* Constructor * Constructor.
* *
* @param Connection $connection * @param Connection $connection
* @param array $message_numbers * @param array $message_numbers
@ -37,13 +34,19 @@ class MessageIterator extends \ArrayIterator
} }
/** /**
* Get current message * Get current message.
* *
* @return Message * @return Message
*/ */
public function current() public function current()
{ {
$message = new Message($this->connection, new Header($this->connection), new Action($this->connection), new Body($this->connection)); $message = new Message(
$this->connection,
new Header($this->connection),
new Action($this->connection),
new Body($this->connection)
);
return $message->setUid(parent::current())->config(); return $message->setUid(parent::current())->config();
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core; namespace Clivern\Imap\Core;
@ -8,22 +10,30 @@ namespace Clivern\Imap\Core;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Search Class * Search Class.
*
* @package Clivern\Imap\Core
*/ */
class Search class Search
{ {
/** /**
* @var array * @var array
*/ */
protected $conditions = []; protected $conditions = [];
/** /**
* Add Condition * Get Conditions Query.
*
* @return string
*/
public function __toString()
{
return (!empty($this->conditions)) ? implode(' ', $this->conditions) : '';
}
/**
* Add Condition.
* *
* @param Condition $condition * @param Condition $condition
*
* @return Search * @return Search
*/ */
public function addCondition(Condition $condition) public function addCondition(Condition $condition)
@ -34,7 +44,7 @@ class Search
} }
/** /**
* Get Conditions * Get Conditions.
* *
* @return array * @return array
*/ */
@ -42,14 +52,4 @@ class Search
{ {
return $this->conditions; return $this->conditions;
} }
/**
* Get Conditions Query
*
* @return string
*/
public function __toString()
{
return (!empty($this->conditions)) ? implode(" ", $this->conditions) : "";
}
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* All Class * All Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class All implements Condition class All implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "ALL"; return 'ALL';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Answered Class * Answered Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Answered implements Condition class Answered implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "ANSWERED"; return 'ANSWERED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* BCC Class * BCC Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class BCC implements Condition class BCC implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class BCC implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Before Class * Before Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Before implements Condition class Before implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Before implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Body Class * Body Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Body implements Condition class Body implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Body implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* CC Class * CC Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class CC implements Condition class CC implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class CC implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Deleted Class * Deleted Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Deleted implements Condition class Deleted implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "DELETED"; return 'DELETED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Flagged Class * Flagged Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Flagged implements Condition class Flagged implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "FLAGGED"; return 'FLAGGED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* From Class * From Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class From implements Condition class From implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class From implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Keyword Class * Keyword Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Keyword implements Condition class Keyword implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Keyword implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* New Flag Class * New Flag Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class NewFlag implements Condition class NewFlag implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "NEW"; return 'NEW';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Old Class * Old Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Old implements Condition class Old implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "OLD"; return 'OLD';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* On Class * On Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class On implements Condition class On implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class On implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* All Class * All Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Recent implements Condition class Recent implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "RECENT"; return 'RECENT';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Seen Class * Seen Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Seen implements Condition class Seen implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "SEEN"; return 'SEEN';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Since Class * Since Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Since implements Condition class Since implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Since implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Subject Class * Subject Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Subject implements Condition class Subject implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Subject implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* Text Class * Text Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class Text implements Condition class Text implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class Text implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* To Class * To Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class To implements Condition class To implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class To implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* UnAnswered Class * UnAnswered Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class UnAnswered implements Condition class UnAnswered implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "UNANSWERED"; return 'UNANSWERED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* UnDeleted Class * UnDeleted Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class UnDeleted implements Condition class UnDeleted implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "UNDELETED"; return 'UNDELETED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* UnFlagged Class * UnFlagged Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class UnFlagged implements Condition class UnFlagged implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "UNFLAGGED"; return 'UNFLAGGED';
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* UnKeyword Class * UnKeyword Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class UnKeyword implements Condition class UnKeyword implements Condition
{ {
/** /**
* @var string * @var string
*/ */
protected $data; protected $data;
/** /**
* Class Constructor * Class Constructor.
* *
* @param string $data * @param string $data
*/ */
@ -31,7 +30,7 @@ class UnKeyword implements Condition
} }
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Condition; namespace Clivern\Imap\Core\Search\Condition;
@ -8,20 +10,17 @@ namespace Clivern\Imap\Core\Search\Condition;
use Clivern\Imap\Core\Search\Contract\Condition; use Clivern\Imap\Core\Search\Contract\Condition;
/** /**
* UnSeen Class * UnSeen Class.
*
* @package Clivern\Imap\Core\Search\Condition
*/ */
class UnSeen implements Condition class UnSeen implements Condition
{ {
/** /**
* Query String * Query String.
* *
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return "UNSEEN"; return 'UNSEEN';
} }
} }

View file

@ -1,14 +1,14 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap\Core\Search\Contract; namespace Clivern\Imap\Core\Search\Contract;
/** /**
* Condition Interface * Condition Interface.
*
* @package Clivern\Imap\Core\Search\Contract
*/ */
interface Condition interface Condition
{ {

View file

@ -1,28 +1,27 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Clivern\Imap; namespace Clivern\Imap;
use Clivern\Imap\Core\Connection; use Clivern\Imap\Core\Connection;
use Clivern\Imap\Core\MessageIterator; use Clivern\Imap\Core\Exception\FolderNotExistException;
use Clivern\Imap\Core\Message; use Clivern\Imap\Core\Message;
use Clivern\Imap\Core\Search;
use Clivern\Imap\Core\Message\Header;
use Clivern\Imap\Core\Message\Action; use Clivern\Imap\Core\Message\Action;
use Clivern\Imap\Core\Message\Attachments; use Clivern\Imap\Core\Message\Attachments;
use Clivern\Imap\Core\Message\Body; use Clivern\Imap\Core\Message\Body;
use Clivern\Imap\Core\Exception\FolderNotExistException; use Clivern\Imap\Core\Message\Header;
use Clivern\Imap\Core\MessageIterator;
use Clivern\Imap\Core\Search;
/** /**
* MailBox Class * MailBox Class.
*
* @package Clivern\Imap
*/ */
class MailBox class MailBox
{ {
/** /**
* @var string * @var string
*/ */
@ -38,9 +37,8 @@ class MailBox
*/ */
protected $folders = []; protected $folders = [];
/** /**
* Constructor * Constructor.
* *
* @param Connection $connection IMAP connection * @param Connection $connection IMAP connection
*/ */
@ -50,14 +48,15 @@ class MailBox
} }
/** /**
* Set Folder Name * Set Folder Name.
* *
* @param string $folder * @param string $folder
*
* @return MailBox * @return MailBox
*/ */
public function setFolder($folder) public function setFolder($folder)
{ {
if( !in_array($folder, $this->getFolders()) ){ if (!\in_array($folder, $this->getFolders(), true)) {
throw new FolderNotExistException($folder); throw new FolderNotExistException($folder);
} }
@ -67,7 +66,7 @@ class MailBox
} }
/** /**
* Get Folder name * Get Folder name.
* *
* @return string * @return string
*/ */
@ -77,20 +76,22 @@ class MailBox
} }
/** /**
* Get number of messages in this mailbox * Get number of messages in this mailbox.
* *
* @return int * @return int
*/ */
public function count() public function count()
{ {
$this->connection->survive($this->folder); $this->connection->survive($this->folder);
return imap_num_msg($this->connection->getStream()); return imap_num_msg($this->connection->getStream());
} }
/** /**
* Get message ids * Get message ids.
* *
* @param Search $search * @param Search $search
*
* @return MessageIterator * @return MessageIterator
*/ */
public function getMessages(Search $search = null) public function getMessages(Search $search = null)
@ -99,7 +100,7 @@ class MailBox
$query = ($search) ? (string) $search : 'ALL'; $query = ($search) ? (string) $search : 'ALL';
$message_numbers = imap_search($this->connection->getStream(), $query, \SE_UID); $message_numbers = imap_search($this->connection->getStream(), $query, \SE_UID);
if (false == $message_numbers) { if (false === $message_numbers) {
// imap_search can also return false // imap_search can also return false
$message_numbers = []; $message_numbers = [];
} }
@ -108,38 +109,46 @@ class MailBox
} }
/** /**
* Get a message by message number or uid * Get a message by message number or uid.
*
* @param bool|int $message_number
* @param bool|int $message_uid
* *
* @param int|boolean $message_number
* @param int|boolean $message_uid
* @return Message * @return Message
*/ */
public function getMessage($message_number = false, $message_uid = false) public function getMessage($message_number = false, $message_uid = false)
{ {
$this->connection->survive($this->folder); $this->connection->survive($this->folder);
$message = new Message($this->connection, new Header($this->connection), new Action($this->connection), new Attachments($this->connection), new Body($this->connection)); $message = new Message(
$this->connection,
new Header($this->connection),
new Action($this->connection),
new Attachments($this->connection),
new Body($this->connection)
);
if( $message_number == false ){ if (false === $message_number) {
return $message->setUid($message_uid)->config(); return $message->setUid($message_uid)->config();
}else{
return $message->setMsgNo($message_number)->config();
} }
return $message->setMsgNo($message_number)->config();
} }
/** /**
* Delete all messages marked for deletion * Delete all messages marked for deletion.
* *
* @return boolean * @return bool
*/ */
public function expunge() public function expunge()
{ {
$this->connection->survive($this->folder); $this->connection->survive($this->folder);
return (boolean) imap_expunge($this->connection->getStream());
return (bool) imap_expunge($this->connection->getStream());
} }
/** /**
* Get Folders List * Get Folders List.
* *
* @return array * @return array
*/ */
@ -149,10 +158,10 @@ class MailBox
return $this->folders; return $this->folders;
} }
$this->folders = imap_getmailboxes($this->connection->getStream(), "{" . $this->connection->getServer() . "}", "*"); $this->folders = imap_getmailboxes($this->connection->getStream(), '{'.$this->connection->getServer().'}', '*');
foreach ($this->folders as $key => $folder) { foreach ($this->folders as $key => $folder) {
$this->folders[$key] = str_replace("{" . $this->connection->getServer() . "}", "", $folder->name); $this->folders[$key] = str_replace('{'.$this->connection->getServer().'}', '', $folder->name);
} }
return $this->folders; return $this->folders;

View file

@ -1,4 +1,10 @@
<?php <?php
/*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/
namespace Tests\Core; namespace Tests\Core;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -7,10 +13,10 @@ class ConnectionTest extends TestCase
{ {
public function testConnect() public function testConnect()
{ {
#$email = getenv("TEST_EMAIL"); //$email = getenv("TEST_EMAIL");
#$password = getenv("TEST_EMAIL_PASS"); //$password = getenv("TEST_EMAIL_PASS");
#$connection = new \Clivern\Imap\Core\Connection("imap.gmail.com", "993", $email, $password, "/ssl", "INBOX"); //$connection = new \Clivern\Imap\Core\Connection("imap.gmail.com", "993", $email, $password, "/ssl", "INBOX");
#$this->assertTrue($connection->connect()->checkConnection()); //$this->assertTrue($connection->connect()->checkConnection());
#$this->assertTrue($connection->connect()->disconnect()); //$this->assertTrue($connection->connect()->disconnect());
} }
} }

View file

@ -1,4 +1,10 @@
<?php <?php
/*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/
namespace Tests\Core; namespace Tests\Core;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -8,8 +14,32 @@ class SearchTest extends TestCase
public function testConditionBuilder() public function testConditionBuilder()
{ {
$search = new \Clivern\Imap\Core\Search(); $search = new \Clivern\Imap\Core\Search();
$search->addCondition(new \Clivern\Imap\Core\Search\Condition\All())->addCondition(new \Clivern\Imap\Core\Search\Condition\Answered())->addCondition(new \Clivern\Imap\Core\Search\Condition\BCC("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Before("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Body("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\CC("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Deleted())->addCondition(new \Clivern\Imap\Core\Search\Condition\Flagged())->addCondition(new \Clivern\Imap\Core\Search\Condition\From("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Keyword("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\NewFlag())->addCondition(new \Clivern\Imap\Core\Search\Condition\Old())->addCondition(new \Clivern\Imap\Core\Search\Condition\On("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Recent())->addCondition(new \Clivern\Imap\Core\Search\Condition\Seen())->addCondition(new \Clivern\Imap\Core\Search\Condition\Since("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Subject("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\Text("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\To("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\UnAnswered())->addCondition(new \Clivern\Imap\Core\Search\Condition\UnDeleted())->addCondition(new \Clivern\Imap\Core\Search\Condition\UnFlagged())->addCondition(new \Clivern\Imap\Core\Search\Condition\UnKeyword("val"))->addCondition(new \Clivern\Imap\Core\Search\Condition\UnSeen()); $search->addCondition(new \Clivern\Imap\Core\Search\Condition\All())
$this->assertEquals($search->getConditions(), [ ->addCondition(new \Clivern\Imap\Core\Search\Condition\Answered())
->addCondition(new \Clivern\Imap\Core\Search\Condition\BCC('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Before('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Body('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\CC('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Deleted())
->addCondition(new \Clivern\Imap\Core\Search\Condition\Flagged())
->addCondition(new \Clivern\Imap\Core\Search\Condition\From('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Keyword('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\NewFlag())
->addCondition(new \Clivern\Imap\Core\Search\Condition\Old())
->addCondition(new \Clivern\Imap\Core\Search\Condition\On('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Recent())
->addCondition(new \Clivern\Imap\Core\Search\Condition\Seen())
->addCondition(new \Clivern\Imap\Core\Search\Condition\Since('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Subject('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\Text('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\To('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\UnAnswered())
->addCondition(new \Clivern\Imap\Core\Search\Condition\UnDeleted())
->addCondition(new \Clivern\Imap\Core\Search\Condition\UnFlagged())
->addCondition(new \Clivern\Imap\Core\Search\Condition\UnKeyword('val'))
->addCondition(new \Clivern\Imap\Core\Search\Condition\UnSeen());
$this->assertSame($search->getConditions(), [
'ALL', 'ALL',
'ANSWERED', 'ANSWERED',
'BCC "val"', 'BCC "val"',
@ -33,8 +63,13 @@ class SearchTest extends TestCase
'UNDELETED', 'UNDELETED',
'UNFLAGGED', 'UNFLAGGED',
'UNKEYWORD "val"', 'UNKEYWORD "val"',
'UNSEEN' 'UNSEEN',
]); ]);
$this->assertEquals((string) $search, 'ALL ANSWERED BCC "val" BEFORE "val" BODY "val" CC "val" DELETED FLAGGED FROM "val" KEYWORD "val" NEW OLD ON "val" RECENT SEEN SINCE "val" SUBJECT "val" TEXT "val" TO "val" UNANSWERED UNDELETED UNFLAGGED UNKEYWORD "val" UNSEEN'); $this->assertSame(
(string) $search,
'ALL ANSWERED BCC "val" BEFORE "val" BODY "val" CC "val" DELETED FLAGGED FROM "val" KEYWORD "val" '.
'NEW OLD ON "val" RECENT SEEN SINCE "val" SUBJECT "val" TEXT "val" TO "val" UNANSWERED UNDELETED '.
'UNFLAGGED UNKEYWORD "val" UNSEEN'
);
} }
} }

View file

@ -1,6 +1,8 @@
<?php <?php
/**
* @author clivern <hello@clivern.com> /*
* This file is part of the Imap PHP package.
* (c) Clivern <hello@clivern.com>
*/ */
namespace Tests; namespace Tests;
@ -8,9 +10,7 @@ namespace Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/** /**
* MailBox Class Test * MailBox Class Test.
*
* @package Tests
*/ */
class MailBoxTest extends TestCase class MailBoxTest extends TestCase
{ {