Skip to content

Commit f85be9e

Browse files
Merge pull request #8451 from jdarwood007/mailAgentFixes
Various fixes for Mail Agent
2 parents 05ef441 + c072f60 commit f85be9e

3 files changed

Lines changed: 15 additions & 25 deletions

File tree

Sources/MailAgent/APIs/SMTP.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use SMF\Lang;
1919
use SMF\MailAgent\MailAgent;
2020
use SMF\MailAgent\MailAgentInterface;
21+
use SMF\Sapi;
2122
use SMF\Url;
22-
use SMF\Utils;
2323

2424
/**
2525
* Sends mail via SMTP
@@ -41,11 +41,12 @@ class SMTP extends MailAgent implements MailAgentInterface
4141
public bool $useTLS = false;
4242

4343
/**
44-
* @var resource
44+
* @var resource|false
4545
*
4646
* A file pointer containing the active connection to the SMTP server.
47+
* PHP does not have a type hint for resource of type Stream. So we just use mixed.
4748
*/
48-
private object $socket;
49+
private mixed $socket;
4950

5051
/**
5152
* {@inheritDoc}
@@ -111,16 +112,9 @@ public function connect(): bool
111112
return false;
112113
}
113114

114-
// Enable the encryption
115-
// php 5.6+ fix
116-
$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
115+
$crypto_method = STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
117116

118-
if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
119-
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
120-
$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
121-
}
122-
123-
if (!@stream_socket_enable_crypto($this->socket, true, $crypto_method)) {
117+
if (!stream_socket_enable_crypto($this->socket, true, $crypto_method)) {
124118
return false;
125119
}
126120

@@ -198,8 +192,8 @@ public function send(string $to, string $subject, string $message, string $heade
198192
}
199193

200194
// Almost done, almost done... don't stop me just yet!
201-
Utils::sapiSetTimeLimit(300);
202-
Utils::sapiResetTimeout();
195+
Sapi::setTimeLimit(300);
196+
Sapi::resetTimeout();
203197

204198
return true;
205199
}

Sources/MailAgent/APIs/SendMail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use SMF\Lang;
1919
use SMF\MailAgent\MailAgent;
2020
use SMF\MailAgent\MailAgentInterface;
21-
use SMF\Utils;
21+
use SMF\Sapi;
2222

2323
/**
2424
* Sends mail via SendMail
@@ -89,8 +89,8 @@ function ($errno, $errstr, $errfile, $errline) {
8989
restore_error_handler();
9090

9191
// Wait, wait, I'm still sending here!
92-
Utils::sapiSetTimeLimit();
93-
Utils::sapiResetTimeout();
92+
Sapi::setTimeLimit();
93+
Sapi::resetTimeout();
9494

9595
return $mail_result;
9696
}

Sources/MailAgent/MailAgent.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ abstract class MailAgent
5454
public static string $agent;
5555

5656
/**
57-
* @var \SMF\MailAgent\MailAgentInterface|bool
57+
* @var \SMF\MailAgent\MailAgentInterface|bool|null
5858
*
5959
* The loaded agent, or false on failure.
6060
*/
61-
public static MailAgentInterface|bool $loaded_api;
61+
public static MailAgentInterface|bool|null $loaded_api = null;
6262

6363
/**********************
6464
* Protected properties
@@ -211,7 +211,7 @@ final public static function load(bool $loadDefault = false): bool|MailAgentInte
211211
}
212212
}
213213

214-
if (is_object(self::$loaded_api)) {
214+
if (!is_null(self::$loaded_api) && is_object(self::$loaded_api)) {
215215
return self::$loaded_api;
216216
}
217217

@@ -220,7 +220,7 @@ final public static function load(bool $loadDefault = false): bool|MailAgentInte
220220
}
221221

222222
// What agent we are going to try.
223-
$agent_class_name = !empty(self::$agent) ? self::$agent : self::APIS_DEFAULT;
223+
$agent_class_name = !empty(self::$agent) && !$loadDefault ? self::$agent : self::APIS_DEFAULT;
224224
$fully_qualified_class_name = self::APIS_NAMESPACE . $agent_class_name;
225225

226226
// Do some basic tests.
@@ -252,10 +252,6 @@ final public static function load(bool $loadDefault = false): bool|MailAgentInte
252252
}
253253
}
254254

255-
if (!$agent_api && $agent_class_name !== self::APIS_DEFAULT) {
256-
$agent_api = self::load(false);
257-
}
258-
259255
return $agent_api;
260256
}
261257

0 commit comments

Comments
 (0)