summaryrefslogtreecommitdiff
path: root/MessageFilterRules.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
committerChristoph Berg <myon@debian.org>2026-09-26 23:24:03 +0200
commit059831534c7e884f0a607ed86b582fd00d821731 (patch)
tree76bcb67a78f8aa2654fd34c2ad801a62136b0170 /MessageFilterRules.cpp
parentd83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff)
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'MessageFilterRules.cpp')
-rw-r--r--MessageFilterRules.cpp72
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;
+}