Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/BackgroundJob/QuotaJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function run($argument): void {
if ($quota->getLimit() === 0) {
$mailAccount->setQuotaPercentage(0);
} else {
$mailAccount->setQuotaPercentage((int)round($quota->getUsage() / $quota->getLimit() * 100));
$mailAccount->setQuotaPercentage((int)round((float)$quota->getUsage() / (float)$quota->getLimit() * 100.0));
}
$this->accountService->update($mailAccount);
$current = $mailAccount->getQuotaPercentage();
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/AddMissingTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$progress->finish();
$output->writeln('');
$output->writeln('Patched default tags for ' . count($accounts));
$n = count($accounts);
$output->writeln("Patched default tags for $n");
return 0;
}
}
2 changes: 1 addition & 1 deletion lib/Command/CreateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$account = $this->accountService->save($account);

$output->writeln('<info>Account ' . $account->getId() . " for $email created</info>");
$output->writeln("<info>Account {$account->getId()} for $email created</info>");

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/DiagnoseAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ protected function printMailboxesMessagesStats(OutputInterface $output,
$status = $imapClient->status($mb, Horde_Imap_Client::STATUS_MESSAGES);
return $c + $status['messages'];
}, 0);
$output->writeln('Account has ' . $messages . ' messages in ' . count($mailboxes) . ' mailboxes');
$nMailboxes = count($mailboxes);
$output->writeln("Account has $messages messages in $nMailboxes mailboxes");
}
}
9 changes: 6 additions & 3 deletions lib/Command/ExportAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln(json_encode($this->getAccountsData($accounts), JSON_PRETTY_PRINT));
} else {
foreach ($accounts as $account) {
$output->writeln('<info>Account ' . $account->getId() . ':</info>');
$accountId = $account->getId();
$output->writeln("<info>Account $accountId:</info>");
$output->writeln('- E-Mail: ' . $account->getEmail());
$output->writeln('- Name: ' . $account->getName());
$output->writeln('- Provision: ' . ($account->getMailAccount()->getProvisioningId() ? 'set' : 'none') . ' ID: ' . ($account->getMailAccount()->getProvisioningId() ?: 'N/A'));
$output->writeln('- IMAP user: ' . $account->getMailAccount()->getInboundUser());
$output->writeln('- IMAP host: ' . $account->getMailAccount()->getInboundHost() . ':' . $account->getMailAccount()->getInboundPort() . ', security: ' . $account->getMailAccount()->getInboundSslMode());
$inboundPort = $account->getMailAccount()->getInboundPort();
$output->writeln('- IMAP host: ' . $account->getMailAccount()->getInboundHost() . ":$inboundPort, security: " . $account->getMailAccount()->getInboundSslMode());
$output->writeln('- SMTP user: ' . $account->getMailAccount()->getOutboundUser());
$output->writeln('- SMTP host: ' . $account->getMailAccount()->getOutboundHost() . ':' . $account->getMailAccount()->getOutboundPort() . ', security: ' . $account->getMailAccount()->getOutboundSslMode());
$outboundPort = $account->getMailAccount()->getOutboundPort();
$output->writeln('- SMTP host: ' . $account->getMailAccount()->getOutboundHost() . ":$outboundPort, security: " . $account->getMailAccount()->getOutboundSslMode());
}
}

Expand Down
12 changes: 8 additions & 4 deletions lib/Command/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<error>Could not read thread data</error>');
return 2;
}
$consoleLogger->debug(strlen($json) . 'B read');
$nRead = strlen($json);
$consoleLogger->debug("{$nRead}B read");
$parsed = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
$consoleLogger->debug(count($parsed) . ' data sets loaded');
$nParsed = count($parsed);
$consoleLogger->debug("$nParsed data sets loaded");
$threadData = array_map(static fn ($serialized) => new DatabaseMessage(
$serialized['databaseId'],
$serialized['subject'],
Expand All @@ -75,10 +77,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
), $parsed);

$threads = $this->builder->build($threadData, $consoleLogger);
$output->writeln(count($threads) . ' threads built from ' . count($threadData) . ' messages');
$nThreads = count($threads);
$nThreadData = count($threadData);
$output->writeln("$nThreads threads built from $nThreadData messages");

$mbs = (int)(memory_get_peak_usage() / 1024 / 1024);
$output->writeln('<info>' . $mbs . 'MB of memory used</info>');
$output->writeln("<info>{$mbs}MB of memory used</info>");

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public function updateBulk(Account $account, bool $permflagsEnabled, Message ...
$this->db->beginTransaction();

$perf = $this->performanceLogger->start(
'partial sync ' . $account->getId() . ':' . $account->getName()
"partial sync {$account->getId()}:{$account->getName()}"
);

// MailboxId is the same for all messages according to updateBulk() call
Expand Down
2 changes: 1 addition & 1 deletion lib/IMAP/IMAPClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C
];
}
if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
$fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log';
$fn = "mail-{$account->getUserId()}-{$account->getId()}-imap.log";
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn;
}

Expand Down
15 changes: 9 additions & 6 deletions lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function findAll(Horde_Imap_Client_Socket $client,
// Here we assume somewhat equally distributed UIDs
// +1 is added to fetch all messages with the rare case of strictly
// continuous UIDs and fractions
$estimatedPageSize = (int)(($totalRange / $total) * $maxResults) + 1;
$estimatedPageSize = (int)((float)($totalRange / $total) * $maxResults) + 1;
// Determine min UID to fetch, but don't exceed the known maximum
$lower = max(
$min,
Expand All @@ -180,20 +180,20 @@ public function findAll(Horde_Imap_Client_Socket $client,
];
}

$idsToFetch = new Horde_Imap_Client_Ids($lower . ':' . $upper);
$idsToFetch = new Horde_Imap_Client_Ids("$lower:$upper");
$actualPageSize = $this->getPageSize($client, $mailbox, $idsToFetch);
$logger->debug("Built range for findAll: min=$min max=$max total=$total totalRange=$totalRange estimatedPageSize=$estimatedPageSize actualPageSize=$actualPageSize lower=$lower upper=$upper highestKnownUid=$highestKnownUid");
while ($actualPageSize > $maxResults) {
$logger->debug("Range for findAll matches too many messages: min=$min max=$max total=$total estimatedPageSize=$estimatedPageSize actualPageSize=$actualPageSize");

$estimatedPageSize = (int)($estimatedPageSize / 2);
$estimatedPageSize = (int)($estimatedPageSize / 2.0);

$upper = min(
$max,
$lower + $estimatedPageSize,
$lower + 1_000_000, // Somewhat sensible number of UIDs that fit into memory (Horde_Imap_ClientId bloat)
);
$idsToFetch = new Horde_Imap_Client_Ids($lower . ':' . $upper);
$idsToFetch = new Horde_Imap_Client_Ids("$lower:$upper");
$actualPageSize = $this->getPageSize($client, $mailbox, $idsToFetch);
}

Expand Down Expand Up @@ -304,7 +304,8 @@ public function findByIds(Horde_Imap_Client_Base $client,
$fetchResults = array_values(array_filter($fetchResults, static fn (Horde_Imap_Client_Data_Fetch $fetchResult) => $fetchResult->exists(Horde_Imap_Client::FETCH_ENVELOPE)));

if ($fetchResults === []) {
$this->logger->debug("findByIds in $mailbox got " . count($ids) . ' UIDs but found none');
$nIds = count($ids);
$this->logger->debug("findByIds in $mailbox got $nIds UIDs but found none");
} else {
$minFetched = $fetchResults[0]->getUid();
$maxFetched = $fetchResults[count($fetchResults) - 1]->getUid();
Expand All @@ -313,7 +314,9 @@ public function findByIds(Horde_Imap_Client_Base $client,
} else {
$range = 'literals';
}
$this->logger->debug("findByIds in $mailbox got " . count($ids) . " UIDs ($range) and found " . count($fetchResults) . ". minFetched=$minFetched maxFetched=$maxFetched");
$nIds = count($ids);
$nFetched = count($fetchResults);
$this->logger->debug("findByIds in $mailbox got $nIds UIDs ($range) and found $nFetched. minFetched=$minFetched maxFetched=$maxFetched");
}

return array_map(fn (Horde_Imap_Client_Data_Fetch $fetchResult) => $this->imapMessageFactory
Expand Down
3 changes: 2 additions & 1 deletion lib/IMAP/Threading/ThreadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public function __construct(PerformanceLogger $performanceLogger) {
* @return Container[]
*/
public function build(array $messages, LoggerInterface $logger): array {
$n = count($messages);
$log = $this->performanceLogger->startWithLogger(
'Threading ' . count($messages) . ' messages',
"Threading $n messages",
$logger
);

Expand Down
12 changes: 8 additions & 4 deletions lib/Listener/AccountSynchronizedThreadUpdaterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ public function handle(Event $event): void {
$accountId = $event->getAccount()->getId();
$logger->debug("Building threads for account $accountId");
$messages = $this->mapper->findThreadingData($event->getAccount());
$logger->debug("Account $accountId has " . count($messages) . ' messages with threading information');
$nMessages = count($messages);
$logger->debug("Account $accountId has $nMessages messages with threading information");
$threads = $this->builder->build($messages, $logger);
$logger->debug("Account $accountId has " . count($threads) . ' threads');
$nThreads = count($threads);
$logger->debug("Account $accountId has $nThreads threads");
/** @var DatabaseMessage[] $flattened */
$flattened = iterator_to_array($this->flattenThreads($threads), false);
$logger->debug("Account $accountId has " . count($flattened) . ' messages with a new thread IDs');
$nFlattened = count($flattened);
$logger->debug("Account $accountId has $nFlattened messages with a new thread IDs");
$chunkSize = self::WRITE_IDS_CHUNK_SIZE;
foreach (array_chunk($flattened, self::WRITE_IDS_CHUNK_SIZE) as $chunk) {
$this->mapper->writeThreadIds($chunk);

$logger->debug('Chunk of ' . self::WRITE_IDS_CHUNK_SIZE . ' messages updated');
$logger->debug("Chunk of $chunkSize messages updated");
Comment on lines +70 to +74
}

// Free memory
Expand Down
12 changes: 6 additions & 6 deletions lib/Listener/MailboxesSynchronizedSpecialMailboxesUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(Event $event): void {
$draftsMailbox = $this->findSpecial($mailboxes, 'drafts');
$mailAccount->setDraftsMailboxId($draftsMailbox->getId());
} catch (DoesNotExistException $e) {
$this->logger->info('Account ' . $account->getId() . ' does not have a drafts mailbox');
$this->logger->info("Account {$account->getId()} does not have a drafts mailbox");

$mailAccount->setDraftsMailboxId(null);
}
Expand All @@ -72,7 +72,7 @@ public function handle(Event $event): void {
$sentMailbox = $this->findSpecial($mailboxes, 'sent');
$mailAccount->setSentMailboxId($sentMailbox->getId());
} catch (DoesNotExistException $e) {
$this->logger->info('Account ' . $account->getId() . ' does not have a sent mailbox');
$this->logger->info("Account {$account->getId()} does not have a sent mailbox");

$mailAccount->setSentMailboxId(null);
}
Expand All @@ -82,7 +82,7 @@ public function handle(Event $event): void {
$trashMailbox = $this->findSpecial($mailboxes, 'trash');
$mailAccount->setTrashMailboxId($trashMailbox->getId());
} catch (DoesNotExistException $e) {
$this->logger->info('Account ' . $account->getId() . ' does not have a trash mailbox');
$this->logger->info("Account {$account->getId()} does not have a trash mailbox");

$mailAccount->setTrashMailboxId(null);
}
Expand All @@ -92,7 +92,7 @@ public function handle(Event $event): void {
$archiveMailbox = $this->findSpecial($mailboxes, 'archive');
$mailAccount->setArchiveMailboxId($archiveMailbox->getId());
} catch (DoesNotExistException $e) {
$this->logger->info('Account ' . $account->getId() . ' does not have an archive mailbox');
$this->logger->info("Account {$account->getId()} does not have an archive mailbox");

$mailAccount->setArchiveMailboxId(null);
}
Expand All @@ -102,7 +102,7 @@ public function handle(Event $event): void {
$junkMailbox = $this->findSpecial($mailboxes, 'junk');
$mailAccount->setJunkMailboxId($junkMailbox->getId());
} catch (DoesNotExistException) {
$this->logger->info('Account ' . $account->getId() . ' does not have an junk mailbox');
$this->logger->info("Account {$account->getId()} does not have an junk mailbox");
$mailAccount->setJunkMailboxId(null);
Comment on lines +105 to 106
}
}
Expand All @@ -111,7 +111,7 @@ public function handle(Event $event): void {
$snoozeMailbox = $this->findSpecial($mailboxes, 'snooze');
$mailAccount->setSnoozeMailboxId($snoozeMailbox->getId());
} catch (DoesNotExistException $e) {
$this->logger->info('Account ' . $account->getId() . ' does not have an snooze mailbox');
$this->logger->info("Account {$account->getId()} does not have an snooze mailbox");

$mailAccount->setSnoozeMailboxId(null);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Migration/MigrateImportantFromImapAndDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function migrateImportantOnImap(Horde_Imap_Client_Socket $client, Account
try {
$this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT);
} catch (Horde_Imap_Client_Exception $e) {
$this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>');
$this->logger->debug("Could not flag messages in mailbox <{$mailbox->getId()}>");
throw new ServiceException($e->getMessage(), 0, $e);
}
}
Expand All @@ -67,7 +67,7 @@ public function migrateImportantFromDb(Horde_Imap_Client_Socket $client, Account
try {
$this->messageMapper->addFlag($client, $mailbox, $uids, Tag::LABEL_IMPORTANT);
} catch (Horde_Imap_Client_Exception $e) {
$this->logger->debug('Could not flag messages in mailbox <' . $mailbox->getId() . '>');
$this->logger->debug("Could not flag messages in mailbox <{$mailbox->getId()}>");
throw new ServiceException($e->getMessage(), 0, $e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SMTP/SmtpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function create(Account $account): Horde_Mail_Transport {
);
}
if ($account->getMailAccount()->getDebug() || $this->config->getSystemValueBool('app.mail.debug')) {
$fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log';
$fn = "mail-{$account->getUserId()}-{$account->getId()}-smtp.log";
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn;
}
return new Horde_Mail_Transport_Smtphorde($params);
Expand Down
9 changes: 5 additions & 4 deletions lib/Service/AiIntegrations/AiIntegrationsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function generateEventData(Account $account, string $threadId, array $mes
*/
public function getSmartReply(Account $account, Mailbox $mailbox, Message $message, string $currentUserId): ?array {
if (in_array(FreePromptTaskType::class, $this->textProcessingManager->getAvailableTaskTypes(), true)) {
$cachedReplies = $this->cache->getValue('smartReplies_' . $message->getId());
$cachedReplies = $this->cache->getValue("smartReplies_{$message->getId()}");
if ($cachedReplies) {
return json_decode($cachedReplies, true, 512);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public function getSmartReply(Account $account, Mailbox $mailbox, Message $messa
try {
$cleaned = preg_replace('/^```json\s*|\s*```$/', '', trim($replies));
$decoded = json_decode($cleaned, true, 512, JSON_THROW_ON_ERROR);
$this->cache->addValue('smartReplies_' . $message->getId(), $replies);
$this->cache->addValue("smartReplies_{$message->getId()}", $replies);
return $decoded;
} catch (JsonException $e) {
throw new ServiceException('Failed to decode smart replies JSON output', previous: $e);
Expand Down Expand Up @@ -341,7 +341,8 @@ public function requiresTranslation(
}

$language = explode('_', $this->l->getLanguageCode())[0];
$cachedValue = $this->cache->getValue('needsTranslation_' . $language . $message->getId());
$messageId = $message->getId();
$cachedValue = $this->cache->getValue("needsTranslation_{$language}{$messageId}");
if ($cachedValue) {
return $cachedValue === 'true' ? true : false;
}
Expand Down Expand Up @@ -397,7 +398,7 @@ public function requiresTranslation(
}
// Can't use json_decode() here because the output contains additional garbage
$result = preg_match('/{\s*"needsTranslation"\s*:\s*true\s*}/i', $output) === 1;
$this->cache->addValue('needsTranslation_' . $language . $message->getId(), $result ? 'true' : 'false');
$this->cache->addValue("needsTranslation_{$language}{$messageId}", $result ? 'true' : 'false');
return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Service/AntiSpamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function sendReportEmail(Account $account, Mailbox $mailbox, int $uid, st
try {
$attachmentMessage = $this->mailManager->getMessage($userId, $messageId);
} catch (DoesNotExistException $e) {
$this->logger->error('Could not find reported email with message ID #' . $messageId, ['exception' => $e]);
$this->logger->error("Could not find reported email with message ID #$messageId", ['exception' => $e]);
return;
}

Expand Down Expand Up @@ -203,7 +203,7 @@ public function sendReportEmail(Account $account, Mailbox $mailbox, int $uid, st
$mail->getRaw(false)
);
} catch (Horde_Imap_Client_Exception $e) {
$this->logger->error('Could not move report email to sent mailbox, but the report email was sent. Reported email was id: #' . $messageId, ['exception' => $e]);
$this->logger->error("Could not move report email to sent mailbox, but the report email was sent. Reported email was id: #$messageId", ['exception' => $e]);
} finally {
$client->logout();
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Service/AutoCompletion/AddressCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function __construct(CollectedAddressMapper $mapper,
* @return void
*/
public function addAddresses(string $userId, AddressList $addressList): void {
$this->logger->debug('collecting ' . count($addressList) . ' email addresses');
$nAddresses = count($addressList);
$this->logger->debug("collecting $nAddresses email addresses");
foreach ($addressList->iterate() as $address) {
/* @var $address Address */
$this->saveAddress($userId, $address);
Expand Down Expand Up @@ -82,7 +83,8 @@ private function saveAddress(string $userId, Address $address): void {
public function searchAddress(string $userId, string $term): array {
$this->logger->debug("searching for collected address <$term>");
$result = $this->mapper->findMatching($userId, $term);
$this->logger->debug('found ' . count($result) . ' matches in collected addresses');
$nResult = count($result);
$this->logger->debug("found $nResult matches in collected addresses");
return $result;
}
}
3 changes: 2 additions & 1 deletion lib/Service/AutoConfig/MxRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function query(string $host) {
asort($sortedRecords, SORT_NUMERIC);

$mxRecords = array_filter(array_keys($sortedRecords), static fn ($record) => !empty($record));
$this->logger->debug('found ' . count($sortedRecords) . " MX records for host <$host>");
$nRecords = count($sortedRecords);
$this->logger->debug("found $nRecords MX records for host <$host>");
if (empty(($mxRecords))) {
return [];
}
Expand Down
Loading
Loading