From 0ca4624195cdd8c78ff614e3912af5b914458497 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 26 Aug 2026 13:28:51 +0200 Subject: feat: flag what you answered, mark what was forwarded to you Item 68, which turned out to be three things once its premise was measured. The note asked to extend a "passed" subject rule to "Fw:"; there was no subject rule, and the correlation it rested on did not exist. What did exist was a gap nobody had reported. Reply and forward now flag their source. The Maildir R and P flags, which every other client sets and notmuch reads back as "replied" and "passed", had never been written here: measured on the developer's index, all 317 "replied" and all 6 "passed" came from other clients. ComposeWindow emits sourceMessageAnswered after a successful send and MainWindow routes it through sendMessageTagChange, message-scoped and off the undo stack, for the reason auto mark-read is: the flag records that the mail went, and the send cannot be undone. ComposeContext carries sourceMessageId rather than reusing inReplyTo, which is deliberately empty on a forward so the recipient's client does not file it under the thread it left. Keying on it made the "passed" half dead code that compiled and never fired. A resumed draft is excluded: its kind records how the file was opened, not what the user is doing, so flagging on it would set R from a guess. A received forward gets its own mark. Derived from the subject at paint time, storing nothing and reaching no server, because "passed" means "I forwarded this" and setting it from a guess would assert something false on 222 existing messages. subjectIsForwarded() shares forwardSubject()'s prefix table so the two cannot disagree, strips a Re: chain first, and takes extra locale spellings from [general] forward_prefixes, which extends the built-in table rather than replacing it. A mutation survived the first round and corrected a claim in the code: QRegularExpression::escape already makes a punctuation prefix inert, so the word guard is not about pattern validity. It stops a configured "-" matching "-: x". The comment and test say that now. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LXCZFLXbAii5n5wtovpdhh --- tests/test_composecontext.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'tests/test_composecontext.cpp') diff --git a/tests/test_composecontext.cpp b/tests/test_composecontext.cpp index fccec87..bea390d 100644 --- a/tests/test_composecontext.cpp +++ b/tests/test_composecontext.cpp @@ -81,6 +81,8 @@ private slots: void aSingleLetterBeforeAColonIsNotAPrefix(); // Account resolution. + void aReceivedForwardIsRecognisedFromItsSubject(); + void configuredForwardPrefixesExtendTheBuiltInTable(); void theReplyAccountComesFromTheMessagesMaildir(); void anAccountIsNotMatchedByAPrefixOfItsMaildir(); void anAmbiguousMessagePrefersTheMatchingRecipient(); @@ -808,6 +810,81 @@ void TestComposeContext::aSingleLetterBeforeAColonIsNotAPrefix() QStringLiteral("Fwd: F: results")); } +void TestComposeContext::aReceivedForwardIsRecognisedFromItsSubject() +{ + using ComposeContextBuilder::subjectIsForwarded; + + // Item 68. The display predicate behind the received-forward mark. It + // shares forwardSubject()'s prefix table deliberately, so the two cannot + // disagree about what a forward looks like. + QVERIFY(subjectIsForwarded(QStringLiteral("Fwd: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("Fw: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("FWD: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("WG: Angebot"))); + QVERIFY(subjectIsForwarded(QStringLiteral("TR: document"))); + + // Anchored. "Fwd:" inside a subject is a quotation, not a marker, and the + // whole reason item 68's entry insisted on anchoring. + QVERIFY(!subjectIsForwarded(QStringLiteral("Notes fwd: budget"))); + QVERIFY(!subjectIsForwarded(QStringLiteral("budget"))); + QVERIFY(!subjectIsForwarded(QString())); + + // The single-letter spellings stay unrecognised here for exactly the + // reason forwardSubject() rejects them: "I: notes" is an ordinary subject. + QVERIFY(!subjectIsForwarded(QStringLiteral("I: notes"))); + QVERIFY(!subjectIsForwarded(QStringLiteral("F: results"))); + + // A reply to a forward is still a forward the user received, so the Re: + // chain is stripped first. Both orders, and a counted Outlook form. + QVERIFY(subjectIsForwarded(QStringLiteral("Re: Fwd: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("Re: Re: Fwd: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("Re[2]: Fwd: budget"))); + QVERIFY(subjectIsForwarded(QStringLiteral("AW: WG: Angebot"))); + + // A plain reply is not a forward, however deep the chain. + QVERIFY(!subjectIsForwarded(QStringLiteral("Re: budget"))); + QVERIFY(!subjectIsForwarded(QStringLiteral("Re: Re: Re: budget"))); +} + +void TestComposeContext::configuredForwardPrefixesExtendTheBuiltInTable() +{ + using ComposeContextBuilder::subjectIsForwarded; + + // Item 68. [general] forward_prefixes ADDS to the table rather than + // replacing it: a user adding Dutch must not lose English. + const QStringList dutch = { QStringLiteral("Doorst") }; + QVERIFY(subjectIsForwarded(QStringLiteral("Doorst: begroting"), dutch)); + QVERIFY(subjectIsForwarded(QStringLiteral("Fwd: budget"), dutch)); + + // Case-insensitive and counted forms, like the built-ins. + QVERIFY(subjectIsForwarded(QStringLiteral("DOORST: begroting"), dutch)); + QVERIFY(subjectIsForwarded(QStringLiteral("Doorst[2]: begroting"), dutch)); + QVERIFY(subjectIsForwarded(QStringLiteral("Re: Doorst: begroting"), dutch)); + + // An unconfigured spelling stays unrecognised, which is what makes the + // key worth having rather than the predicate matching anything. + QVERIFY(!subjectIsForwarded(QStringLiteral("Doorst: begroting"))); + + // Non-word entries are ignored per entry. Measured 2026-08-26: escaping + // alone already makes punctuation inert, so what the guard actually buys + // is that a configured "-" does not make "-: x" a forward, and a digit + // does not make "2: x" one. Neither is a marker any client emits. + QVERIFY(!subjectIsForwarded(QStringLiteral("-: x"), + { QStringLiteral("-") })); + QVERIFY(!subjectIsForwarded(QStringLiteral("2: x"), + { QStringLiteral("2") })); + + // An empty or blank entry contributes nothing rather than matching + // everything, which is the failure that would be silent and total. + const QStringList blank = { QString(), QStringLiteral(" ") }; + QVERIFY(!subjectIsForwarded(QStringLiteral("budget"), blank)); + QVERIFY(!subjectIsForwarded(QStringLiteral("anything at all"), blank)); + + // A configured "Re" must not turn every reply into a forward. + QVERIFY(!subjectIsForwarded(QStringLiteral("Re: budget"), + { QStringLiteral("Re") })); +} + // --------------------------------------------------------------------------- // Account resolution // --------------------------------------------------------------------------- -- cgit v1.2.3