Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(db): Truncate long IMAP message IDs #10178

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
foreach ($messages as $message) {
$query->setParameter(
'thread_root_id',
$message->getThreadRootId(),
mb_substr($message->getThreadRootId(), 0, 1023),

Check failure on line 238 in lib/Db/MessageMapper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Db/MessageMapper.php:238:16: PossiblyNullArgument: Argument 1 of mb_substr cannot be null, possibly null value provided (see https://psalm.dev/078)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How often will the prefix of thread_root_id be the same causing collisions? Would hashing to 1k bytes provide better resiliency against collisions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to say. Hashing long values could be a good idea for long messages. I'll look into that!

$message->getThreadRootId() === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR
);
$query->setParameter('id', $message->getDatabaseId(), IQueryBuilder::PARAM_INT);
Expand Down Expand Up @@ -289,13 +289,25 @@

foreach ($messages as $message) {
$qb1->setParameter('uid', $message->getUid(), IQueryBuilder::PARAM_INT);
$qb1->setParameter('message_id', $message->getMessageId(), IQueryBuilder::PARAM_STR);
$qb1->setParameter(
'message_id',
mb_substr($message->getMessageId(), 0, 1023),
IQueryBuilder::PARAM_STR,
);
$inReplyTo = $message->getInReplyTo();
$qb1->setParameter('in_reply_to', $inReplyTo, $inReplyTo === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR);
$qb1->setParameter(
'in_reply_to',
$inReplyTo === null ? null : mb_substr($inReplyTo, 0, 1023), // Truncate longer values
$inReplyTo === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR,
);
$references = $message->getReferences();
$qb1->setParameter('references', $references, $references === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR);
$threadRootId = $message->getThreadRootId();
$qb1->setParameter('thread_root_id', $threadRootId, $threadRootId === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR);
$qb1->setParameter(
'thread_root_id',
$threadRootId === null ? null : mb_substr($threadRootId, 0, 1023),
$threadRootId === null ? IQueryBuilder::PARAM_NULL : IQueryBuilder::PARAM_STR,
);
$qb1->setParameter('mailbox_id', $message->getMailboxId(), IQueryBuilder::PARAM_INT);
$qb1->setParameter('subject', $message->getSubject(), IQueryBuilder::PARAM_STR);
$qb1->setParameter('sent_at', $message->getSentAt(), IQueryBuilder::PARAM_INT);
Expand Down Expand Up @@ -541,7 +553,7 @@
return strcmp($a->getImapLabel(), $b->getImapLabel());
});
foreach ($toRemove as $tag) {
$this->tagMapper->untagMessage($tag, $message->getMessageId());

Check failure on line 556 in lib/Db/MessageMapper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyNullArgument

lib/Db/MessageMapper.php:556:41: PossiblyNullArgument: Argument 2 of OCA\Mail\Db\TagMapper::untagMessage cannot be null, possibly null value provided (see https://psalm.dev/078)
}
$perf->step('Untagged messages');
}
Expand Down
Loading