Skip to content

Commit

Permalink
Map connection_time_limit to ping_threshold.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Oct 3, 2024
1 parent 92279bf commit 36f84ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ port = 25
; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol
; based on the configured port is chosen (587 -> tls, 487 -> ssl).
;secure = tls
; This setting enforces a limit (in seconds) on the lifetime of an SMTP
; connection before the connection is checked, which can be useful when sending
; batches of emails, since it can help avoid errors caused by server timeouts.
; This is mapped to the ping_threshold option in Symfony Mailer.
; Comment out the setting to use the default ping threshold.
; See https://symfony.com/doc/current/mailer.html#other-options for more
; information.
connection_time_limit = 60
; The server name to report to the upstream mail server when sending mail.
;name = vufind.myuniversity.edu

Expand Down
10 changes: 9 additions & 1 deletion module/VuFind/src/VuFind/Mailer/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ protected function getDSN(array $config): string
if ($port = $config['Mail']['port'] ?? null) {
$dsn .= ":$port";
}

$dsnParams = [];
if ($name = $config['Mail']['name'] ?? null) {
$dsn .= "?local_domain=$name";
$dsnParams['local_domain'] = $name;
}
if (null !== ($limit = $config['Mail']['connection_time_limit'] ?? null)) {
$dsnParams['ping_threshold'] = $limit;
}
if ($dsnParams) {
$dsn .= '?' . http_build_query($dsnParams);
}

return $dsn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public function testFactoryConfiguration()
'Mail' => [
'host' => 'vufindtest.localhost',
'port' => 123,
'name' => 'foo',
'name' => 'foo?bar',
'username' => 'vufinduser',
'password' => 'vufindpass',
'connection_time_limit' => 60,
],
];
$configDsn = [
Expand All @@ -78,7 +79,7 @@ public function testFactoryConfiguration()
$factory = new MailerFactory();

$this->assertEquals(
'smtp://vufinduser:[email protected]:123?local_domain=foo',
'smtp://vufinduser:[email protected]:123?local_domain=foo%3Fbar&ping_threshold=60',
$this->callMethod($factory, 'getDSN', [$config])
);

Expand Down

0 comments on commit 36f84ca

Please sign in to comment.