Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Command/SyncAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -95,5 +99,9 @@ private function sync(Account $account, bool $force, OutputInterface $output): v
$output->writeln("<info>Batch of new messages sync'ed. " . $mbs . 'MB of memory in use</info>');
$this->sync($account, $force, $output);
}

foreach ($this->clientFactory->getLoginStats() as $host => $count) {
$consoleLogger->debug(sprintf('%d IMAP connection(s) to %s', $count, $host));
}
}
}
10 changes: 9 additions & 1 deletion lib/IMAP/HordeImapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 13 additions & 1 deletion lib/IMAP/IMAPClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
use function json_encode;

class IMAPClientFactory {
/** @var array<string, int> */
private array $loginCounts = [];

/** @var ICrypto */
private $crypto;

Expand Down Expand Up @@ -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) {
Expand All @@ -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<string, int> */
public function getLoginStats(): array {
return $this->loginCounts;
}
}
Loading