diff --git a/module/VuFind/src/VuFind/Mailer/Mailer.php b/module/VuFind/src/VuFind/Mailer/Mailer.php index ad096ba9a5431ccc1d917dd5d47d22e767326418..98deb61a34e816189ecdcd2373e62b2107ee3f1a 100644 --- a/module/VuFind/src/VuFind/Mailer/Mailer.php +++ b/module/VuFind/src/VuFind/Mailer/Mailer.php @@ -104,6 +104,21 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface return $message; } + /** + * Reset the connection in the transport. Implements a fluent interface. + * + * @return Mailer + */ + public function resetConnection() + { + // If the transport has a disconnect method, call it: + $transport = $this->getTransport(); + if (is_callable([$transport, 'disconnect'])) { + $transport->disconnect(); + } + return $this; + } + /** * Set the mail transport object. * diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php index 4f6d852489d6597d9ca3ae1ca7d44d0f5ef87f99..bf8dab5a97a96aaf6fabd5d832af2645e0d5c406 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php @@ -374,6 +374,19 @@ class MailerTest extends \VuFindTest\Unit\TestCase $mailer = new Mailer($transport); $mailer->sendRecord('to@example.com', 'from@example.com', 'message', $driver, $view); } + + /** + * Test connection reset + * + * @return void + */ + public function testResetConnection() + { + $transport = $this->createMock(\Zend\Mail\Transport\Smtp::class); + $transport->expects($this->once())->method('disconnect'); + $mailer = new Mailer($transport); + $mailer->resetConnection(); + } } class MockEmailRenderer extends \Zend\View\Renderer\PhpRenderer