Skip to content

Commit

Permalink
NEXT-15669 - Improve mail configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim authored and pweyck committed Aug 2, 2021
1 parent 14b301b commit 82d8d19
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Core/Content/Mail/Service/MailerTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82d8d19

Please sign in to comment.