Skip to content

Commit f7343f9

Browse files
Merge branch '5.4' into 6.0
* 5.4: [VarExporter] fix tests on Windows [GHA] Fix psalm job Fix CS [PropertyInfo] strip only leading `\` when unknown docType [RateLimiter] Fix rate serialization for long intervals (monthly and yearly) ignoring exception from sem_get in SemaphoreStore Lock component, preventing of error: identifier removed [Console] Fix compact table style to avoid outputting a leading space fix: stringify from address for ses+api transport [Mailer] Use recipients in sendmail transport [Serializer] Fix nested deserialization_path computation when there is no metadata for the attribute [Asset] Update the error message when assets are not built
2 parents 0f4772d + 0333203 commit f7343f9

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env php
2+
<?php
3+
$argsPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'sendmail_args';
4+
5+
file_put_contents($argsPath, implode(' ', $argv));

Tests/Transport/SendmailTransportTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,81 @@
1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\DelayedEnvelope;
1516
use Symfony\Component\Mailer\Transport\SendmailTransport;
17+
use Symfony\Component\Mime\Address;
18+
use Symfony\Component\Mime\Email;
1619

1720
class SendmailTransportTest extends TestCase
1821
{
22+
private const FAKE_SENDMAIL = __DIR__.'/Fixtures/fake-sendmail.php -t';
23+
24+
/**
25+
* @var string
26+
*/
27+
private $argsPath;
28+
29+
protected function setUp(): void
30+
{
31+
$this->argsPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'sendmail_args';
32+
}
33+
34+
protected function tearDown(): void
35+
{
36+
if (file_exists($this->argsPath)) {
37+
@unlink($this->argsPath);
38+
}
39+
unset($this->argsPath);
40+
}
41+
1942
public function testToString()
2043
{
2144
$t = new SendmailTransport();
2245
$this->assertEquals('smtp://sendmail', (string) $t);
2346
}
47+
48+
public function testToIsUsedWhenRecipientsAreNotSet()
49+
{
50+
if ('\\' === \DIRECTORY_SEPARATOR) {
51+
$this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
52+
}
53+
54+
$mail = new Email();
55+
$mail
56+
57+
58+
->subject('Subject')
59+
->text('Some text')
60+
;
61+
62+
$envelope = new DelayedEnvelope($mail);
63+
64+
$sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
65+
$sendmailTransport->send($mail, $envelope);
66+
67+
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php [email protected] [email protected]');
68+
}
69+
70+
public function testRecipientsAreUsedWhenSet()
71+
{
72+
if ('\\' === \DIRECTORY_SEPARATOR) {
73+
$this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
74+
}
75+
76+
$mail = new Email();
77+
$mail
78+
79+
80+
->subject('Subject')
81+
->text('Some text')
82+
;
83+
84+
$envelope = new DelayedEnvelope($mail);
85+
$envelope->setRecipients([new Address('[email protected]')]);
86+
87+
$sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
88+
$sendmailTransport->send($mail, $envelope);
89+
90+
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php [email protected] [email protected]');
91+
}
2492
}

Transport/SendmailTransport.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ protected function doSend(SentMessage $message): void
9191
$this->getLogger()->debug(sprintf('Email transport "%s" starting', __CLASS__));
9292

9393
$command = $this->command;
94+
95+
if ($recipients = $message->getEnvelope()->getRecipients()) {
96+
$command = str_replace(' -t', '', $command);
97+
}
98+
9499
if (!str_contains($command, ' -f')) {
95100
$command .= ' -f'.escapeshellarg($message->getEnvelope()->getSender()->getEncodedAddress());
96101
}
@@ -101,6 +106,10 @@ protected function doSend(SentMessage $message): void
101106
$chunks = AbstractStream::replace("\n.", "\n..", $chunks);
102107
}
103108

109+
foreach ($recipients as $recipient) {
110+
$command .= ' '.escapeshellarg($recipient->getEncodedAddress());
111+
}
112+
104113
$this->stream->setCommand($command);
105114
$this->stream->initialize();
106115
foreach ($chunks as $chunk) {

0 commit comments

Comments
 (0)