diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-24 21:19:05 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-24 21:19:05 +0200 |
| commit | c08ca00c36d06d7b1bbd5ce73d4d4dc3ce157e1c (patch) | |
| tree | b02f035e9b30ffc828dc00a4ae1760a3edf9598b | |
| parent | cf88c95aa5f16b918ebf207b3e323e44c525b440 (diff) | |
| download | qtmaildir-c08ca00c36d06d7b1bbd5ce73d4d4dc3ce157e1c.tar.gz qtmaildir-c08ca00c36d06d7b1bbd5ce73d4d4dc3ce157e1c.zip | |
fix(compose): a resumed draft does not re-seed on a From: change
A resumed draft kept m_signatureChosen false, so a From: change re-seeded
the signature and rewrote what the user had saved, inserting the new
account's where the saved block no longer matched a known file. The draft is
the user's deliberate prior state and must not follow a From: change, so the
draft branch marks it chosen.
| -rw-r--r-- | src/composewindow.cpp | 5 | ||||
| -rw-r--r-- | tests/test_composewindow.cpp | 58 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/composewindow.cpp b/src/composewindow.cpp index 94a3f46..d781e52 100644 --- a/src/composewindow.cpp +++ b/src/composewindow.cpp @@ -792,6 +792,11 @@ void ComposeWindow::seedSignature() // verbatim. Seeding again would append a second one. if (m_context.kind == ComposeContext::Kind::Draft) { none->setChecked(true); + // The draft IS the user's choice: its signature is deliberate prior + // state, so a From: change must not follow the new account and + // rewrite what was saved. Marking it chosen keeps the same invariant + // the switch actions set, without ever having run the switch. + m_signatureChosen = true; return; } diff --git a/tests/test_composewindow.cpp b/tests/test_composewindow.cpp index 8221ce3..47f7d87 100644 --- a/tests/test_composewindow.cpp +++ b/tests/test_composewindow.cpp @@ -46,6 +46,7 @@ private slots: void theSwitchListsEveryFileAndNone(); void changingTheAccountFollowsItsSignature(); void changingTheAccountStopsFollowingOnceTheSwitchIsUsed(); + void aResumedDraftDoesNotReseedOnAnAccountChange(); private: /// A config pointing at a signatures directory holding \p files, with one @@ -335,5 +336,62 @@ void TestComposeWindow::changingTheAccountStopsFollowingOnceTheSwitchIsUsed() QVERIFY(!body->toPlainText().contains(QStringLiteral("Home sig"))); } +void TestComposeWindow::aResumedDraftDoesNotReseedOnAnAccountChange() +{ + for (const auto &entry : + QList<QPair<QString, QString>>{ + { QStringLiteral("work.md"), QStringLiteral("Work sig") }, + { QStringLiteral("home.md"), QStringLiteral("Home sig") } }) { + QFile file(m_signatureDir + QStringLiteral("/") + entry.first); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + file.write(entry.second.toUtf8()); + file.close(); + } + + const QString path = m_dir->path() + QStringLiteral("/qtmaildir.conf"); + { + QFile file(path); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + QTextStream out(&file); + out << "[account.work]\n" + << "name = Someone\naddress = someone@example.org\n" + << "maildir = work\nsend_command = /bin/cat\n" + << "signature = work\n" + << "\n[account.home]\n" + << "name = Someone\naddress = other@example.org\n" + << "maildir = home\nsend_command = /bin/cat\n" + << "signature = home\n"; + } + Config config; + config.load(path); + + // The saved body already carries its own signature, which does not match + // any on-disk file. A From: change must not replace it with the new + // account's: the draft is the message the user wrote, exactly as + // seedBody() takes its body verbatim. + ComposeContext context; + context.kind = ComposeContext::Kind::Draft; + context.accountKey = QStringLiteral("work"); + context.body = QStringLiteral("Half a thought.\n\n-- \nJane Doe"); + context.draftPath = m_dir->path() + QStringLiteral("/draft"); + + ComposeWindow window(context, config, m_dir->path()); + window.setSignatureDir(m_signatureDir); + window.seedSignature(); + + auto *body = window.findChild<QPlainTextEdit *>(QStringLiteral("body")); + auto *from = window.findChild<QComboBox *>(QStringLiteral("from")); + QVERIFY(body); + QVERIFY(from); + QVERIFY(body->toPlainText().contains(QStringLiteral("Jane Doe"))); + + const int home = from->findData(QStringLiteral("home")); + QVERIFY(home >= 0); + from->setCurrentIndex(home); + + QVERIFY(body->toPlainText().contains(QStringLiteral("Jane Doe"))); + QVERIFY(!body->toPlainText().contains(QStringLiteral("Home sig"))); +} + QTEST_MAIN(TestComposeWindow) #include "test_composewindow.moc" |
