diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:28 +0200 |
| commit | 69344560ea394c06ca94acac46a2e4c3e8b7b229 (patch) | |
| tree | ebc98370a697a9bbd6b973a14fa5113c475c6db7 /MessageFilterRules.cpp | |
| parent | 3e9d10a67671d0bd5c7b8c3ca8088f1818322eff (diff) | |
| parent | 059831534c7e884f0a607ed86b582fd00d821731 (diff) | |
Update upstream source from tag 'upstream/3.2.0_rc1+dfsg'
Update to upstream version '3.2.0~rc1+dfsg'
with Debian dir dbff457fd2c3616d5c77b863c7bfb2186ed86047
Diffstat (limited to 'MessageFilterRules.cpp')
| -rw-r--r-- | MessageFilterRules.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/MessageFilterRules.cpp b/MessageFilterRules.cpp new file mode 100644 index 00000000..6208d998 --- /dev/null +++ b/MessageFilterRules.cpp @@ -0,0 +1,72 @@ +#include "MessageFilterRules.hpp" + +#include "MessageFilter.hpp" + +#include <QRegularExpression> +#include <QStringList> + +namespace +{ + using SpecOp = SpecialOperatingActivity; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + auto const SkipEmptyParts = Qt::SkipEmptyParts; +#else + auto const SkipEmptyParts = QString::SkipEmptyParts; +#endif + + QString msk144FilterText(QString const& text, MessageFilterLogic::FilterContext const& ctx) + { + if (!ctx.filtersForWord2) return text; + + QStringList const words = text.mid(24).split(" ", SkipEmptyParts); + if (words.size() < 2) return "___"; + if (words[1].length() == 2 && words[1].contains(QRegularExpression{"\\w\\w"})) { + return words.size() > 2 ? words[2] : "___"; + } + return words[1]; + } + + bool containsFilterMatch(QString const& filterText, QStringList const& keywords, bool startsWith) + { + return startsWith ? MessageFilter::startsWithAny(filterText, keywords) + : MessageFilter::containsAny(filterText, keywords); + } +} + +MessageFilterRules::Evaluation MessageFilterRules::evaluateMSK144Text(QString text, MessageFilterLogic::FilterContext const& ctx) +{ + Evaluation evaluation; + text = text.replace("<", "").replace(">", ""); + + bool const startsWith = ctx.filtersForWord2; + QString const filterText = msk144FilterText(text, ctx); + + if (SpecOp::NONE == ctx.specOp && ctx.alwaysPass && containsFilterMatch(filterText, ctx.passKeywords, startsWith)) { + return evaluation; + } + + evaluation.filtersApplied = true; + + if (SpecOp::NONE == ctx.specOp && ctx.blacklisted && containsFilterMatch(filterText, ctx.blacklistKeywords, startsWith)) { + if (!ctx.bypass) evaluation.result.filtered = true; + if (!(ctx.filtersForWaitAndPounceOnly || ctx.bypass)) { + evaluation.result.shouldReturn = true; + return evaluation; + } + if (ctx.pounce && isScoringAutoRespondPolicy (ctx.respondPolicy)) { + evaluation.result.resetPoints = true; + } + } else if (SpecOp::NONE == ctx.specOp && ctx.whitelisted && !containsFilterMatch(filterText, ctx.whitelistKeywords, startsWith)) { + if (!ctx.bypass) evaluation.result.filtered = true; + if (!(ctx.filtersForWaitAndPounceOnly || ctx.bypass)) { + evaluation.result.shouldReturn = true; + return evaluation; + } + if (ctx.pounce && isScoringAutoRespondPolicy (ctx.respondPolicy)) { + evaluation.result.resetPoints = true; + } + } + + return evaluation; +} |
