generated from Nodarx/template
feat: speed improvements
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit is contained in:
@@ -10,24 +10,25 @@ declare(strict_types=1);
|
||||
namespace KTXM\ProviderImapMail\Service\Remote;
|
||||
|
||||
use Gricob\IMAP\Client;
|
||||
use KTXC\Server;
|
||||
use KTXC\Logger\PlainFileLogger;
|
||||
use KTXM\ProviderImapMail\Providers\Service;
|
||||
|
||||
/**
|
||||
* Static factory for IMAP remote service objects.
|
||||
*
|
||||
* - freshClient() → builds a imap client from service config
|
||||
* - mailService() → constructs a RemoteMailService from the wrapper
|
||||
* - freshClient() → builds a gricob Client from service config
|
||||
* - mailService() → constructs a RemoteMailService from the client
|
||||
*/
|
||||
class RemoteService
|
||||
{
|
||||
/**
|
||||
* Build a fully-configured imap client from a Service's location and identity.
|
||||
* Build a fully-configured IMAP client from a Service's location and identity.
|
||||
*
|
||||
* Handles STARTTLS: connects on plain TCP, sends STARTTLS, upgrades to TLS,
|
||||
* then authenticates — all before returning the wrapper.
|
||||
* then authenticates — all before returning the client.
|
||||
*/
|
||||
public static function freshClient(Service $service, string $logDir): ImapClientWrapper
|
||||
public static function freshClient(Service $service): Client
|
||||
{
|
||||
$location = $service->getLocation();
|
||||
$identity = $service->getIdentity();
|
||||
@@ -35,6 +36,7 @@ class RemoteService
|
||||
// Build a file logger when debug mode is enabled, otherwise pass null
|
||||
$logger = null;
|
||||
if ($service->getDebug()) {
|
||||
$logDir = Server::getInstance()?->logDir() ?? __DIR__ . '/../../../../../var/log';
|
||||
$logger = new PlainFileLogger($logDir . '/imap', $service->identifier());
|
||||
}
|
||||
|
||||
@@ -47,17 +49,17 @@ class RemoteService
|
||||
|
||||
$client->logIn($identity->getIdentity(), $identity->getSecret());
|
||||
|
||||
return new ImapClientWrapper($client);
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a RemoteMailService from a Service and a pre-authenticated wrapper.
|
||||
* Build a RemoteMailService from a Service and a pre-authenticated client.
|
||||
*
|
||||
* The provider identifier and service ID are taken directly from the Service
|
||||
* object so the caller does not have to repeat them.
|
||||
*/
|
||||
public static function mailService(Service $service, ImapClientWrapper $wrapper): RemoteMailService
|
||||
public static function mailService(Service $service, Client $client): RemoteMailService
|
||||
{
|
||||
return new RemoteMailService($wrapper, $service->provider(), $service->identifier());
|
||||
return new RemoteMailService($client, $service->provider(), $service->identifier());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user