Skip to content

Commit

Permalink
fix: mail
Browse files Browse the repository at this point in the history
  • Loading branch information
papac committed Jan 27, 2025
1 parent 84dae97 commit e8ef6d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Mail/Adapters/SmtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function send(Envelop $envelop): bool
// Validate SPF if enabled
if ($this->spfChecker !== null) {
$senderIp = $_SERVER['REMOTE_ADDR'] ?? '';
$senderEmail = $envelop->getFrom()[0][1] ?? '';
$senderEmail = $envelop->getFrom();
$senderHelo = gethostname();

$spfResult = $this->spfChecker->verify($senderIp, $senderEmail, $senderHelo);
Expand Down Expand Up @@ -158,7 +158,7 @@ public function send(Envelop $envelop): bool

foreach ($envelop->getTo() as $value) {
if ($value[0] !== null) {
$to = $value[0] . '<' . $value[1] . '>';
$to = $value[0] . ' <' . $value[1] . '>';
} else {
$to = '<' . $value[1] . '>';
}
Expand Down
16 changes: 15 additions & 1 deletion src/Mail/Envelop.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private function formatEmail(string $email): array
throw new InvalidArgumentException("$email is not valid email.", E_USER_ERROR);
}

return [is_null($name) ? $email : $name, $email];
return [$name, $email];
}

/**
Expand All @@ -491,4 +491,18 @@ private function type(string $message, string $type): Envelop

return $this;
}

public function composeTo()
{
$to = '';
foreach ($this->getTo() as $value) {
if ($value[0] !== null) {
$to .= $value[0] . ' <' . $value[1] . '>';
} else {
$to .= '<' . $value[1] . '>';
}

$this->write('RCPT TO: ' . $to, 250);
}
}
}
4 changes: 1 addition & 3 deletions tests/Messaging/MessagingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
use PHPUnit\Framework\TestCase;
use Bow\Tests\Config\TestingConfiguration;
use Bow\Tests\Messaging\Stubs\TestMessage;
use Bow\Queue\Connection as QueueConnection;
use PHPUnit\Framework\MockObject\MockObject;
use Bow\Tests\Messaging\Stubs\TestNotifiableModel;

class MessagingTest extends TestCase
{
private static QueueConnection $queueConnection;
private MockObject|Model $context;
private MockObject|TestMessage $message;

Expand Down Expand Up @@ -63,7 +61,7 @@ public function test_message_can_send_to_mail(): void
$mailMessage = $message->toMail($context);

$this->assertInstanceOf(Envelop::class, $mailMessage);
$this->assertEquals('[email protected]', $mailMessage->getTo());
$this->assertEquals('[email protected]', $mailMessage->getTo()[1]);
$this->assertEquals('Test Message', $mailMessage->getSubject());
}

Expand Down

0 comments on commit e8ef6d6

Please sign in to comment.