Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7134e46

Browse filesBrowse files
committed
[Mailer] Use recipients in sendmail transport
1 parent f1f123b commit 7134e46
Copy full SHA for 7134e46

File tree

Expand file treeCollapse file tree

3 files changed

+82
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+82
-0
lines changed
+5Lines 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));

‎src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/SendmailTransportTest.php
+68Lines 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+
->from('from@mail.com')
57+
->to('to@mail.com')
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 -ffrom@mail.com to@mail.com');
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+
->from('from@mail.com')
79+
->to('to@mail.com')
80+
->subject('Subject')
81+
->text('Some text')
82+
;
83+
84+
$envelope = new DelayedEnvelope($mail);
85+
$envelope->setRecipients([new Address('recipient@mail.com')]);
86+
87+
$sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
88+
$sendmailTransport->send($mail, $envelope);
89+
90+
$this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php -ffrom@mail.com recipient@mail.com');
91+
}
2492
}

‎src/Symfony/Component/Mailer/Transport/SendmailTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/SendmailTransport.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ protected function doSend(SentMessage $message): void
8686
$this->getLogger()->debug(sprintf('Email transport "%s" starting', __CLASS__));
8787

8888
$command = $this->command;
89+
90+
if (!empty($recipients = $message->getEnvelope()->getRecipients())) {
91+
$command = str_replace(' -t', '', $command);
92+
}
93+
8994
if (!str_contains($command, ' -f')) {
9095
$command .= ' -f'.escapeshellarg($message->getEnvelope()->getSender()->getEncodedAddress());
9196
}
@@ -96,6 +101,10 @@ protected function doSend(SentMessage $message): void
96101
$chunks = AbstractStream::replace("\n.", "\n..", $chunks);
97102
}
98103

104+
foreach ($recipients as $recipient) {
105+
$command .= ' '.escapeshellarg($recipient->getEncodedAddress());
106+
}
107+
99108
$this->stream->setCommand($command);
100109
$this->stream->initialize();
101110
foreach ($chunks as $chunk) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.