File indexing completed on 2024-09-22 04:50:10

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "searchpattern.h"
0010 #include <Akonadi/Item>
0011 
0012 /**
0013  * @short This class represents a search pattern rule operating on a string.
0014  *
0015  * This class represents a search to be performed against a string.
0016  * The string can be either a message header, or a pseudo header, such
0017  * as \<body\>
0018  */
0019 namespace MailCommon
0020 {
0021 class SearchRuleString : public SearchRule
0022 {
0023 public:
0024     /**
0025      * Creates new new string search rule.
0026      *
0027      * @param field The field to search in.
0028      * @param function The function to use for searching.
0029      * @param contents The contents to search for.
0030      */
0031     explicit SearchRuleString(const QByteArray &field = QByteArray(), Function function = FuncContains, const QString &contents = QString());
0032 
0033     /**
0034      * Creates a new string search rule from an @p other rule.
0035      */
0036     SearchRuleString(const SearchRuleString &other);
0037 
0038     /**
0039      * Initializes this rule with an @p other rule.
0040      */
0041     const SearchRuleString &operator=(const SearchRuleString &other);
0042 
0043     /**
0044      * Destroys the string search rule.
0045      */
0046     ~SearchRuleString() override;
0047 
0048     /**
0049      * @copydoc SearchRule::isEmpty()
0050      */
0051     [[nodiscard]] bool isEmpty() const override;
0052 
0053     /**
0054      * @copydoc SearchRule::requiredPart()
0055      */
0056     [[nodiscard]] RequiredPart requiredPart() const override;
0057 
0058     /**
0059      * @copydoc SearchRule::matches()
0060      */
0061     [[nodiscard]] bool matches(const Akonadi::Item &item) const override;
0062 
0063     /**
0064      * A helper method for the main matches() method.
0065      * Does the actual comparing.
0066      */
0067     [[nodiscard]] bool matchesInternal(const QString &contents) const;
0068 
0069     /**
0070      * @copydoc SearchRule::addQueryTerms()
0071      */
0072     void addQueryTerms(Akonadi::SearchTerm &groupTerm, bool &emptyIsNotAnError) const override;
0073     [[nodiscard]] QString informationAboutNotValidRules() const override;
0074 };
0075 }