MailCommon::SearchPattern Class

class MailCommon::SearchPattern

An abstraction of a search over messages. More...

Header: #include <MailCommon/SearchPattern>
CMake: find_package(KPim6MailCommon REQUIRED)
target_link_libraries(mytarget PRIVATE KPim6::MailCommon)
Inherits: QList

Public Types

enum Operator { OpAnd, OpOr, OpAll }

Public Functions

SearchPattern()
SearchPattern(const KConfigGroup &config)
~SearchPattern()
MailCommon::SearchPattern::SparqlQueryError asAkonadiQuery(Akonadi::SearchQuery &) const
QString asString() const
void deserialize(const QByteArray &)
void generateSieveScript(QStringList &requiresModules, QString &code)
bool matches(const Akonadi::Item &item, bool ignoreBody = false) const
QString name() const
MailCommon::SearchPattern::Operator op() const
QString purify(bool removeAction = true)
void readConfig(const KConfigGroup &config)
MailCommon::SearchRule::RequiredPart requiredPart() const
QByteArray serialize() const
void setName(const QString &newName)
void setOp(MailCommon::SearchPattern::Operator aOp)
void writeConfig(KConfigGroup &config) const
QDataStream &operator<<(QDataStream &s)
const MailCommon::SearchPattern &operator=(const MailCommon::SearchPattern &aPattern)
QDataStream &operator>>(QDataStream &s) const

Static Public Members

Detailed Description

This class is an abstraction of a search over messages. It is intended to be used inside a KFilter (which adds KFilterAction's), as well as in KMSearch. It can read and write itself into a KConfig group and there is a constructor, mainly used by KMFilter to initialize from a preset KConfig-Group.

From a class hierarchy point of view, it is a QPtrList of SearchRule's that adds the boolean operators (see Operator) 'and' and 'or' that connect the rules logically, and has a name under which it could be stored in the config file.

As a QPtrList with autoDelete enabled, it assumes that it is the central repository for the rules it contains. So if you want to reuse a rule in another pattern, make a deep copy of that rule.

Author: Marc Mutz <mutz@kde.org>

Member Type Documentation

enum SearchPattern::Operator

Boolean operators that connect the return values of the individual rules. A pattern with OpAnd will match iff all it's rules match, whereas a pattern with OpOr will match if any of it's rules matches.

ConstantValueDescription
MailCommon::SearchPattern::OpAnd0All rules must match
MailCommon::SearchPattern::OpOr1Any rule must match
MailCommon::SearchPattern::OpAll2All messages match

Member Function Documentation

SearchPattern::SearchPattern()

Constructor which provides a pattern with minimal, but sufficient initialization. Unmodified, such a pattern will fail to match any KMime::Message. You can query for such an empty rule by using isEmpty, which is inherited from QPtrList.

[explicit] SearchPattern::SearchPattern(const KConfigGroup &config)

Constructor that initializes from a given KConfig group, if given. This feature is mainly (solely?) used in KMFilter, as we don't allow to store search patterns in the config (yet).

[noexcept] SearchPattern::~SearchPattern()

Destructor. Deletes all stored rules!

MailCommon::SearchPattern::SparqlQueryError SearchPattern::asAkonadiQuery(Akonadi::SearchQuery &) const

Returns the pattern as akonadi query

QString SearchPattern::asString() const

Returns the pattern as string. For debugging.

void SearchPattern::deserialize(const QByteArray &)

Constructs the pattern from a byte array serialization.

[static] int SearchPattern::filterRulesMaximumSize()

Returns the maximum number of filter rules allowed.

void SearchPattern::generateSieveScript(QStringList &requiresModules, QString &code)

Generates a Sieve script representation of this pattern.

requiresModules The list of Sieve modules required by the script code The generated Sieve script code

bool SearchPattern::matches(const Akonadi::Item &item, bool ignoreBody = false) const

The central function of this class. Tries to match the set of rules against a KMime::Message. It's virtual to allow derived classes with added rules to reimplement it, yet reimplemented methods should and (&&) the result of this function with their own result or else most functionality is lacking, or has to be reimplemented, since the rules are private to this class.

item The Akonadi item to match ignoreBody Whether to ignore the body content when matching Returns True if the match was successful, false otherwise

QString SearchPattern::name() const

Returns the name of the search pattern.

See also setName().

MailCommon::SearchPattern::Operator SearchPattern::op() const

Returns the filter operator.

See also setOp().

QString SearchPattern::purify(bool removeAction = true)

Removes all empty rules from the list. You should call this method whenever the user had had control of the rules outside of this class. (e.g. after editing it with SearchPatternEdit).

Rules are only removed if removeAction is true. Returns a description of the invalid rules that were removed.

void SearchPattern::readConfig(const KConfigGroup &config)

Reads a search pattern from a KConfigGroup. If it does not find a valid saerch pattern in the preset group, initializes the pattern as if it were constructed using the default constructor.

For backwards compatibility with previous versions of KMail, it checks for old-style filter rules (e.g. using OpIgnore) in config und converts them to the new format on writeConfig.

Derived classes reimplementing readConfig() should also call this method, or else the rules will not be loaded.

MailCommon::SearchRule::RequiredPart SearchPattern::requiredPart() const

Returns the required part from the item that is needed for the search to operate. See SearchRule::RequiredPart

QByteArray SearchPattern::serialize() const

Writes the pattern into a byte array for persistence purposes.

void SearchPattern::setName(const QString &newName)

Sets the name of the search pattern to newName. KMFilter uses this to store it's own name, too.

See also name().

void SearchPattern::setOp(MailCommon::SearchPattern::Operator aOp)

Sets the filter operator to aOp.

See also op().

void SearchPattern::writeConfig(KConfigGroup &config) const

Writes itself into config. Tries to delete old-style keys by overwriting them with QString().

Derived classes reimplementing writeConfig() should also call this method, or else the rules will not be stored.

QDataStream &SearchPattern::operator<<(QDataStream &s)

Stream operator for input. Reads the pattern from the stream s and returns it.

const MailCommon::SearchPattern &SearchPattern::operator=(const MailCommon::SearchPattern &aPattern)

Overloaded assignment operator. Makes a deep copy of aPattern.

QDataStream &SearchPattern::operator>>(QDataStream &s) const

Stream operator for output. Writes the pattern into the stream s and returns it.