feat: initial version

Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
Sebastian Krupinski
2026-02-20 16:41:19 -05:00
committed by Sebastian Krupinski
parent a313767846
commit e51c65bf19
139 changed files with 11256 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderImapMail\Service\Remote;
use Gricob\IMAP\Client;
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
*/
class RemoteService
{
/**
* 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.
*/
public static function freshClient(Service $service, string $logDir): ImapClientWrapper
{
$location = $service->getLocation();
$identity = $service->getIdentity();
// Build a file logger when debug mode is enabled, otherwise pass null
$logger = null;
if ($service->getDebug()) {
$logger = new PlainFileLogger($logDir . '/imap', $service->identifier());
}
$client = Client::create($location->toConfiguration(), $logger);
$client->connect();
if ($location->getEncryption() === 'starttls') {
$client->startTls();
}
$client->logIn($identity->getIdentity(), $identity->getSecret());
return new ImapClientWrapper($client);
}
/**
* Build a RemoteMailService from a Service and a pre-authenticated wrapper.
*
* 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
{
return new RemoteMailService($wrapper, $service->provider(), $service->identifier());
}
}