File tree 2 files changed +37
-1
lines changed
Test/MailTemplate/Service
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ public function create(?SystemConfigService $configService = null): TransportInt
5353 case 'smtp ' :
5454 return $ this ->createSmtpTransport ($ configService );
5555 case 'local ' :
56- return new SendmailTransport (' /usr/sbin/sendmail ' . ( $ configService -> getString ( ' core.mailerSettings.sendMailOptions ' ) ?: ' -bs ' ));
56+ return new SendmailTransport ($ this -> getSendMailCommandLineArgument ( $ configService ));
5757 default :
5858 throw new \RuntimeException (sprintf ('Invalid mail agent given "%s" ' , $ emailAgent ));
5959 }
@@ -86,4 +86,21 @@ private function getEncryption(SystemConfigService $configService): ?string
8686 return null ;
8787 }
8888 }
89+
90+ private function getSendMailCommandLineArgument (SystemConfigService $ configService ): string
91+ {
92+ $ command = '/usr/sbin/sendmail ' ;
93+
94+ $ option = $ configService ->getString ('core.mailerSettings.sendMailOptions ' );
95+
96+ if ($ option === '' ) {
97+ $ option = '-t ' ;
98+ }
99+
100+ if ($ option !== '-bs ' && $ option !== '-t ' ) {
101+ throw new \RuntimeException (sprintf ('Given sendmail option "%s" is invalid ' , $ option ));
102+ }
103+
104+ return $ command . $ option ;
105+ }
89106}
Original file line number Diff line number Diff line change @@ -70,6 +70,25 @@ public function testFactoryWithConfig(): void
7070
7171 static ::assertEquals (\get_class ($ original ), \get_class ($ mailer ));
7272 }
73+
74+ public function testFactoryWithLocalAndInvalidConfig (): void
75+ {
76+ $ original = new SendmailTransport ();
77+
78+ $ factory = $ this ->getContainer ()->get ('mailer.transport_factory ' );
79+
80+ static ::expectException (\RuntimeException::class);
81+ static ::expectExceptionMessage ('Given sendmail option "-t && echo bla" is invalid ' );
82+
83+ $ mailer = $ factory ->create (
84+ new ConfigService ([
85+ 'core.mailerSettings.emailAgent ' => 'local ' ,
86+ 'core.mailerSettings.sendMailOptions ' => '-t && echo bla ' ,
87+ ])
88+ );
89+
90+ static ::assertEquals (\get_class ($ original ), \get_class ($ mailer ));
91+ }
7392}
7493
7594class ConfigService extends SystemConfigService
You can’t perform that action at this time.
0 commit comments