From 7baf1bf5e56f5f6e45f080021f4ade4f30e623ff Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 13 Feb 2025 22:48:03 +0200 Subject: [PATCH] mu: remove empty refs + unit-test Some message can have an _empty_ message-id, e.g. with: In-Reply-To: <> which we weren't filter out. This would yield and _empty_ Thread-Id, in mu-message.cc And this would make mu-query believe it had no matches in the first query, in Query::Private::run_related, and effectively throw away the results. (Xapian using empty string both for a "not found" result, and "found an empty string doesn't help either). So, avoid having an empty reference. Also add a unit-test. Fixes #2812. --- lib/message/mu-mime-object.cc | 9 ++++-- lib/tests/test-mu-store-query.cc | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/lib/message/mu-mime-object.cc b/lib/message/mu-mime-object.cc index a75da5be..37b9020c 100644 --- a/lib/message/mu-mime-object.cc +++ b/lib/message/mu-mime-object.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2022-2023 Dirk-Jan C. Binnema +** Copyright (C) 2022-2025 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -426,7 +426,10 @@ MimeMessage::references() const noexcept return seq_some(seq, [&](auto&& str) { return ref == str; }); }; - auto is_fake = [](auto&& msgid) { + auto on_blacklist = [](auto&& msgid) { + // don't include empty message-ids + if (!*msgid) + return true; // this is bit ugly; protonmail injects fake References which // can otherwise screw up threading. if (g_str_has_suffix(msgid, "protonmail.internalid")) @@ -447,7 +450,7 @@ MimeMessage::references() const noexcept for (auto i = 0; i != g_mime_references_length(mime_refs); ++i) { const auto msgid{g_mime_references_get_message_id(mime_refs, i)}; - if (msgid && !is_dup(refs, msgid) && !is_fake(msgid)) + if (msgid && !is_dup(refs, msgid) && !on_blacklist(msgid)) refs.emplace_back(msgid); } g_mime_references_free(mime_refs); diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc index c79c43f1..0baa7992 100644 --- a/lib/tests/test-mu-store-query.cc +++ b/lib/tests/test-mu-store-query.cc @@ -919,6 +919,57 @@ Boo! } +static void +test_related_empty_in_reply_to() +{ + g_test_bug("2812"); + // test message sent to self, and copy of received msg. + + const auto test_msg = R"(From: "Edward Mallory" +To: "Russ Hildebrandt +Subject: New Prospect +Date: Wed, 07 Dec 2022 18:38:06 +0200 +Message-ID: <875ysdfentbhg.fsf@djcbsoftware.nl> +MIME-Version: 1.0 +In-Reply-To: <> +Content-Type: text/plain + +Boo! +)"; + const TestMap test_msgs = { + {"inbox/cur/msg1", test_msg }}; + + TempDir tdir; + auto store{make_test_store(tdir.path(), test_msgs, {})}; + + g_assert_cmpuint(store.size(), ==, 1); + + // normal query should give 1 + { + auto qr = store.run_query("maildir:/inbox", Field::Id::Date, + QueryFlags::None); + assert_valid_result(qr); + g_assert_cmpuint(qr->size(), ==, 1); + } + + // a related query should also give 1 + { + auto qr = store.run_query("maildir:/inbox", Field::Id::Date, + QueryFlags::IncludeRelated); + assert_valid_result(qr); + g_assert_cmpuint(qr->size(), ==, 1); + } + + // a related/threading query should also give 1 + { + auto qr = store.run_query("maildir:/inbox", Field::Id::Date, + QueryFlags::IncludeRelated | QueryFlags::Threading); + assert_valid_result(qr); + g_assert_cmpuint(qr->size(), ==, 1); + } +} + + static void test_html() { @@ -1056,6 +1107,8 @@ main(int argc, char* argv[]) test_subject_kata_containers); g_test_add_func("/store/query/related-dup-threaded", test_related_dup_threaded); + g_test_add_func("/store/query/related-empty-in-reply-to", + test_related_empty_in_reply_to); g_test_add_func("/store/query/html", test_html); g_test_add_func("/store/query/ngrams",