2020-01-26 19:23:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Object;
|
|
|
|
|
|
|
|
use Friendica\Object\EMail\IEmail;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default implementation of the IEmail interface
|
|
|
|
*
|
2020-01-26 22:47:16 +00:00
|
|
|
* Provides the possibility to reuse the email instance with new recipients (@see Email::withRecipient())
|
2020-01-26 19:23:58 +00:00
|
|
|
*/
|
2020-01-26 22:47:16 +00:00
|
|
|
class Email implements IEmail
|
2020-01-26 19:23:58 +00:00
|
|
|
{
|
|
|
|
/** @var string */
|
|
|
|
private $fromName;
|
|
|
|
/** @var string */
|
2020-01-26 22:47:16 +00:00
|
|
|
private $fromAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
/** @var string */
|
|
|
|
private $replyTo;
|
|
|
|
|
|
|
|
/** @var string */
|
2020-01-26 22:47:16 +00:00
|
|
|
private $toAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $subject;
|
|
|
|
/** @var string */
|
|
|
|
private $msgHtml;
|
|
|
|
/** @var string */
|
|
|
|
private $msgText;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $additionalMailHeader = '';
|
|
|
|
/** @var int|null */
|
|
|
|
private $toUid = null;
|
|
|
|
|
2020-01-26 23:01:17 +00:00
|
|
|
public function __construct(string $fromName, string $fromAddress, string $replyTo, string $toAddress,
|
2020-01-26 19:23:58 +00:00
|
|
|
string $subject, string $msgHtml, string $msgText,
|
|
|
|
string $additionalMailHeader = '', int $toUid = null)
|
|
|
|
{
|
|
|
|
$this->fromName = $fromName;
|
2020-01-26 23:01:17 +00:00
|
|
|
$this->fromAddress = $fromAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
$this->replyTo = $replyTo;
|
2020-01-26 23:01:17 +00:00
|
|
|
$this->toAddress = $toAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
$this->subject = $subject;
|
|
|
|
$this->msgHtml = $msgHtml;
|
|
|
|
$this->msgText = $msgText;
|
|
|
|
$this->additionalMailHeader = $additionalMailHeader;
|
|
|
|
$this->toUid = $toUid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getFromName()
|
|
|
|
{
|
|
|
|
return $this->fromName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-26 22:47:16 +00:00
|
|
|
public function getFromAddress()
|
2020-01-26 19:23:58 +00:00
|
|
|
{
|
2020-01-26 22:47:16 +00:00
|
|
|
return $this->fromAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getReplyTo()
|
|
|
|
{
|
|
|
|
return $this->replyTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-26 22:47:16 +00:00
|
|
|
public function getToAddress()
|
2020-01-26 19:23:58 +00:00
|
|
|
{
|
2020-01-26 22:47:16 +00:00
|
|
|
return $this->toAddress;
|
2020-01-26 19:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getSubject()
|
|
|
|
{
|
|
|
|
return $this->subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-26 19:41:53 +00:00
|
|
|
public function getMessage(bool $plain = false)
|
2020-01-26 19:23:58 +00:00
|
|
|
{
|
2020-01-26 19:41:53 +00:00
|
|
|
if ($plain) {
|
2020-01-26 19:23:58 +00:00
|
|
|
return $this->msgText;
|
|
|
|
} else {
|
|
|
|
return $this->msgHtml;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getAdditionalMailHeader()
|
|
|
|
{
|
|
|
|
return $this->additionalMailHeader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getRecipientUid()
|
|
|
|
{
|
|
|
|
return $this->toUid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current email with a new recipient
|
|
|
|
*
|
|
|
|
* @param string $email The email of the recipient
|
|
|
|
* @param int $uid The (optional) UID of the recipient for further infos
|
|
|
|
*
|
2020-01-26 19:44:41 +00:00
|
|
|
* @return static
|
2020-01-26 19:23:58 +00:00
|
|
|
*/
|
|
|
|
public function withRecipient(string $email, int $uid = null)
|
|
|
|
{
|
2020-01-26 22:47:16 +00:00
|
|
|
$newEmail = clone $this;
|
|
|
|
$newEmail->toAddress = $email;
|
|
|
|
$newEmail->toUid = $uid;
|
2020-01-26 19:23:58 +00:00
|
|
|
|
|
|
|
return $newEmail;
|
|
|
|
}
|
2020-01-29 19:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Email instance based on a given prototype
|
|
|
|
*
|
|
|
|
* @param static $prototype The base prototype
|
|
|
|
* @param array $data The delta-data (key must be an existing property)
|
|
|
|
*
|
|
|
|
* @return static The new email instance
|
|
|
|
*/
|
|
|
|
public static function createFromPrototype(Email $prototype, array $data = [])
|
|
|
|
{
|
|
|
|
$newMail = clone $prototype;
|
|
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
if (property_exists($newMail, $key)) {
|
|
|
|
$newMail->{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $newMail;
|
|
|
|
}
|
2020-01-26 19:23:58 +00:00
|
|
|
}
|