Skip to content

Commit

Permalink
SMTP: Dont send 'QUIT' on __destruct()
Browse files Browse the repository at this point in the history
This commit attempts to avoid errors / exceptions that cannot be managed from PHP
userspace when an SMTP object is destructed. It also adds a connection timeout
of 5 minutes so old connections can be recreated.
  • Loading branch information
protich committed Nov 7, 2022
1 parent bc017ec commit dbeae22
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions include/class.mail.php
Expand Up @@ -609,9 +609,10 @@ public function __construct(AccountSetting $setting) {
parent::__construct($this->buildOptions($setting));
}

// Build out SmtpOptions options based on SmtpAccount Settings
private function buildOptions(AccountSetting $setting) {
// Build out SmtpOptions options based on SmtpAccount Settings
$config = [];
// Dont send 'QUIT' on __destruct()
$config = ['use_complete_quit' => false];
$connect = $setting->getConnectionConfig();
$auth = $setting->getAuthCredentials();
switch (true) {
Expand All @@ -623,7 +624,7 @@ private function buildOptions(AccountSetting $setting) {
];
break;
case $auth instanceof BasicAuthCredentials:
$config = [
$config += [
'username' => $auth->getUsername(),
'password' => $auth->getPasswd(),
'ssl' => $connect['ssl'],
Expand All @@ -633,7 +634,7 @@ private function buildOptions(AccountSetting $setting) {
$token = $auth->getAccessToken();
if ($token->hasExpired())
throw new Exception('Access Token is Expired');
$config = [
$config += [
'xoauth2' => $token->getAuthRequest(),
'ssl' => $connect['ssl'],
];
Expand All @@ -643,8 +644,9 @@ private function buildOptions(AccountSetting $setting) {
}

return [
'host' => $connect['host'],
'port' => $connect['port'],
'host' => $connect['host'],
'port' => $connect['port'],
'connection_time_limit' => 300, # 5 minutes limit
'connection_class' => $auth->getConnectionClass(),
'connection_config' => $config
];
Expand Down

0 comments on commit dbeae22

Please sign in to comment.