File size: 2,806 Bytes
cb29db0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/src/Core/Content/Mail/Service/MailerTransportFactory.php b/src/Core/Content/Mail/Service/MailerTransportFactory.php
index 6b4ccac68d9..72400df9e78 100644
--- a/src/Core/Content/Mail/Service/MailerTransportFactory.php
+++ b/src/Core/Content/Mail/Service/MailerTransportFactory.php
@@ -53,7 +53,7 @@ public function create(?SystemConfigService $configService = null): TransportInt
             case 'smtp':
                 return $this->createSmtpTransport($configService);
             case 'local':
-                return new SendmailTransport('/usr/sbin/sendmail ' . ($configService->getString('core.mailerSettings.sendMailOptions') ?: '-bs'));
+                return new SendmailTransport($this->getSendMailCommandLineArgument($configService));
             default:
                 throw new \RuntimeException(sprintf('Invalid mail agent given "%s"', $emailAgent));
         }
@@ -86,4 +86,21 @@ private function getEncryption(SystemConfigService $configService): ?string
                 return null;
         }
     }
+
+    private function getSendMailCommandLineArgument(SystemConfigService $configService): string
+    {
+        $command = '/usr/sbin/sendmail ';
+
+        $option = $configService->getString('core.mailerSettings.sendMailOptions');
+
+        if ($option === '') {
+            $option = '-t';
+        }
+
+        if ($option !== '-bs' && $option !== '-t') {
+            throw new \RuntimeException(sprintf('Given sendmail option "%s" is invalid', $option));
+        }
+
+        return $command . $option;
+    }
 }
diff --git a/src/Core/Content/Test/MailTemplate/Service/MailerTransportFactoryTest.php b/src/Core/Content/Test/MailTemplate/Service/MailerTransportFactoryTest.php
index 013cb15ff64..8fbb9a20995 100644
--- a/src/Core/Content/Test/MailTemplate/Service/MailerTransportFactoryTest.php
+++ b/src/Core/Content/Test/MailTemplate/Service/MailerTransportFactoryTest.php
@@ -70,6 +70,25 @@ public function testFactoryWithConfig(): void
 
         static::assertEquals(\get_class($original), \get_class($mailer));
     }
+
+    public function testFactoryWithLocalAndInvalidConfig(): void
+    {
+        $original = new SendmailTransport();
+
+        $factory = $this->getContainer()->get('mailer.transport_factory');
+
+        static::expectException(\RuntimeException::class);
+        static::expectExceptionMessage('Given sendmail option "-t && echo bla" is invalid');
+
+        $mailer = $factory->create(
+            new ConfigService([
+                'core.mailerSettings.emailAgent' => 'local',
+                'core.mailerSettings.sendMailOptions' => '-t && echo bla',
+            ])
+        );
+
+        static::assertEquals(\get_class($original), \get_class($mailer));
+    }
 }
 
 class ConfigService extends SystemConfigService