mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 05:58:42 +00:00
impl. mail functionality, some bug fixes and code style
This commit is contained in:
parent
bbab09b0ea
commit
6cd43859ec
|
|
@ -12,14 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all
|
||||||
|
|
||||||
### Issues
|
### Issues
|
||||||
|
|
||||||
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code and have the following structure:
|
Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file.
|
||||||
|
|
||||||
```php
|
|
||||||
/**
|
|
||||||
* @todo Orange-Management/phpOMS#ISSUE_NUMBER
|
|
||||||
* Description for the issue
|
|
||||||
*/
|
|
||||||
```
|
|
||||||
|
|
||||||
### Code Style
|
### Code Style
|
||||||
|
|
||||||
|
|
@ -29,6 +22,6 @@ Not always are the defined coding style standards upheld, if you notice that sim
|
||||||
|
|
||||||
While code coverage is just a metric it is still appreciated to cover as many files and code paths as possible. Just have a look at the code coverage and implement missing unit tests.
|
While code coverage is just a metric it is still appreciated to cover as many files and code paths as possible. Just have a look at the code coverage and implement missing unit tests.
|
||||||
|
|
||||||
### Freatures
|
### Features
|
||||||
|
|
||||||
You have a good idea for a feature and can implement it yourself, go ahead and create a new pull request.
|
You have a good idea for a feature and can implement it yourself, go ahead and create a new pull request.
|
||||||
|
|
@ -3163,7 +3163,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
}
|
}
|
||||||
} catch (\Throwable $t) {
|
} catch (\Throwable $t) {
|
||||||
$results = false;
|
$results = false;
|
||||||
\var_dump($query->toSql());
|
\var_dump($a = $query->toSql());
|
||||||
\var_dump($t->getMessage());
|
\var_dump($t->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,14 +109,13 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
|
||||||
public function render(...$data) : string
|
public function render(...$data) : string
|
||||||
{
|
{
|
||||||
$types = $this->header->get('Content-Type');
|
$types = $this->header->get('Content-Type');
|
||||||
|
|
||||||
foreach ($types as $type) {
|
foreach ($types as $type) {
|
||||||
if (\stripos($type, MimeType::M_JSON) !== false) {
|
if (\stripos($type, MimeType::M_JSON) !== false) {
|
||||||
return (string) \json_encode($this->jsonSerialize());
|
return (string) \json_encode($this->jsonSerialize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getRaw($data[0] ?? false);
|
return $this->getRaw(\stripos($type ?? '', MimeType::M_HTML) !== false ? ($data[0] ?? false) : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -133,8 +132,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface
|
||||||
private function getRaw(bool $optimize = false) : string
|
private function getRaw(bool $optimize = false) : string
|
||||||
{
|
{
|
||||||
$render = '';
|
$render = '';
|
||||||
|
foreach ($this->response as $response) {
|
||||||
foreach ($this->response as $key => $response) {
|
|
||||||
$render .= StringUtils::stringify($response);
|
$render .= StringUtils::stringify($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1107,24 +1107,28 @@ class Email implements MessageInterface
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = \tempnam(\sys_get_temp_dir(), 'srcsign');
|
$file = \tempnam($tmpDir = \sys_get_temp_dir(), 'srcsign');
|
||||||
$signed = \tempnam(\sys_get_temp_dir(), 'mailsign');
|
$signed = \tempnam($tmpDir, 'mailsign');
|
||||||
\file_put_contents($file, $body);
|
\file_put_contents($file, $body);
|
||||||
|
|
||||||
//Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
|
try {
|
||||||
$sign = empty($this->signExtracertFiles)
|
// Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
|
||||||
? \openssl_pkcs7_sign($file, $signed,
|
$sign = empty($this->signExtracertFiles)
|
||||||
'file://' . \realpath($this->signCertFile),
|
? \openssl_pkcs7_sign(\realpath($file), $signed,
|
||||||
['file://' . \realpath($this->signKeyFile), $this->signKeyPass],
|
'file://' . \realpath($this->signCertFile),
|
||||||
[]
|
['file://' . \realpath($this->signKeyFile), $this->signKeyPass],
|
||||||
)
|
[],
|
||||||
: \openssl_pkcs7_sign($file, $signed,
|
)
|
||||||
'file://' . \realpath($this->signCertFile),
|
: \openssl_pkcs7_sign(\realpath($file), $signed,
|
||||||
['file://' . \realpath($this->signKeyFile), $this->signKeyPass],
|
'file://' . \realpath($this->signCertFile),
|
||||||
[],
|
['file://' . \realpath($this->signKeyFile), $this->signKeyPass],
|
||||||
\PKCS7_DETACHED,
|
[],
|
||||||
$this->signExtracertFiles
|
\PKCS7_DETACHED,
|
||||||
);
|
$this->signExtracertFiles
|
||||||
|
);
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
$sign = false;
|
||||||
|
}
|
||||||
|
|
||||||
\unlink($file);
|
\unlink($file);
|
||||||
if ($sign === false) {
|
if ($sign === false) {
|
||||||
|
|
@ -1314,7 +1318,7 @@ class Email implements MessageInterface
|
||||||
|
|
||||||
$fileBuffer = \file_get_contents($path);
|
$fileBuffer = \file_get_contents($path);
|
||||||
if ($fileBuffer === false) {
|
if ($fileBuffer === false) {
|
||||||
return '';
|
return ''; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileBuffer = $this->encodeString($fileBuffer, $encoding);
|
$fileBuffer = $this->encodeString($fileBuffer, $encoding);
|
||||||
|
|
|
||||||
|
|
@ -22,141 +22,295 @@ namespace phpOMS\Message\Mail;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Imap extends MailHandler implements MailBoxInterface
|
class Imap implements MailBoxInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Connection flags
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $flags = '/imap';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current inbox
|
||||||
|
*
|
||||||
|
* Boxes can be in parent boxes. The path must be delimitted with . e.g. INBOX.Subdir1.Subdir2
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $box = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Host.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $host = 'localhost';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default port.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public int $port = 110;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encryption
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $encryption = EncryptionType::NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Username.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $username = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $password = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function __construct(string $user = '', string $pass = '', int $port = 143, string $encryption = EncryptionType::NONE)
|
||||||
|
{
|
||||||
|
$this->username = $user;
|
||||||
|
$this->password = $pass;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->encryption = $encryption;
|
||||||
|
$this->flags .= $this->encryption !== EncryptionType::NONE ? '/ssl' : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
$this->inboxClose();
|
$this->closeInbox();
|
||||||
parent::__destruct();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to server
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function connectInbox() : bool
|
public function connectInbox() : bool
|
||||||
{
|
{
|
||||||
$this->mailbox = ($tmp = \imap_open(
|
$this->mailbox = ($tmp = \imap_open(
|
||||||
'{'
|
'{' . $this->host . ':' . $this->port . $this->flags . '}',
|
||||||
. $this->host . ':' . $this->port . '/imap'
|
|
||||||
. ($this->encryption !== EncryptionType::NONE ? '/ssl' : '')
|
|
||||||
. '}',
|
|
||||||
$this->username, $this->password
|
$this->username, $this->password
|
||||||
) === false) ? null : $tmp;
|
)) === false ? null : $tmp;
|
||||||
|
|
||||||
|
return \is_resource($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mailboxes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getBoxes() : array
|
public function getBoxes() : array
|
||||||
{
|
{
|
||||||
$list = \imap_list($this->mailbox, '{' . $this->host . ':' . $this->port . '}');
|
$list = \imap_list($this->mailbox, $reference = '{' . $this->host . ':' . $this->port . '}', '*');
|
||||||
if (!\is_array($list)) {
|
if (!\is_array($list)) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
$list[$key] = \imap_utf7_decode($value);
|
$list[$key] = \str_replace($reference, '', \imap_utf7_decode($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename mailbox
|
||||||
|
*
|
||||||
|
* @param string $old Old name
|
||||||
|
* @param string $new New name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renameBox(string $old, string $new) : bool
|
public function renameBox(string $old, string $new) : bool
|
||||||
{
|
{
|
||||||
return \imap_renamemailbox($this->mailbox, $old, \imap_utf7_encode($new));
|
return \imap_renamemailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . '}' . $old),
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . '}' . $new)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to delete
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function deleteBox(string $box) : bool
|
public function deleteBox(string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_deletemailbox($this->mailbox, $box);
|
return \imap_deletemailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . '}' . $box)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to create
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function createBox(string $box) : bool
|
public function createBox(string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_createmailbox($this->mailbox, \imap_utf7_encode($box));
|
return \imap_createmailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . '}' . $box)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function countMail(string $box) : int
|
public function countMail(string $box) : int
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_num_msg($this->mailbox);
|
return \imap_num_msg($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getMailboxInfo(string $box) : object
|
public function getMailboxInfo(string $box) : object
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
return \imap_status($this->mailbox, '{' . $this->host . ':' . $this->port . '}' . $box, \SA_ALL);
|
||||||
\imap_reopen($this->box, $box);
|
|
||||||
$this->box = $box;
|
|
||||||
}
|
|
||||||
|
|
||||||
return \imap_status($this->mailbox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecentCount(string $box) : int
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function countRecent(string $box) : int
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_num_recent($this->mailbox);
|
return \imap_num_recent($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy message to another mailbox
|
||||||
|
*
|
||||||
|
* @param string|array $messages Messages to copy
|
||||||
|
* @param string $box Box to copy messages to
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function copyMail(string | array $messages, string $box) : bool
|
public function copyMail(string | array $messages, string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, $box);
|
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . '}' . $box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move message to another mailbox
|
||||||
|
*
|
||||||
|
* @param string|array $messages Messages to copy
|
||||||
|
* @param string $box Box to copy messages to
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function moveMail(string | array $messages, string $box) : bool
|
public function moveMail(string | array $messages, string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, $box);
|
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . '}' . $box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete message
|
||||||
|
*
|
||||||
|
* @param int $msg Message number (not uid)
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function deleteMail(int $msg) : bool
|
public function deleteMail(int $msg) : bool
|
||||||
{
|
{
|
||||||
return \imap_delete($this->mailbox, $msg);
|
return \imap_delete($this->mailbox, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getHeaders(string $box) : array
|
public function getHeaders(string $box) : array
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_headers($this->mailbox);
|
return \imap_headers($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get message header information
|
||||||
|
*
|
||||||
|
* @param int $msg Message number (not uid)
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getHeaderInfo(int $msg) : object
|
public function getHeaderInfo(int $msg) : object
|
||||||
{
|
{
|
||||||
return \imap_headerinfo($this->mailbox, $msg);
|
return \imap_headerinfo($this->mailbox, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getMail(int $msg) : Email
|
public function getMail(int $msg) : Email
|
||||||
{
|
{
|
||||||
return new Email();
|
return new Email();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close mailbox
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function inboxClose() : void
|
public function closeInbox() : void
|
||||||
{
|
{
|
||||||
if ($this->mailbox !== null) {
|
if (\is_resource($this->mailbox)) {
|
||||||
\imap_close($this->mailbox);
|
\imap_close($this->mailbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 8.0
|
* PHP Version 8.0
|
||||||
*
|
*
|
||||||
* @package phpOMS\Uri
|
* @package phpOMS\Message\Mail
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -17,13 +17,83 @@ namespace phpOMS\Message\Mail;
|
||||||
/**
|
/**
|
||||||
* Message interface.
|
* Message interface.
|
||||||
*
|
*
|
||||||
* @property string $subject Subject
|
* @package phpOMS\Message\Mail
|
||||||
*
|
|
||||||
* @package phpOMS\Uri
|
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
interface MailBoxInterface
|
interface MailBoxInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Connect to server
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function connectInbox() : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close mailbox
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function closeInbox() : void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count mail in mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to count the mail in
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function countMail(string $box) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count recent mail in mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to count the mail in
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function countRecent(string $box) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all message headers from a mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Mailbox
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getHeaders(string $box) : array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mailbox information summary
|
||||||
|
*
|
||||||
|
* @param string $box Box to check
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getMailboxInfo(string $box) : object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get message
|
||||||
|
*
|
||||||
|
* @param int $msg Message number (not uid)
|
||||||
|
*
|
||||||
|
* @return Email
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getMail(int $msg) : Email;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,14 +206,6 @@ class MailHandler
|
||||||
*/
|
*/
|
||||||
public ?Smtp $smtp = null;
|
public ?Smtp $smtp = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* An instance of the SMTP sender class.
|
|
||||||
*
|
|
||||||
* @var resource
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public mixed $mailbox = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMTP RFC standard line ending
|
* SMTP RFC standard line ending
|
||||||
*
|
*
|
||||||
|
|
@ -455,12 +447,14 @@ class MailHandler
|
||||||
$badRcpt = [];
|
$badRcpt = [];
|
||||||
foreach ([$mail->to, $mail->cc, $mail->bcc] as $togroup) {
|
foreach ([$mail->to, $mail->cc, $mail->bcc] as $togroup) {
|
||||||
foreach ($togroup as $to) {
|
foreach ($togroup as $to) {
|
||||||
$badRcpt = $this->smtp->recipient($to[0], $this->dsn) ? $badRcpt + 1 : $badRcpt;
|
if (!$this->smtp->recipient($to[0], $this->dsn)) {
|
||||||
|
$badRcpt[] = $to[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only send the DATA command if we have viable recipients
|
// Only send the DATA command if we have viable recipients
|
||||||
if ((\count($this->to) + \count($this->cc) + \count($this->bcc) > $badRcpt)
|
if ((\count($mail->to) + \count($mail->cc) + \count($mail->bcc) > \count($badRcpt))
|
||||||
&& !$this->smtp->data($header . $mail->body, self::MAX_LINE_LENGTH)
|
&& !$this->smtp->data($header . $mail->body, self::MAX_LINE_LENGTH)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -22,149 +22,295 @@ namespace phpOMS\Message\Mail;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Pop3 extends MailHandler implements MailBoxInterface
|
class Pop3 implements MailBoxInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Current mailbox
|
* Connection flags
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
* @sicne 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private string $box = '';
|
public string $flags = '/pop3';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current inbox
|
||||||
|
*
|
||||||
|
* Boxes can be in parent boxes. The path must be delimitted with . e.g. INBOX.Subdir1.Subdir2
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $box = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Host.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $host = 'localhost';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default port.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public int $port = 110;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encryption
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $encryption = EncryptionType::NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Username.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $username = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public string $password = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function __construct(string $user = '', string $pass = '', int $port = 110, string $encryption = EncryptionType::NONE)
|
||||||
|
{
|
||||||
|
$this->username = $user;
|
||||||
|
$this->password = $pass;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->encryption = $encryption;
|
||||||
|
$this->flags .= $this->encryption !== EncryptionType::NONE ? '/ssl' : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
$this->inboxClose();
|
$this->closeInbox();
|
||||||
parent::__destruct();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to server
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function connectInbox() : bool
|
public function connectInbox() : bool
|
||||||
{
|
{
|
||||||
$this->mailbox = ($tmp = \imap_open(
|
$this->mailbox = ($tmp = \imap_open(
|
||||||
'{'
|
'{' . $this->host . ':' . $this->port . $this->flags . '}',
|
||||||
. $this->host . ':' . $this->port . '/pop3'
|
|
||||||
. ($this->encryption !== EncryptionType::NONE ? '/ssl' : '')
|
|
||||||
. '}',
|
|
||||||
$this->username, $this->password
|
$this->username, $this->password
|
||||||
) === false) ? null : $tmp;
|
)) === false ? null : $tmp;
|
||||||
|
|
||||||
|
return \is_resource($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mailboxes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getBoxes() : array
|
public function getBoxes() : array
|
||||||
{
|
{
|
||||||
$list = \imap_list($this->mailbox, '{' . $this->host . ':' . $this->port . '}');
|
$list = \imap_list($this->mailbox, $reference = '{' . $this->host . ':' . $this->port . $this->flags . '}', '*');
|
||||||
if (!\is_array($list)) {
|
if (!\is_array($list)) {
|
||||||
return [];
|
return []; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($list as $key => $value) {
|
foreach ($list as $key => $value) {
|
||||||
$list[$key] = \imap_utf7_decode($value);
|
$list[$key] = \str_replace($reference, '', \imap_utf7_decode($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename mailbox
|
||||||
|
*
|
||||||
|
* @param string $old Old name
|
||||||
|
* @param string $new New name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renameBox(string $old, string $new) : bool
|
public function renameBox(string $old, string $new) : bool
|
||||||
{
|
{
|
||||||
return \imap_renamemailbox($this->mailbox, $old, \imap_utf7_encode($new));
|
return \imap_renamemailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . $this->flags . '}' . $old),
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . $this->flags . '}' . $new)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to delete
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function deleteBox(string $box) : bool
|
public function deleteBox(string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_deletemailbox($this->mailbox, $box);
|
return \imap_deletemailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . $this->flags . '}' . $box)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create mailbox
|
||||||
|
*
|
||||||
|
* @param string $box Box to create
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function createBox(string $box) : bool
|
public function createBox(string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_createmailbox($this->mailbox, \imap_utf7_encode($box));
|
return \imap_createmailbox(
|
||||||
|
$this->mailbox,
|
||||||
|
\imap_utf7_encode('{' . $this->host . ':' . $this->port . $this->flags . '}' . $box)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function countMail(string $box) : int
|
public function countMail(string $box) : int
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_num_msg($this->mailbox);
|
return \imap_num_msg($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getMailboxInfo(string $box) : object
|
public function getMailboxInfo(string $box) : object
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
return \imap_status($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box, \SA_ALL);
|
||||||
\imap_reopen($this->box, $box);
|
|
||||||
$this->box = $box;
|
|
||||||
}
|
|
||||||
|
|
||||||
return \imap_status($this->mailbox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRecentCount(string $box) : int
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function countRecent(string $box) : int
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_num_recent($this->mailbox);
|
return \imap_num_recent($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy message to another mailbox
|
||||||
|
*
|
||||||
|
* @param string|array $messages Messages to copy
|
||||||
|
* @param string $box Box to copy messages to
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function copyMail(string | array $messages, string $box) : bool
|
public function copyMail(string | array $messages, string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, $box);
|
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move message to another mailbox
|
||||||
|
*
|
||||||
|
* @param string|array $messages Messages to copy
|
||||||
|
* @param string $box Box to copy messages to
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function moveMail(string | array $messages, string $box) : bool
|
public function moveMail(string | array $messages, string $box) : bool
|
||||||
{
|
{
|
||||||
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, $box);
|
return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete message
|
||||||
|
*
|
||||||
|
* @param int $msg Message number (not uid)
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function deleteMail(int $msg) : bool
|
public function deleteMail(int $msg) : bool
|
||||||
{
|
{
|
||||||
return \imap_delete($this->mailbox, $msg);
|
return \imap_delete($this->mailbox, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getHeaders(string $box) : array
|
public function getHeaders(string $box) : array
|
||||||
{
|
{
|
||||||
if ($this->box !== $box) {
|
if ($this->box !== $box) {
|
||||||
\imap_reopen($this->box, $box);
|
\imap_reopen($this->mailbox, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box);
|
||||||
$this->box = $box;
|
$this->box = $box;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \imap_headers($this->mailbox);
|
return \imap_headers($this->mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get message header information
|
||||||
|
*
|
||||||
|
* @param int $msg Message number (not uid)
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function getHeaderInfo(int $msg) : object
|
public function getHeaderInfo(int $msg) : object
|
||||||
{
|
{
|
||||||
return \imap_headerinfo($this->mailbox, $msg);
|
return \imap_headerinfo($this->mailbox, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function getMail(int $msg) : Email
|
public function getMail(int $msg) : Email
|
||||||
{
|
{
|
||||||
return new Email();
|
return new Email();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close mailbox
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public function inboxClose() : void
|
public function closeInbox() : void
|
||||||
{
|
{
|
||||||
if ($this->mailbox !== null) {
|
if (\is_resource($this->mailbox)) {
|
||||||
\imap_close($this->mailbox);
|
\imap_close($this->mailbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class Smtp
|
||||||
* @var ?resource
|
* @var ?resource
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $con;
|
protected $con = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reply the server sent to us for HELO.
|
* The reply the server sent to us for HELO.
|
||||||
|
|
@ -215,6 +215,8 @@ class Smtp
|
||||||
$crypto_method |= \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
|
$crypto_method |= \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This may throw "Peer certificate CN=`...` did not match expected CN=`...`"
|
||||||
|
// The solution is to replace the invalid ssl certificate with a correct one
|
||||||
return (bool) \stream_socket_enable_crypto($this->con, true, $crypto_method);
|
return (bool) \stream_socket_enable_crypto($this->con, true, $crypto_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ require_once __DIR__ . '/../Autoloader.php';
|
||||||
use phpOMS\DataStorage\Database\DatabasePool;
|
use phpOMS\DataStorage\Database\DatabasePool;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
use phpOMS\DataStorage\Session\HttpSession;
|
use phpOMS\DataStorage\Session\HttpSession;
|
||||||
|
use phpOMS\Log\FileLogger;
|
||||||
|
|
||||||
|
// Initialize file logger with correct path
|
||||||
|
$tmp = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||||
|
|
||||||
$CONFIG = [
|
$CONFIG = [
|
||||||
'db' => [
|
'db' => [
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\tests\Message;
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../Autoloader.php';
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
|
|
||||||
116
tests/Message/Mail/ImapTest.php
Normal file
116
tests/Message/Mail/ImapTest.php
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Mail\Imap;
|
||||||
|
use phpOMS\Message\Mail\MailBoxInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class ImapTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected MailBoxInterface $handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->handler = new Imap('testuser', 'testuser', 143);
|
||||||
|
$this->handler->host = '127.0.0.1';
|
||||||
|
$this->handler->flags = '/imap/notls/norsh/novalidate-cert';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!$this->handler->connectInbox()) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function tearDown() : void
|
||||||
|
{
|
||||||
|
$this->handler->closeInbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnect() : void
|
||||||
|
{
|
||||||
|
$this->handler->closeInbox();
|
||||||
|
self::assertTrue($this->handler->connectInbox());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBoxes() : void
|
||||||
|
{
|
||||||
|
self::assertTrue(\in_array('INBOX', $this->handler->getBoxes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBoxesInputOutputDelte() : void
|
||||||
|
{
|
||||||
|
$startCount = \count($this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->createBox('TestBox'));
|
||||||
|
self::assertTrue(\in_array('TestBox', $this->handler->getBoxes()));
|
||||||
|
self::assertCount($startCount + 1, $this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->renameBox('TestBox', 'NewTestBox'));
|
||||||
|
self::assertTrue(\in_array('NewTestBox', $this->handler->getBoxes()));
|
||||||
|
self::assertCount($startCount + 1, $this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->deleteBox('NewTestBox'));
|
||||||
|
self::assertCount($startCount, $this->handler->getBoxes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMailboxInfo() : void
|
||||||
|
{
|
||||||
|
$this->handler->createBox('INBOX.TestBox');
|
||||||
|
$info = $this->handler->getMailboxInfo('INBOX.TestBox');
|
||||||
|
$this->handler->deleteBox('INBOX.TestBox');
|
||||||
|
|
||||||
|
self::assertEquals(0, $info->messages);
|
||||||
|
self::assertEquals(0, $info->recent);
|
||||||
|
self::assertEquals(0, $info->unseen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCountMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->createBox('INBOX.TestBox');
|
||||||
|
self::assertEquals(0, $this->handler->countMail('INBOX.TestBox'));
|
||||||
|
$this->handler->deleteBox('INBOX.TestBox');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCountRecent() : void
|
||||||
|
{
|
||||||
|
$this->handler->createBox('INBOX.TestBox');
|
||||||
|
self::assertEquals(0, $this->handler->countRecent('INBOX.TestBox'));
|
||||||
|
$this->handler->deleteBox('INBOX.TestBox');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testWithActualMail() : void
|
||||||
|
{
|
||||||
|
\mail('testuser@localhost', 'Test Subject', 'This is my test message!');
|
||||||
|
self::assertGreaterThan(0, $mailCount = $this->handler->countMail('INBOX'));
|
||||||
|
//self::assertGreaterThan(0, $recentCount = $this->handler->countRecent('INBOX'));
|
||||||
|
self::assertGreaterThan(0, \count($this->handler->getHeaders('INBOX')));
|
||||||
|
}
|
||||||
|
}
|
||||||
427
tests/Message/Mail/MailHandlerMailTrait.php
Normal file
427
tests/Message/Mail/MailHandlerMailTrait.php
Normal file
|
|
@ -0,0 +1,427 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Mail\Email;
|
||||||
|
use phpOMS\Message\Mail\SubmitType;
|
||||||
|
use phpOMS\System\CharsetType;
|
||||||
|
use phpOMS\System\OperatingSystem;
|
||||||
|
use phpOMS\System\SystemType;
|
||||||
|
|
||||||
|
trait MailHandlerMailTrait
|
||||||
|
{
|
||||||
|
public function testSendTextWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendTextWithMail';
|
||||||
|
$mail->body = "This is some content\n\Image: <img alt=\"image\" src=\"cid:cid1\">";
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendHtmlWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendHtmlWithMail';
|
||||||
|
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
|
||||||
|
$mail->charset = CharsetType::UTF_8;
|
||||||
|
$mail->body = '';
|
||||||
|
$mail->bodyAlt = '';
|
||||||
|
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML($message, __DIR__ . '/files');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendInlineWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendInlineWithMail';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAttachmentWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAttachmentWithMail';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltWithMail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltInlineWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltInlineWithMail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltAttachmentWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltAttachmentWithMail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainWithMail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMWithMail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMSignWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMSignWithMail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->dkimDomain = 'orange-management.email';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
$mail->dkimSelector = 'phpOMS';
|
||||||
|
$mail->dkimPass = '';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainSignWithMail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainSignWithMail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->sign(__DIR__ . '/cert.pem', __DIR__ . '/key.pem', 'password');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodMail
|
||||||
|
*/
|
||||||
|
public function testSendICalAltWithMail(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendICalAltWithMail';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodMail
|
||||||
|
*/
|
||||||
|
public function testSendICalAltAttachmentWithMail(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::MAIL);
|
||||||
|
|
||||||
|
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
||||||
|
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
||||||
|
) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->subject = 'testSendICalAltAttachmentWithMail';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataICalMethodMail()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Valid method: request (default)' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:REQUEST",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal invalid method to use default (REQUEST).
|
||||||
|
'Invalid method' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:INVALID",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal missing method to use default (REQUEST).
|
||||||
|
'Missing method' => [
|
||||||
|
'methodLine' => '',
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
399
tests/Message/Mail/MailHandlerSendmailTrait.php
Normal file
399
tests/Message/Mail/MailHandlerSendmailTrait.php
Normal file
|
|
@ -0,0 +1,399 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Mail\Email;
|
||||||
|
use phpOMS\Message\Mail\SubmitType;
|
||||||
|
use phpOMS\System\CharsetType;
|
||||||
|
|
||||||
|
trait MailHandlerSendmailTrait
|
||||||
|
{
|
||||||
|
public function testSendTextWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendTextWithSendmail';
|
||||||
|
$mail->body = "This is some content\n\Image: <img alt=\"image\" src=\"cid:cid1\">";
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendHtmlWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendHtmlWithSendmail';
|
||||||
|
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
|
||||||
|
$mail->charset = CharsetType::UTF_8;
|
||||||
|
$mail->body = '';
|
||||||
|
$mail->bodyAlt = '';
|
||||||
|
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML($message, __DIR__ . '/files');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendInlineWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendInlineWithSendmail';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAttachmentWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAttachmentWithSendmail';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltWithSendmail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltInlineWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltInlineWithSendmail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltAttachmentWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltAttachmentWithSendmail';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainWithSendmail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMWithSendmail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMSignWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMSignWithSendmail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->dkimDomain = 'orange-management.email';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
$mail->dkimSelector = 'phpOMS';
|
||||||
|
$mail->dkimPass = '';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainSignWithSendmail() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainSignWithSendmail';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->sign(__DIR__ . '/cert.pem', __DIR__ . '/key.pem', 'password');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodSendmail
|
||||||
|
*/
|
||||||
|
public function testSendICalAltWithSendmail(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendICalAltWithSendmail';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodSendmail
|
||||||
|
*/
|
||||||
|
public function testSendICalAltAttachmentWithSendmail(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SENDMAIL);
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->subject = 'testSendICalAltAttachmentWithSendmail';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataICalMethodSendmail()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Valid method: request (default)' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:REQUEST",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal invalid method to use default (REQUEST).
|
||||||
|
'Invalid method' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:INVALID",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal missing method to use default (REQUEST).
|
||||||
|
'Missing method' => [
|
||||||
|
'methodLine' => '',
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
478
tests/Message/Mail/MailHandlerSmtpTrait.php
Normal file
478
tests/Message/Mail/MailHandlerSmtpTrait.php
Normal file
|
|
@ -0,0 +1,478 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Mail\Email;
|
||||||
|
use phpOMS\Message\Mail\Smtp;
|
||||||
|
use phpOMS\Message\Mail\SubmitType;
|
||||||
|
use phpOMS\System\CharsetType;
|
||||||
|
|
||||||
|
trait MailHandlerSmtpTrait
|
||||||
|
{
|
||||||
|
public function testSendTextWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendTextWithSmtp';
|
||||||
|
$mail->body = "This is some content\n\Image: <img alt=\"image\" src=\"cid:cid1\">";
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendHtmlWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendHtmlWithSmtp';
|
||||||
|
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
|
||||||
|
$mail->charset = CharsetType::UTF_8;
|
||||||
|
$mail->body = '';
|
||||||
|
$mail->bodyAlt = '';
|
||||||
|
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML($message, __DIR__ . '/files');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
||||||
|
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendInlineWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendInlineWithSmtp';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAttachmentWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAttachmentWithSmtp';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltWithSmtp';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltInlineWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltInlineWithSmtp';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->setHtml(true);
|
||||||
|
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
||||||
|
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendAltAttachmentWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendAltAttachmentWithSmtp';
|
||||||
|
$mail->altBody = 'Alt body';
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainWithSmtp';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMWithSmtp';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainDKIMSignWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainDKIMSignWithSmtp';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->dkimDomain = 'orange-management.email';
|
||||||
|
$mail->dkimPrivatePath = __DIR__ . '/dkim.pem';
|
||||||
|
$mail->dkimSelector = 'phpOMS';
|
||||||
|
$mail->dkimPass = '';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendPlainSignWithSmtp() : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendPlainSignWithSmtp';
|
||||||
|
$mail->body = 'Body';
|
||||||
|
|
||||||
|
$mail->sign(__DIR__ . '/cert.pem', __DIR__ . '/key.pem', 'password');
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodSmtp
|
||||||
|
*/
|
||||||
|
public function testSendICalAltWithSmtp(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->subject = 'testSendICalAltWithSmtp';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataICalMethodSmtp
|
||||||
|
*/
|
||||||
|
public function testSendICalAltAttachmentWithSmtp(string $methodLine, string $expected) : void
|
||||||
|
{
|
||||||
|
$this->handler->setMailer(SubmitType::SMTP);
|
||||||
|
$this->handler->useAutoTLS = false;
|
||||||
|
$this->handler->username = 'testuser';
|
||||||
|
$this->handler->password = 'testuser';
|
||||||
|
|
||||||
|
$smtp = new Smtp();
|
||||||
|
$this->handler->smtp = $smtp;
|
||||||
|
|
||||||
|
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new Email();
|
||||||
|
$mail->priority = 1;
|
||||||
|
$mail->confirmationAddress = 'test1@orange-management.email';
|
||||||
|
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
||||||
|
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
||||||
|
$mail->subject = 'testSendICalAltAttachmentWithSmtp';
|
||||||
|
$mail->body = 'Ical test';
|
||||||
|
$mail->altBody = 'Ical test';
|
||||||
|
$mail->ical = 'BEGIN:VCALENDAR'
|
||||||
|
. "\r\nVERSION:2.0"
|
||||||
|
. "\r\nPRODID:-//phpOMS//Orange Management Calendar//EN"
|
||||||
|
. $methodLine
|
||||||
|
. "\r\nCALSCALE:GREGORIAN"
|
||||||
|
. "\r\nX-MICROSOFT-CALSCALE:GREGORIAN"
|
||||||
|
. "\r\nBEGIN:VEVENT"
|
||||||
|
. "\r\nUID:201909250755-42825@test"
|
||||||
|
. "\r\nDTSTART;20190930T080000Z"
|
||||||
|
. "\r\nSEQUENCE:2"
|
||||||
|
. "\r\nTRANSP:OPAQUE"
|
||||||
|
. "\r\nSTATUS:CONFIRMED"
|
||||||
|
. "\r\nDTEND:20190930T084500Z"
|
||||||
|
. "\r\nLOCATION:[London] London Eye"
|
||||||
|
. "\r\nSUMMARY:Test ICal method"
|
||||||
|
. "\r\nATTENDEE;CN=Attendee, Test;ROLE=OPT-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP="
|
||||||
|
. "\r\n TRUE:MAILTO:attendee-test@example.com"
|
||||||
|
. "\r\nCLASS:PUBLIC"
|
||||||
|
. "\r\nDESCRIPTION:Some plain text"
|
||||||
|
. "\r\nORGANIZER;CN=\"Example, Test\":MAILTO:test@example.com"
|
||||||
|
. "\r\nDTSTAMP:20190925T075546Z"
|
||||||
|
. "\r\nCREATED:20190925T075709Z"
|
||||||
|
. "\r\nLAST-MODIFIED:20190925T075546Z"
|
||||||
|
. "\r\nEND:VEVENT"
|
||||||
|
. "\r\nEND:VCALENDAR";
|
||||||
|
|
||||||
|
$expected = 'Content-Type: text/calendar; method=' . $expected . ';';
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->send($mail));
|
||||||
|
self::assertStringContainsString(
|
||||||
|
$expected,
|
||||||
|
$mail->bodyMime,
|
||||||
|
'Wrong ICal method in Content-Type header'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataICalMethodSmtp()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Valid method: request (default)' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:REQUEST",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal invalid method to use default (REQUEST).
|
||||||
|
'Invalid method' => [
|
||||||
|
'methodLine' => "\r\nMETHOD:INVALID",
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
// Test ICal missing method to use default (REQUEST).
|
||||||
|
'Missing method' => [
|
||||||
|
'methodLine' => '',
|
||||||
|
'expected' => 'REQUEST',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,17 +12,11 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\tests\Message;
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../Autoloader.php';
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\Message\Mail\Email;
|
|
||||||
use phpOMS\Message\Mail\Imap;
|
|
||||||
use phpOMS\Message\Mail\MailHandler;
|
use phpOMS\Message\Mail\MailHandler;
|
||||||
use phpOMS\Message\Mail\SubmitType;
|
|
||||||
use phpOMS\System\CharsetType;
|
|
||||||
use phpOMS\System\OperatingSystem;
|
|
||||||
use phpOMS\System\SystemType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
|
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
|
||||||
|
|
@ -33,6 +27,56 @@ final class MailHandlerTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
protected MailHandler $handler;
|
protected MailHandler $handler;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass() : void
|
||||||
|
{
|
||||||
|
$pk = \openssl_pkey_new(
|
||||||
|
[
|
||||||
|
'private_key_bits' => 2048,
|
||||||
|
'private_key_type' => \OPENSSL_KEYTYPE_RSA,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
\openssl_pkey_export_to_file($pk, __DIR__ . '/dkim.pem');
|
||||||
|
|
||||||
|
$password = 'password';
|
||||||
|
$dn = [
|
||||||
|
'countryName' => 'DE',
|
||||||
|
'stateOrProvinceName' => 'Hesse',
|
||||||
|
'localityName' => 'Frankfurt',
|
||||||
|
'organizationName' => 'Orange Management',
|
||||||
|
'organizationalUnitName' => 'Framework',
|
||||||
|
'commonName' => 'Orange Management Test',
|
||||||
|
'emailAddress' => 'test@orange-management.email',
|
||||||
|
];
|
||||||
|
$keyconfig = [
|
||||||
|
'digest_alg' => 'sha256',
|
||||||
|
'private_key_bits' => 2048,
|
||||||
|
'private_key_type' => \OPENSSL_KEYTYPE_RSA,
|
||||||
|
];
|
||||||
|
|
||||||
|
$pk = \openssl_pkey_new($keyconfig);
|
||||||
|
$csr = \openssl_csr_new($dn, $pk);
|
||||||
|
$cert = \openssl_csr_sign($csr, null, $pk, 1);
|
||||||
|
\openssl_x509_export($cert, $certout);
|
||||||
|
\file_put_contents(__DIR__ . '/cert.pem', $certout);
|
||||||
|
\openssl_pkey_export($pk, $pkeyout, $password);
|
||||||
|
\file_put_contents(__DIR__ . '/key.pem', $pkeyout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfterClass() : void
|
||||||
|
{
|
||||||
|
if (\is_file(__DIR__ . '/dkim.pem')) {
|
||||||
|
\unlink(__DIR__ . '/dkim.pem');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\is_file(__DIR__ . '/cert.pem')) {
|
||||||
|
\unlink(__DIR__ . '/cert.pem');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\is_file(__DIR__ . '/key.pem')) {
|
||||||
|
\unlink(__DIR__ . '/key.pem');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -41,355 +85,7 @@ final class MailHandlerTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->handler = new MailHandler();
|
$this->handler = new MailHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendTextWithMail() : void
|
use MailHandlerMailTrait;
|
||||||
{
|
use MailHandlerSendmailTrait;
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
use MailHandlerSmtpTrait;
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendTextWithMail';
|
|
||||||
$mail->body = "This is some content\n\Image: <img alt=\"image\" src=\"cid:cid1\">";
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
|
||||||
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendTextWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendTextWithSendmail';
|
|
||||||
$mail->body = "This is some content\n\Image: <img alt=\"image\" src=\"cid:cid1\">";
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
|
||||||
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendHtmlWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendHtmlWithMail';
|
|
||||||
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
|
|
||||||
$mail->charset = CharsetType::UTF_8;
|
|
||||||
$mail->body = '';
|
|
||||||
$mail->bodyAlt = '';
|
|
||||||
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML($message, __DIR__ . '/files');
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
|
||||||
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendHtmlWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addCC('test2@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addBCC('test3@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addReplyTo('test4@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendHtmlWithSendmail';
|
|
||||||
$message = \file_get_contents(__DIR__ . '/files/utf8.html');
|
|
||||||
$mail->charset = CharsetType::UTF_8;
|
|
||||||
$mail->body = '';
|
|
||||||
$mail->bodyAlt = '';
|
|
||||||
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML($message, __DIR__ . '/files');
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
$mail->addStringAttachment('String content', 'string_content_file.txt');
|
|
||||||
$mail->addStringEmbeddedImage(\file_get_contents(__DIR__ . '/files/logo.png'), 'cid2');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendInlineWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendInlineWithMail';
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendInlineWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendInlineWithSendmail';
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAttachmentWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAttachmentWithMail';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAttachmentWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAttachmentWithSendmail';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltWithMail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltWithSendmail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltInlineWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltInlineWithMail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltInlineWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltInlineWithSendmail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->setHtml(true);
|
|
||||||
$mail->msgHTML("<img alt=\"image\" src=\"cid:cid1\">");
|
|
||||||
$mail->addEmbeddedImage(__DIR__ . '/files/logo.png', 'cid1');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltAttachmentWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltAttachmentWithMail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendAltAttachmentWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendAltAttachmentWithSendmail';
|
|
||||||
$mail->altBody = 'Alt body';
|
|
||||||
$mail->addAttachment(__DIR__ . '/files/logo.png', 'logo');
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendPlainWithMail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::MAIL);
|
|
||||||
|
|
||||||
if (($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0]))
|
|
||||||
|| ($this->handler->mailerTool === '' && OperatingSystem::getSystem() !== SystemType::WIN && (\stripos($sendmailPath = \ini_get('sendmail_path'), 'sendmail') === false) || !\file_exists(\explode(' ', $sendmailPath)[0]))
|
|
||||||
) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendPlainWithMail';
|
|
||||||
$mail->body = 'Body';
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSendPlainWithSendmail() : void
|
|
||||||
{
|
|
||||||
$this->handler->setMailer(SubmitType::SENDMAIL);
|
|
||||||
|
|
||||||
if ($this->handler->mailerTool !== '' && !\file_exists(\explode(' ', $this->handler->mailerTool)[0])) {
|
|
||||||
self::markTestSkipped();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new Email();
|
|
||||||
$mail->setFrom('test1@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->addTo('test@orange-management.email', 'Dennis Eichhorn');
|
|
||||||
$mail->subject = 'testSendPlainWithSendmail';
|
|
||||||
$mail->body = 'Body';
|
|
||||||
|
|
||||||
self::assertTrue($this->handler->send($mail));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public function testReceiveMailWithImap() : void
|
|
||||||
{
|
|
||||||
$this->handler = new Imap();
|
|
||||||
$this->handler->connectInbox();
|
|
||||||
|
|
||||||
var_dump($this->handler->getBoxes());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
114
tests/Message/Mail/Pop3Test.php
Normal file
114
tests/Message/Mail/Pop3Test.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 8.0
|
||||||
|
*
|
||||||
|
* @package tests
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://orange-management.org
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace phpOMS\tests\Message\Mail;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../Autoloader.php';
|
||||||
|
|
||||||
|
use phpOMS\Message\Mail\MailBoxInterface;
|
||||||
|
use phpOMS\Message\Mail\Pop3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox phpOMS\tests\Message\MailHandlerTest: Abstract mail handler
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Pop3Test extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
protected MailBoxInterface $handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function setUp() : void
|
||||||
|
{
|
||||||
|
$this->handler = new Pop3('testuser', 'testuser', 110);
|
||||||
|
$this->handler->host = '127.0.0.1';
|
||||||
|
$this->handler->flags = '/pop3/notls';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!$this->handler->connectInbox()) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
self::markTestSkipped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function tearDown() : void
|
||||||
|
{
|
||||||
|
$this->handler->closeInbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnect() : void
|
||||||
|
{
|
||||||
|
$this->handler->closeInbox();
|
||||||
|
self::assertTrue($this->handler->connectInbox());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBoxes() : void
|
||||||
|
{
|
||||||
|
self::assertTrue(\in_array('INBOX', $this->handler->getBoxes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not working with pop3
|
||||||
|
public function testBoxesInputOutputDelte() : void
|
||||||
|
{
|
||||||
|
$startCount = \count($this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->createBox('TestBox'));
|
||||||
|
self::assertTrue(\in_array('TestBox', $this->handler->getBoxes()));
|
||||||
|
self::assertCount($startCount + 1, $this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->renameBox('TestBox', 'NewTestBox'));
|
||||||
|
self::assertTrue(\in_array('NewTestBox', $this->handler->getBoxes()));
|
||||||
|
self::assertCount($startCount + 1, $this->handler->getBoxes());
|
||||||
|
|
||||||
|
self::assertTrue($this->handler->deleteBox('NewTestBox'));
|
||||||
|
self::assertCount($startCount, $this->handler->getBoxes());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function testWithActualMail() : void
|
||||||
|
{
|
||||||
|
\mail('testuser@localhost', 'Test Subject', 'This is my test message!');
|
||||||
|
self::assertGreaterThan(0, $mailCount = $this->handler->countMail('INBOX'));
|
||||||
|
//self::assertGreaterThan(0, $recentCount = $this->handler->countRecent('INBOX'));
|
||||||
|
self::assertGreaterThan(0, \count($this->handler->getHeaders('INBOX')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMailboxInfo() : void
|
||||||
|
{
|
||||||
|
$info = $this->handler->getMailboxInfo('INBOX');
|
||||||
|
|
||||||
|
self::assertGreaterThan(0, $info->messages);
|
||||||
|
self::assertGreaterThan(0, $info->recent);
|
||||||
|
self::assertGreaterThan(0, $info->unseen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCountMail() : void
|
||||||
|
{
|
||||||
|
self::assertGreaterThan(0, $this->handler->countMail('INBOX'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCountRecent() : void
|
||||||
|
{
|
||||||
|
$this->handler->createBox('INBOX');
|
||||||
|
self::assertGreaterThan(0, $this->handler->countRecent('INBOX'));
|
||||||
|
$this->handler->deleteBox('INBOX');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user