query: add related: combi-field + test

Add a new combination (pseudo) field "related:", which combines
"message-id" and "references"
This commit is contained in:
Dirk-Jan C. Binnema
2024-12-02 21:41:59 +02:00
parent 05be072676
commit 8fefc52eee
4 changed files with 47 additions and 14 deletions

View File

@ -38,6 +38,10 @@ Mu::combi_fields()
field_from_id(Field::Id::Cc),
field_from_id(Field::Id::Bcc),
field_from_id(Field::Id::From)}},
CombiField { "related",
{ field_from_id(Field::Id::MessageId),
field_from_id(Field::Id::References)}
},
CombiField { "",
{ field_from_id(Field::Id::To),
field_from_id(Field::Id::Cc),

View File

@ -217,10 +217,6 @@ Boo!
}
}
static void
test_related()
{
@ -262,7 +258,6 @@ Child
TempDir tdir;
auto store{make_test_store(tdir.path(), test_msgs, {})};
{
// direct matches
auto qr = store.run_query("msgid:aap@foo.bar", Field::Id::Date,
QueryFlags::None);
g_assert_true(!!qr);
@ -271,7 +266,6 @@ Child
}
{
// skip duplicate messages; which one is skipped is arbitrary.
auto qr = store.run_query("msgid:aap@foo.bar", Field::Id::Date,
QueryFlags::IncludeRelated);
g_assert_true(!!qr);
@ -280,7 +274,6 @@ Child
}
{
// skip duplicate messages; which one is skipped is arbitrary.
auto qr = store.run_query("msgid:mies@foo.bar", Field::Id::Date,
QueryFlags::IncludeRelated);
g_assert_true(!!qr);
@ -289,7 +282,6 @@ Child
}
{
// skip duplicate messages; which one is skipped is arbitrary.
auto qr = store.run_query("ref:aap@foo.bar", Field::Id::Date,
QueryFlags::None);
g_assert_true(!!qr);
@ -297,9 +289,15 @@ Child
g_assert_cmpuint(qr->size(), ==, 2);
}
{
auto qr = store.run_query("related:aap@foo.bar", Field::Id::Date,
QueryFlags::None);
g_assert_true(!!qr);
g_assert_false(qr->empty());
g_assert_cmpuint(qr->size(), ==, 3);
}
}
static void
test_dups_related()
{

View File

@ -183,6 +183,8 @@ fields at once:
+-------------+-----------------------------------------+
| contact | to, cc, bcc, from |
+-------------+-----------------------------------------+
| related | message-id, references |
+-------------+-----------------------------------------+
| <empty> | to, cc, bcc, from, subject, body, embed |
+-------------+-----------------------------------------+
#+end_example

View File

@ -352,10 +352,38 @@ either `future' or `past'."
(read-string prompt initial-input 'mu4e--search-hist)))
(defconst mu4e--search-query-keywords
'("and" "or" "not"
"from:" "to:" "cc:" "bcc:" "contact:" "recip:" "date:" "subject:" "body:"
"list:" "maildir:" "flag:" "mime:" "file:" "prio:" "tag:" "msgid:"
"size:" "embed:"))
'(;; logical
"and"
"or"
"not"
;; fields
"bcc:"
"body:"
"cc:"
"changed:"
"date:"
"embed:"
"file:"
"flag:"
"from:"
"lang:"
"maildir:"
"list:"
"msgid"
"mime:"
"path:"
"prio:"
"ref"
"size:"
"subject:"
"tags:"
"thread:"
"to:"
;; combin fields
"recip:"
"contact:"
"related:")
"Mu4e query-keywords for completion.")
(defun mu4e--search-completion-contacts-action (match _status)
"Delete contact alias from contact autocompletion, leaving just email address.
@ -378,7 +406,8 @@ status, STATUS."
(list (match-beginning 1)
(match-end 1)
'("attach" "draft" "flagged" "list" "new" "passed" "replied"
"seen" "trashed" "unread" "encrypted" "signed" "personal")))
"seen" "trashed" "unread" "encrypted" "signed" "personal"
"calendar")))
((looking-back "maildir:\\([a-zA-Z0-9/.]*\\)" nil)
(list (match-beginning 1)
(match-end 1)