From 01194fa2c48019f1dcbdfefac94f8fd5f8e38122 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 7 Aug 2026 19:17:59 +0200 Subject: feat(sync): sync only the accounts with unsynced edits A sync ran mbsync -a regardless of what changed, so tagging mail in one account fetched all of them. The account set was not a parameter anywhere on the path: MailSync::start() took no arguments and the script hardcoded -a, so nothing between a tag edit and mbsync carried which account changed. Track which accounts have edits and pass their mbsync channels through to the script, which now takes channel names and falls back to -a when given none. An empty set means all accounts, per the request: a sync with nothing pending is a fetch, and narrowing that to wherever the last edit landed would quietly stop collecting mail everywhere else. The channel is a new optional per-account key rather than the section key. The two names genuinely diverge, because a QSettings section key may carry dots that the channel does not, and mbsync treats an unknown channel as fatal rather than skipping it, so key-as-channel would fail those accounts' syncs outright rather than degrade. It defaults to the key, so accounts whose two names already agree need no config change. The edited-account set is deliberately not netted the way the pending-edit map is: that map tracks the index, where a tag removed and re-added leaves nothing outstanding, while this tracks the mail store, where both writes have already renamed files that mbsync still has to propagate. It is also snapshotted before flushHeldEdits(), which inserts into it synchronously rather than on a queued reply, so a successful sync cannot clear accounts whose edits it never carried. Closes item 49. Co-Authored-By: Claude Opus 5 --- tests/test_config.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/test_config.cpp') diff --git a/tests/test_config.cpp b/tests/test_config.cpp index 4d92891..dc85968 100644 --- a/tests/test_config.cpp +++ b/tests/test_config.cpp @@ -51,6 +51,8 @@ private slots: void extraMimetypesAppendToBuiltins(); void extraMimetypeDescriptionMayContainComma(); void malformedExtraMimetypeIsSkipped(); + void syncChannelDefaultsToTheAccountKey(); + void syncChannelIsActuallyRead(); }; static QString writeIni(const QTemporaryDir &dir, const QString &body) @@ -524,5 +526,36 @@ void TestConfig::malformedExtraMimetypeIsSkipped() QVERIFY(!config.problems().isEmpty()); } +void TestConfig::syncChannelDefaultsToTheAccountKey() +{ + // Most accounts name their mbsync channel exactly as their section key, so + // the common case must need no config edit at all. + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.work]\n" + "maildir = work\n"))); + + QCOMPARE(config.accounts().size(), 1); + QCOMPARE(config.accounts().at(0).syncChannel(), QStringLiteral("work")); +} + +void TestConfig::syncChannelIsActuallyRead() +{ + // The key exists because the two names genuinely diverge: a QSettings + // section key may carry dots that the mbsync channel does not, and passing + // the section key to mbsync would name a channel that does not exist. + QTemporaryDir dir; + Config config; + config.load(writeIni(dir, QStringLiteral( + "[account.mail-first.last]\n" + "maildir = mail-first.last\n" + "channel = mail-firstlast\n"))); + + QCOMPARE(config.accounts().size(), 1); + QCOMPARE(config.accounts().at(0).syncChannel(), + QStringLiteral("mail-firstlast")); +} + QTEST_MAIN(TestConfig) #include "test_config.moc" -- cgit v1.2.3