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.
This commit is contained in:
Dirk-Jan C. Binnema
2025-02-13 22:48:03 +02:00
parent cd3cb64893
commit 7baf1bf5e5
2 changed files with 59 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2022-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2022-2025 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify it ** 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 ** 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; }); 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 // this is bit ugly; protonmail injects fake References which
// can otherwise screw up threading. // can otherwise screw up threading.
if (g_str_has_suffix(msgid, "protonmail.internalid")) 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) { for (auto i = 0; i != g_mime_references_length(mime_refs); ++i) {
const auto msgid{g_mime_references_get_message_id(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); refs.emplace_back(msgid);
} }
g_mime_references_free(mime_refs); g_mime_references_free(mime_refs);

View File

@ -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" <ed@leviathan.gb>
To: "Russ Hildebrandt <russ@example.com>
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 static void
test_html() test_html()
{ {
@ -1056,6 +1107,8 @@ main(int argc, char* argv[])
test_subject_kata_containers); test_subject_kata_containers);
g_test_add_func("/store/query/related-dup-threaded", g_test_add_func("/store/query/related-dup-threaded",
test_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", g_test_add_func("/store/query/html",
test_html); test_html);
g_test_add_func("/store/query/ngrams", g_test_add_func("/store/query/ngrams",