diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-26 13:28:51 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-26 13:30:22 +0200 |
| commit | 0ca4624195cdd8c78ff614e3912af5b914458497 (patch) | |
| tree | 6fc739e77fed6b5a4e178cacf76ac29fd708ab0b /src/composecontext.cpp | |
| parent | d835cf3c554e9657fffdb91971b66e3a74aee323 (diff) | |
| download | qtmaildir-0ca4624195cdd8c78ff614e3912af5b914458497.tar.gz qtmaildir-0ca4624195cdd8c78ff614e3912af5b914458497.zip | |
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LXCZFLXbAii5n5wtovpdhh
Diffstat (limited to 'src/composecontext.cpp')
| -rw-r--r-- | src/composecontext.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/composecontext.cpp b/src/composecontext.cpp index 7233330..2dfee53 100644 --- a/src/composecontext.cpp +++ b/src/composecontext.cpp @@ -487,6 +487,58 @@ QString ComposeContextBuilder::forwardSubject(const QString &original) return QStringLiteral("Fwd: ") + original; } +bool ComposeContextBuilder::subjectIsForwarded(const QString &subject, + const QStringList &extraPrefixes) +{ + // Strip any Re: chain first, so "Re: Fwd: x" is recognised: a reply to a + // forward is still a forward the user received. Bounded rather than a + // while(true), since a crafted subject of ten thousand "Re:" is input from + // a stranger and this runs per row per repaint. + QString rest = subject; + for (int i = 0; i < 8; ++i) { + const QRegularExpressionMatch match = replyPrefix().match(rest); + if (!match.hasMatch()) + break; + rest = rest.mid(match.capturedEnd()); + } + + if (forwardPrefix().match(rest).hasMatch()) + return true; + + if (extraPrefixes.isEmpty()) + return false; + + // The configured spellings, matched with the same shape as the built-in + // table: anchored, case-insensitive, tolerating the counted forms Outlook + // emits. + // + // Escaped, because this comes from a hand-edited config file. Measured + // 2026-08-26: escaping alone already makes a punctuation entry inert + // rather than invalid, so the word guard below is NOT about pattern + // validity. It is about what a non-word entry would legitimately match: a + // configured "-" matches "-: x", and a digit entry matches a subject + // opening with a number, neither of which is a forward marker in any + // client. + QStringList alternatives; + for (const QString &prefix : extraPrefixes) { + const QString trimmed = prefix.trimmed(); + // A word only. A configured "Re" would swallow every reply, and a + // configured ":" or "" would match every subject in the mailbox. + static const QRegularExpression word(QStringLiteral("^[^\\W\\d_]+$")); + if (trimmed.isEmpty() || !word.match(trimmed).hasMatch()) + continue; + alternatives << QRegularExpression::escape(trimmed); + } + if (alternatives.isEmpty()) + return false; + + const QRegularExpression extra( + QStringLiteral("^\\s*(%1)\\s*(\\[\\d+\\]|\\(\\d+\\))?\\s*:") + .arg(alternatives.join(QLatin1Char('|'))), + QRegularExpression::CaseInsensitiveOption); + return extra.match(rest).hasMatch(); +} + ComposeContext ComposeContextBuilder::forDraft(const Config &config, const QString &path) { |
