summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-02-13 22:48:03 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-02-13 22:48:03 +0200
commit7baf1bf5e56f5f6e45f080021f4ade4f30e623ff (patch)
tree0fa880209add9205e1bb9904602ecfa327ababef /lib
parentcd3cb648930bf23592a206cd44532d6623cb3ccd (diff)
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/message/mu-mime-object.cc9
-rw-r--r--lib/tests/test-mu-store-query.cc53
2 files changed, 59 insertions, 3 deletions
diff --git a/lib/message/mu-mime-object.cc b/lib/message/mu-mime-object.cc
index a75da5b..37b9020 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 <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
** 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 c79c43f..0baa799 100644
--- a/lib/tests/test-mu-store-query.cc
+++ b/lib/tests/test-mu-store-query.cc
@@ -920,6 +920,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
test_html()
{
// test message sent to self, and copy of received msg.
@@ -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",