summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-11 12:41:14 +0200
committerDanilo M. <danix@danix.xyz>2026-08-11 12:41:14 +0200
commit44d62143a83af8acbd1c1d14653d39da37e5de4a (patch)
tree360b8fae46487055fbd65bb1601f78345db7e27f /src/mainwindow.cpp
parent694ec02eb652fcfdbf65c27f68f4607f88615f76 (diff)
downloadqtmaildir-44d62143a83af8acbd1c1d14653d39da37e5de4a.tar.gz
qtmaildir-44d62143a83af8acbd1c1d14653d39da37e5de4a.zip
feat(sent): add a Sent view, flat and by recipient
Adds a `sent` key to [account.*] naming that account's sent folder, and a Sent button beside the saved queries that composes its query from every account carrying one. An account without the key is omitted silently, as a real account may keep no sent mail locally. With no account selected the button spans all of them; selecting one narrows it through the existing scope wrap rather than a second path. Composed at run time rather than shipped as a [queries] entry. A saved query is one fixed string: it cannot narrow to the selected account, and it goes stale the moment an account is added or a provider renames a folder. The design and the measurements behind it are in docs/superpowers/specs/2026-08-11-sent-mail-design.md. Three things there are worth repeating here. The composed path is QUOTED, and that is load-bearing. A real provider nests its sent folder under a bracketed parent, and "[" and "]" are Xapian syntax: unquoted, the query parses rather than matches and returns nothing while looking entirely plausible. Composition happens in one place so there is one chance to get it right, and a bracketed path is pinned in a test. Recipients are opt-in per query, which is a performance contract rather than a preference. notmuch_message_get_header(m, "To") is not served from the index, it reads the message file: folding every thread of a 4411-thread inbox took 38.2 seconds against 251 ms for the 601-thread sent view. The worker skips the walk entirely unless asked, and the refresh path carries the same flag so a background sync cannot blank the column mid-read. Always folding is mutation-tested: the data would be right and only the cost wrong, which nothing else here would notice. The messages reached through the thread are owned by it and freed with it, so recipientsOf() holds them raw and finishes while the thread is alive, exactly as walkReplies does. An NmMessage wrapper there is a double-free. Sent mail is presented flat, and the pane follows. A message you sent otherwise drags in the replies you received, so a view labelled Sent shows conversations rather than what you sent. ThreadListModel::setFlatMode() makes hasChildren() and ReplyCountRole answer differently and changes nothing else; runQuery() sets it on EVERY run, so any other query restores the tree on its way through and the flag cannot outlive the button that set it. The pane needed its own fix for the same reason: the single-message path depends on a field only filled when a thread is expanded, which never happens in a flat list, so loadThread() gained matchedOnly and drops the messages that did not match instead of rendering them as stubs. Recipients replace the sender through the existing SendersRole rather than a new one, so the delegate needs no branch and cannot disagree with the model about which name a row shows. It falls back to the sender when a To header is absent or unparseable, since a blank where a name belongs reads as a rendering fault. Address parsing uses GMime: a display name may contain a comma, so "Rossi, Mario" <m@example.org>, info@example.net is two addresses and splitting reports three. internet_address_list_parse returns NULL for an empty string, which is a crash if unguarded. Backlog item 63.
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 374f228..be6cfdb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -457,6 +457,7 @@ void MainWindow::buildUi()
this, &MainWindow::runCurrentQuery);
m_queryEdit = new QLineEdit(central);
+ m_queryEdit->setObjectName(QStringLiteral("queryEdit"));
m_queryEdit->setPlaceholderText(tr("notmuch query, e.g. tag:inbox"));
// Qt draws the clear button inside the field and shows it only when there
// is text, themed by the desktop. A hand-rolled button beside the bar would
@@ -553,6 +554,28 @@ void MainWindow::buildUi()
});
queryRow->addWidget(button);
}
+
+ // Sent sits with the saved queries and is not one: its query is COMPOSED
+ // from the accounts' `sent` keys at click time, so adding an account or
+ // correcting a folder name is a config edit and nothing else. A [queries]
+ // entry holding the same string would go stale silently, and could not
+ // narrow to the selected account the way this does through
+ // runCurrentQuery()'s existing scope wrap.
+ //
+ // Hidden entirely when no account configures a sent folder, rather than
+ // offering a button that always finds nothing.
+ if (!m_config.allSentQuery().isEmpty()) {
+ auto *sentButton = new QPushButton(tr("Sent"), central);
+ sentButton->setObjectName(QStringLiteral("sentButton"));
+ connect(sentButton, &QPushButton::clicked, this, [this]() {
+ m_queryEdit->setText(m_config.allSentQuery());
+ // Flat for this query only. runCurrentQuery() clears it again for
+ // anything else, including the same query typed by hand, so the
+ // flag cannot outlive the button that set it.
+ runQuery(FlatResult::Yes);
+ });
+ queryRow->addWidget(sentButton);
+ }
layout->addLayout(queryRow);
// Thread list and message pane.
@@ -1471,8 +1494,14 @@ void MainWindow::showWarnings()
problems.join(QLatin1Char('\n')));
}
-void MainWindow::runCurrentQuery()
+void MainWindow::runQuery(FlatResult flat)
{
+ // Set on EVERY run, not only when Yes. This is the line that stops flat
+ // mode leaking: any query that is not the Sent button restores the tree,
+ // so the flag cannot survive into the next view.
+ m_sentView = flat == FlatResult::Yes;
+ m_model->setFlatMode(m_sentView);
+
QString query = m_queryEdit->text().trimmed();
const QString accountKey = m_accountBox->currentData().toString();
@@ -1516,10 +1545,13 @@ void MainWindow::runCurrentQuery()
const auto sort = m_sortOrder->currentIndex() == 1
? NotmuchWorker::OldestFirst
: NotmuchWorker::NewestFirst;
+ // Recipients only for the Sent view: the fold reads message FILES, which
+ // is tens of seconds over an inbox. See ThreadSummary::recipients.
QMetaObject::invokeMethod(m_worker, "runQuery", Qt::QueuedConnection,
Q_ARG(QString, query),
Q_ARG(quint64, m_generation),
- Q_ARG(NotmuchWorker::SortOrder, sort));
+ Q_ARG(NotmuchWorker::SortOrder, sort),
+ Q_ARG(bool, m_sentView));
}
void MainWindow::onThreadsReady(const QVector<ThreadSummary> &threads,
@@ -1863,10 +1895,16 @@ void MainWindow::onThreadSelected(const QModelIndex &current,
m_currentMessageId.clear();
m_currentMessageThreadId.clear();
+ // In the Sent view the pane shows only what matched, which is what the
+ // user sent. Without this the flat list is right and the pane still opens
+ // the whole conversation, replies included, under a heading that says
+ // Sent: the row was never expanded, so the model never learned the
+ // thread's first message and this is the only path a Sent row can take.
QMetaObject::invokeMethod(m_worker, "loadThread", Qt::QueuedConnection,
Q_ARG(QString, m_currentThreadId),
Q_ARG(QString, m_lastQuery),
- Q_ARG(quint64, m_generation));
+ Q_ARG(quint64, m_generation),
+ Q_ARG(bool, m_sentView));
}
void MainWindow::onMessageLoaded(const QVector<MessageRef> &messages,
@@ -2250,10 +2288,14 @@ void MainWindow::refreshCurrentQuery()
const auto sort = m_sortOrder->currentIndex() == 1
? NotmuchWorker::OldestFirst
: NotmuchWorker::NewestFirst;
+ // The SAME recipients flag the visible view was built with. A refresh that
+ // dropped it would quietly replace a Sent view's recipients with empty
+ // strings on the first background sync, while the user was reading it.
QMetaObject::invokeMethod(m_worker, "runQuery", Qt::QueuedConnection,
Q_ARG(QString, m_lastQuery),
Q_ARG(quint64, m_refreshGeneration),
- Q_ARG(NotmuchWorker::SortOrder, sort));
+ Q_ARG(NotmuchWorker::SortOrder, sort),
+ Q_ARG(bool, m_sentView));
}
void MainWindow::updateStaleThreadNotice()