Skip to content

Commit

Permalink
fix(search): Limit recipient joins to their types
Browse files Browse the repository at this point in the history
* The join for FROM should only search only search FROM recipients.
* The join for TO should only search TO recipients.
* Etc.

Without the additional expression in the WHERE clause, all recipient
types would match.

Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst authored and backportbot-nextcloud[bot] committed Oct 16, 2023
1 parent fc5c2f9 commit d1f32a7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit
...array_map(function (string $label) use ($qb) {
return $qb->expr()->iLike('r0.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR));
}, $query->getFrom()),
)
),
$qb->expr()->eq('r0.type', $qb->createNamedParameter(Recipient::TYPE_FROM, IQueryBuilder::PARAM_INT)),
);
}
if (!empty($query->getTo())) {
Expand All @@ -763,7 +764,8 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit
...array_map(function (string $label) use ($qb) {
return $qb->expr()->iLike('r1.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR));
}, $query->getTo()),
)
),
$qb->expr()->eq('r1.type', $qb->createNamedParameter(Recipient::TYPE_TO, IQueryBuilder::PARAM_INT)),
);
}
if (!empty($query->getCc())) {
Expand All @@ -775,7 +777,8 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit
...array_map(function (string $label) use ($qb) {
return $qb->expr()->iLike('r2.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR));
}, $query->getCc()),
)
),
$qb->expr()->eq('r2.type', $qb->createNamedParameter(Recipient::TYPE_CC, IQueryBuilder::PARAM_INT)),
);
}
if (!empty($query->getBcc())) {
Expand All @@ -787,7 +790,8 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit
...array_map(function (string $label) use ($qb) {
return $qb->expr()->iLike('r3.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR));
}, $query->getBcc()),
)
),
$qb->expr()->eq('r3.type', $qb->createNamedParameter(Recipient::TYPE_BCC, IQueryBuilder::PARAM_INT)),
);
}

Expand Down

0 comments on commit d1f32a7

Please sign in to comment.