Skip to content

Commit 1914869

Browse files
committed
Merge branch 'sw-26872/send-mail-message-id' into '5.7'
SW-26872 - Send 'Message-Id' header in mails See merge request shopware/5/product/shopware!867
2 parents 61f9a48 + afe67ef commit 1914869

File tree

6 files changed

+66
-17
lines changed

6 files changed

+66
-17
lines changed

.phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51965,16 +51965,6 @@ parameters:
5196551965
count: 1
5196651966
path: tests/Unit/Components/LegacyRequestWrapper/PostWrapperTest.php
5196751967

51968-
-
51969-
message: "#^Method Shopware\\\\Tests\\\\Unit\\\\Components\\\\MailTest\\:\\:testCodeInjectionInFromHeader\\(\\) has no return type specified\\.$#"
51970-
count: 1
51971-
path: tests/Unit/Components/MailTest.php
51972-
51973-
-
51974-
message: "#^Method Shopware\\\\Tests\\\\Unit\\\\Components\\\\MailTest\\:\\:testValidFromAddress\\(\\) has no return type specified\\.$#"
51975-
count: 1
51976-
path: tests/Unit/Components/MailTest.php
51977-
5197851968
-
5197951969
message: "#^Function Shopware\\\\Components\\\\ini_get\\(\\) has no return type specified\\.$#"
5198051970
count: 1

engine/Library/Enlight/Components/Mail.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ public function send($transport = null)
393393
]
394394
);
395395

396+
if (!$this->getMessageId()) {
397+
$this->setMessageId();
398+
}
399+
396400
return parent::send($transport);
397401
}
398402
}

engine/Library/Zend/Mail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ public function setMessageId($id = true)
10491049
/**
10501050
* Returns the Message-ID of the message
10511051
*
1052-
* @return string
1052+
* @return string|null
10531053
*/
10541054
public function getMessageId()
10551055
{
@@ -1136,7 +1136,7 @@ public function addHeader($name, $value, $append = false)
11361136
/**
11371137
* Return mail headers
11381138
*
1139-
* @return void
1139+
* @return array
11401140
*/
11411141
public function getHeaders()
11421142
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Shopware 5
4+
* Copyright (c) shopware AG
5+
*
6+
* According to our dual licensing model, this program can be used either
7+
* under the terms of the GNU Affero General Public License, version 3,
8+
* or under a proprietary license.
9+
*
10+
* The texts of the GNU Affero General Public License with an additional
11+
* permission and of our proprietary license can be found at and
12+
* in the LICENSE file you have received along with this program.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* "Shopware" is a registered trademark of shopware AG.
20+
* The licensing of the program under the AGPLv3 does not imply a
21+
* trademark license. Therefore any rights, title and interest in
22+
* our trademarks remain entirely with us.
23+
*/
24+
25+
namespace Shopware\Tests\Functional\Components;
26+
27+
use Enlight_Components_Mail;
28+
use PHPUnit\Framework\TestCase;
29+
use Shopware\Tests\Functional\Traits\ContainerTrait;
30+
31+
class MailTest extends TestCase
32+
{
33+
use ContainerTrait;
34+
35+
public function testMessageId(): void
36+
{
37+
$mailTransport = $this->getContainer()->get('mailtransport');
38+
39+
$mail = new Enlight_Components_Mail();
40+
$mail->setBodyText('Test Hello');
41+
$mail->addTo('[email protected]');
42+
43+
$mail->send($mailTransport);
44+
45+
$headers = $mail->getHeaders();
46+
static::assertArrayHasKey('Message-Id', $headers);
47+
$messageId = $headers['Message-Id'][0];
48+
static::assertIsString($messageId);
49+
static::assertStringContainsString('@', $messageId);
50+
static::assertStringStartsWith('<', $messageId);
51+
static::assertStringEndsWith('>', $messageId);
52+
}
53+
}

tests/Functional/Regressions/Ticket5217Test.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@
2828

2929
use Enlight_Components_Mail;
3030
use PHPUnit\Framework\TestCase;
31+
use Shopware\Tests\Functional\Traits\ContainerTrait;
3132

3233
class Ticket5217Test extends TestCase
3334
{
35+
use ContainerTrait;
36+
3437
/**
3538
* Test case method
3639
*/
3740
public function testMailTransport(): void
3841
{
39-
$mailTransport = Shopware()->Container()->get('mailtransport');
42+
$mailTransport = $this->getContainer()->get('mailtransport');
4043

4144
$mail = new Enlight_Components_Mail();
42-
43-
$mail->setBodyText('Test Hallo');
45+
$mail->setBodyText('Test Hello');
4446
$mail->addTo('[email protected]');
4547

4648
$mail = $mail->send($mailTransport);

tests/Unit/Components/MailTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030

3131
class MailTest extends TestCase
3232
{
33-
public function testValidFromAddress()
33+
public function testValidFromAddress(): void
3434
{
3535
$mail = new Enlight_Components_Mail();
3636
$mail->setFrom('[email protected]', 'Sender\'s name');
3737

3838
static::assertSame('[email protected]', $mail->getFrom());
3939
}
4040

41-
public function testCodeInjectionInFromHeader()
41+
public function testCodeInjectionInFromHeader(): void
4242
{
4343
$mail = new Enlight_Components_Mail();
4444

0 commit comments

Comments
 (0)