From 18ff1f33f64428ab96ca0b5ea22e681be564c886 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 13 Sep 2026 20:03:17 +0200 Subject: feat(config): a threaded, path-based spam filter --- tests/test_config.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'tests/test_config.cpp') diff --git a/tests/test_config.cpp b/tests/test_config.cpp index dd34e4f..70e3705 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -129,6 +129,8 @@ private slots: void theDraftsFilterIsFlatLikeSent(); void theTrashFilterComposesPerAccount(); void theTrashFilterMatchesNothingWithoutAFolder(); + void theSpamFilterComposesPerAccount(); + void theSpamFilterMatchesNothingWithoutAFolder(); void anAccountWithoutASendCommandIsReceiveOnly(); void composeSettingsDefaultWhenTheSectionIsAbsent(); void aZeroSendDelayIsHonouredRatherThanTreatedAsUnset(); @@ -1198,6 +1200,34 @@ void TestConfig::theTrashFilterMatchesNothingWithoutAFolder() QCOMPARE(config.resolvedQuery(trash, QString()), Config::matchNothingQuery()); } +void TestConfig::theSpamFilterComposesPerAccount() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\nspam=Spam\n" + "\n[account.personal]\nmaildir=personal\nspam=[Provider]/Spam\n"))); + const SavedQuery spam = Config::builtinFilter(QStringLiteral("spam")); + QVERIFY(spam.isGenerated()); + QVERIFY2(!spam.flat, "spam must be threaded, like trash"); + const QString all = config.resolvedQuery(spam, QString()); + QVERIFY(all.contains(QStringLiteral("path:\"work/Spam/**\""))); + QVERIFY(all.contains(QStringLiteral("path:\"personal/[Provider]/Spam/**\""))); + const QString scoped = config.resolvedQuery(spam, QStringLiteral("work")); + QCOMPARE(scoped, QStringLiteral("path:\"work/Spam/**\"")); + QVERIFY(!scoped.contains(QStringLiteral("personal"))); +} + +void TestConfig::theSpamFilterMatchesNothingWithoutAFolder() +{ + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\nmaildir=work\n"))); + const SavedQuery spam = Config::builtinFilter(QStringLiteral("spam")); + QCOMPARE(config.resolvedQuery(spam, QString()), Config::matchNothingQuery()); +} + void TestConfig::sentQueryComposesWithScopedQuery() { // A Sent view under one account must not show another account's sent mail. @@ -1628,7 +1658,7 @@ void TestConfig::everyBuiltinFilterIsAKnownGenerator() Config config; const QList filters = config.builtinFilters(); - QCOMPARE(filters.size(), 6); + QCOMPARE(filters.size(), 7); QStringList names; for (const SavedQuery &filter : filters) { @@ -1651,7 +1681,8 @@ void TestConfig::everyBuiltinFilterIsAKnownGenerator() QStringLiteral("Important"), QStringLiteral("Sent"), QStringLiteral("Drafts"), - QStringLiteral("Trash") })); + QStringLiteral("Trash"), + QStringLiteral("Spam") })); } void TestConfig::aFilterAcrossAllAccountsIsTheUnscopedQuery() -- cgit v1.2.3