aboutsummaryrefslogtreecommitdiffstats
path: root/src/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 /src/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 'src/businesssenders.cpp')
-rw-r--r--src/businesssenders.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/businesssenders.cpp b/src/businesssenders.cpp
index 06f4d43..ab9394d 100644
--- a/src/businesssenders.cpp
+++ b/src/businesssenders.cpp
@@ -102,10 +102,17 @@ void appendCandidates(const QString &path, const QHash<QString, int> &counts)
// from parse() above, which deliberately drops comments: here a comment is
// exactly what must be remembered.
QSet<QString> mentioned;
+ bool needsLeadingNewline = false;
QFile existing(path);
if (existing.open(QIODevice::ReadOnly | QIODevice::Text)) {
- const QStringList lines =
- QString::fromUtf8(existing.readAll()).split(QLatin1Char('\n'));
+ const QString contents = QString::fromUtf8(existing.readAll());
+ // Hand-editing (the documented workflow) can leave the file without a
+ // trailing newline; appending then glues the first addition onto the
+ // last entry and silently breaks it. Write a newline before the
+ // additions in that case.
+ if (!contents.isEmpty() && !contents.endsWith(QLatin1Char('\n')))
+ needsLeadingNewline = true;
+ const QStringList lines = contents.split(QLatin1Char('\n'));
for (const QString &raw : lines) {
QString line = raw.trimmed();
if (line.startsWith(QLatin1Char('#')))
@@ -140,6 +147,8 @@ void appendCandidates(const QString &path, const QHash<QString, int> &counts)
if (!file.open(QIODevice::Append | QIODevice::Text))
return;
QTextStream out(&file);
+ if (needsLeadingNewline)
+ out << '\n';
for (const QString &line : additions)
out << line << '\n';
}