Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Core/Lib/Email/NewMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@ public function cc(string $email, string $name = ''): NewMail
return $this;
}

/**
* Limpia el BCC del mail
*/
public function clearBCC(): NewMail
{
$this->mail->clearBCCs();

return $this;
}

/**
* Limpia el CC del mail
*/
public function clearCC(): NewMail
{
$this->mail->clearCCs();

return $this;
}

/**
* Limpia el To del mail
*/
public function clearTo(): NewMail
{
$this->mail->clearAddresses();

return $this;
}

public static function create(): NewMail
{
return new static();
Expand Down Expand Up @@ -335,6 +365,8 @@ public function replyTo(string $address, string $name = ''): NewMail

/**
* Envía el correo.
*
* Si se envía correctamente, borra los BCC, CC y To del email después de enviarlo.
*
* @throws Exception
* @throws LoaderError
Expand Down Expand Up @@ -410,6 +442,10 @@ public function send(): bool

if ($this->mail->send()) {
$this->saveMailSent();
// limpiar campos del email después de enviar
$this->clearTo();
$this->clearCC();
$this->clearBCC();
return true;
}

Expand Down
23 changes: 23 additions & 0 deletions Test/Core/Lib/Email/NewMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
namespace FacturaScripts\Test\Core\Lib\Email;

use FacturaScripts\Core\Lib\Email\NewMail;
use PHPMailer\PHPMailer\PHPMailer;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

final class NewMailTest extends TestCase
{
Expand Down Expand Up @@ -67,4 +69,25 @@ public function testBCC(): void
$this->assertEmpty($mailer->getCcAddresses());
$this->assertCount(1, $mailer->getBccAddresses());
}

// testear que las funciones de borrado borran correctamente las cosas
public function testClear(): void
{
$mailer = NewMail::create()
->to('to@facturascripts.com')
->cc('cc@facturascripts.com')
->bcc('bcc@facturascripts.com');

$this->assertNotEmpty($mailer->getToAddresses());
$mailer->clearTo();
$this->assertEmpty($mailer->getToAddresses());

$this->assertNotEmpty($mailer->getCcAddresses());
$mailer->clearCC();
$this->assertEmpty($mailer->getCcAddresses());

$this->assertNotEmpty($mailer->getBccAddresses());
$mailer->clearBCC();
$this->assertEmpty($mailer->getBccAddresses());
}
}
Loading