diff --git a/lib/Command/SyncAccount.php b/lib/Command/SyncAccount.php
index 64f81fa27d..8d725ede7a 100644
--- a/lib/Command/SyncAccount.php
+++ b/lib/Command/SyncAccount.php
@@ -12,6 +12,7 @@
use OCA\Mail\Account;
use OCA\Mail\Exception\IncompleteSyncException;
use OCA\Mail\Exception\ServiceException;
+use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\IMAP\MailboxSync;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Sync\ImapToDbSynchronizer;
@@ -34,17 +35,20 @@ final class SyncAccount extends Command {
private MailboxSync $mailboxSync;
private ImapToDbSynchronizer $syncService;
private LoggerInterface $logger;
+ private IMAPClientFactory $clientFactory;
public function __construct(AccountService $service,
MailboxSync $mailboxSync,
ImapToDbSynchronizer $messageSync,
- LoggerInterface $logger) {
+ LoggerInterface $logger,
+ IMAPClientFactory $clientFactory) {
parent::__construct();
$this->accountService = $service;
$this->mailboxSync = $mailboxSync;
$this->syncService = $messageSync;
$this->logger = $logger;
+ $this->clientFactory = $clientFactory;
}
/**
@@ -95,5 +99,9 @@ private function sync(Account $account, bool $force, OutputInterface $output): v
$output->writeln("Batch of new messages sync'ed. " . $mbs . 'MB of memory in use');
$this->sync($account, $force, $output);
}
+
+ foreach ($this->clientFactory->getLoginStats() as $host => $count) {
+ $consoleLogger->debug(sprintf('%d IMAP connection(s) to %s', $count, $host));
+ }
}
}
diff --git a/lib/IMAP/HordeImapClient.php b/lib/IMAP/HordeImapClient.php
index 46051fcc66..a962fed53b 100644
--- a/lib/IMAP/HordeImapClient.php
+++ b/lib/IMAP/HordeImapClient.php
@@ -28,6 +28,12 @@ class HordeImapClient extends Horde_Imap_Client_Socket {
private ?IMemcache $rateLimiterCache = null;
private ?ITimeFactory $timeFactory = null;
private ?string $hash = null;
+ private IMAPClientFactory $factory;
+
+ public function __construct(array $params, IMAPClientFactory $factory) {
+ parent::__construct($params);
+ $this->factory = $factory;
+ }
public function enableRateLimiter(
IMemcache $cache,
@@ -57,7 +63,9 @@ public function login() {
private const RATE_LIMIT_WINDOW = 3 * 60 * 60;
protected function imapLogin() {
- return parent::_login();
+ $result = parent::_login();
+ $this->factory->recordLogin($this->_params['hostspec']);
+ return $result;
}
#[\Override]
diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php
index 3ec6bd42d6..2829bd54d6 100644
--- a/lib/IMAP/IMAPClientFactory.php
+++ b/lib/IMAP/IMAPClientFactory.php
@@ -27,6 +27,9 @@
use function json_encode;
class IMAPClientFactory {
+ /** @var array */
+ private array $loginCounts = [];
+
/** @var ICrypto */
private $crypto;
@@ -134,7 +137,7 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn;
}
- $client = new HordeImapClient($params);
+ $client = new HordeImapClient($params, $this);
$rateLimitingCache = $this->cacheFactory->createDistributed('mail_imap_ratelimit');
if ($rateLimitingCache instanceof IMemcache) {
@@ -143,4 +146,13 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C
return $client;
}
+
+ public function recordLogin(string $host): void {
+ $this->loginCounts[$host] = ($this->loginCounts[$host] ?? 0) + 1;
+ }
+
+ /** @return array */
+ public function getLoginStats(): array {
+ return $this->loginCounts;
+ }
}