aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_businesssenders.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-26 16:44:45 +0200
committerDanilo M. <danix@danix.xyz>2026-08-26 16:44:45 +0200
commit8dec28ff4f1176b485d9de722756c677be3a4f1c (patch)
tree04a8de233b122e44757f0532c32f52c47490285f /tests/test_businesssenders.cpp
parent29ffcccfd9fcaf15b9960557d662212760310abb (diff)
downloadqtmaildir-8dec28ff4f1176b485d9de722756c677be3a4f1c.tar.gz
qtmaildir-8dec28ff4f1176b485d9de722756c677be3a4f1c.zip
fix: harden candidate appends and cover the message-row sender roles
Diffstat (limited to 'tests/test_businesssenders.cpp')
-rw-r--r--tests/test_businesssenders.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_businesssenders.cpp b/tests/test_businesssenders.cpp
index bc6a5f6..fb26e28 100644
--- a/tests/test_businesssenders.cpp
+++ b/tests/test_businesssenders.cpp
@@ -34,6 +34,7 @@ private slots:
void matchingIsCaseInsensitive();
void anAbsentFileMatchesNothing();
void candidatesAreAppendedCommentedOut();
+ void appendingDoesNotCorruptALineThatLacksATrailingNewline();
void anAddressAlreadyPresentIsNeverReproposed();
void onlyBulkLookingLocalPartsAreProposed();
void theFirstRunScansEverything();
@@ -126,6 +127,36 @@ void TestBusinessSenders::candidatesAreAppendedCommentedOut()
QStringLiteral("noreply@cofidis.it")));
}
+void TestBusinessSenders::appendingDoesNotCorruptALineThatLacksATrailingNewline()
+{
+ // Hand-editing, the documented workflow, can leave the file without a
+ // trailing newline. Appending then glued the first candidate onto the last
+ // existing line, silently breaking the user's own active entry so it
+ // stopped matching. The guard writes a newline before the additions.
+ QTemporaryDir dir;
+ const QString path = dir.filePath(QStringLiteral("business-senders"));
+ QFile seed(path);
+ QVERIFY(seed.open(QIODevice::WriteOnly | QIODevice::Text));
+ seed.write("billing@example.org"); // deliberately no trailing newline
+ seed.close();
+
+ QHash<QString, int> counts;
+ counts.insert(QStringLiteral("noreply@a.org"), 3);
+ BusinessSenders::appendCandidates(path, counts);
+
+ // The original entry is intact and still matches.
+ const BusinessSenders::List list = BusinessSenders::load(path);
+ QVERIFY(BusinessSenders::contains(list,
+ QStringLiteral("billing@example.org")));
+
+ // ...and the candidate sits on its own commented line, not glued onto it.
+ QFile file(path);
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
+ const QString written = QString::fromUtf8(file.readAll());
+ QVERIFY(written.contains(QStringLiteral(
+ "billing@example.org\n# noreply@a.org (3 messages)")));
+}
+
void TestBusinessSenders::anAddressAlreadyPresentIsNeverReproposed()
{
QTemporaryDir dir;