From 89556386b4a21fe37d879f93735caa95500342fe Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 21 Jul 2023 15:56:51 +0200 Subject: [PATCH 1/2] feat(search): Use case-independent wildcard matches for recipients Signed-off-by: Christoph Wurst --- lib/Db/MessageMapper.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php index 82e21f2aec..b6168d6e59 100644 --- a/lib/Db/MessageMapper.php +++ b/lib/Db/MessageMapper.php @@ -743,22 +743,38 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit if (!empty($query->getFrom())) { $select->andWhere( - $qb->expr()->in('r0.email', $qb->createNamedParameter($query->getFrom(), IQueryBuilder::PARAM_STR_ARRAY)) + $qb->expr()->orX( + ...array_map(function (string $email) use ($qb) { + return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getFrom()) + ) ); } if (!empty($query->getTo())) { $select->andWhere( - $qb->expr()->in('r1.email', $qb->createNamedParameter($query->getTo(), IQueryBuilder::PARAM_STR_ARRAY)) + $qb->expr()->orX( + ...array_map(function (string $email) use ($qb) { + return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getTo()) + ) ); } if (!empty($query->getCc())) { $select->andWhere( - $qb->expr()->in('r2.email', $qb->createNamedParameter($query->getCc(), IQueryBuilder::PARAM_STR_ARRAY)) + $qb->expr()->orX( + ...array_map(function (string $email) use ($qb) { + return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getCc()) + ) ); } if (!empty($query->getBcc())) { $select->andWhere( - $qb->expr()->in('r3.email', $qb->createNamedParameter($query->getBcc(), IQueryBuilder::PARAM_STR_ARRAY)) + $qb->expr()->orX( + ...array_map(function (string $email) use ($qb) { + return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getBcc()) + ) ); } From 102a07060619432324729d7a50a56f7c5d5dfb91 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 21 Jul 2023 16:02:56 +0200 Subject: [PATCH 2/2] feat(search): Match recipient labels too Signed-off-by: Christoph Wurst --- lib/Db/MessageMapper.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php index b6168d6e59..d8a003cbcb 100644 --- a/lib/Db/MessageMapper.php +++ b/lib/Db/MessageMapper.php @@ -746,7 +746,10 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit $qb->expr()->orX( ...array_map(function (string $email) use ($qb) { return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); - }, $query->getFrom()) + }, $query->getFrom()), + ...array_map(function (string $label) use ($qb) { + return $qb->expr()->iLike('r0.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getFrom()), ) ); } @@ -755,7 +758,10 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit $qb->expr()->orX( ...array_map(function (string $email) use ($qb) { return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); - }, $query->getTo()) + }, $query->getTo()), + ...array_map(function (string $label) use ($qb) { + return $qb->expr()->iLike('r0.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getTo()), ) ); } @@ -764,7 +770,10 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit $qb->expr()->orX( ...array_map(function (string $email) use ($qb) { return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); - }, $query->getCc()) + }, $query->getCc()), + ...array_map(function (string $label) use ($qb) { + return $qb->expr()->iLike('r0.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getCc()), ) ); } @@ -773,7 +782,10 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, ?int $limit $qb->expr()->orX( ...array_map(function (string $email) use ($qb) { return $qb->expr()->iLike('r0.email', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($email) . '%', IQueryBuilder::PARAM_STR)); - }, $query->getBcc()) + }, $query->getBcc()), + ...array_map(function (string $label) use ($qb) { + return $qb->expr()->iLike('r0.label', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($label) . '%', IQueryBuilder::PARAM_STR)); + }, $query->getBcc()), ) ); }