[mu4e] Auto-include context maildir when searching

13 views
Skip to first unread message

Julin S

unread,
May 30, 2026, 9:50:42 AM (2 days ago) May 30
to mu-discuss
When searching from within mu4e by pressing `s` in the headers view
is it possible to automatically include something like
`maildir:ctxt-name` in the search query?

Currently I have multiple contexts each associated with different mail
account.
But when I search for a query, it includes messages from other contexts
as well since the `maildir:` is not included.

It's a bother to type that part each time, so I was wondering if there's
something to help with that.

Is there anything like that?

Thanks.

Dirk-Jan C. Binnema

unread,
May 31, 2026, 5:11:44 AM (yesterday) May 31
to mu-di...@googlegroups.com
I'd probably just create some context-specific bookmarks or maildir
shortcuts, but there's also `mu4e-query-rewrite-function', which you can
set to some function to rewrite a query, e.g. you set it to something
like

Perhaps something like (untested!):
--8<---------------cut here---------------start------------->8---
(defun my-rewrite-func (expr)
(if-let* ((ctx-prefix
(pcase (mu4e-context-name (mu4e-context-current))
("context1" "maildir:/foo")
("context2" "maildir:/bar")
(_ nil))))
(format "%s AND (%s)" ctx-prefix expr)
expr))
--8<---------------cut here---------------end--------------->8---

Kind regards,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
gpg: 6987 9CED 1745 9375 0F14 DA98 11DD FEA9 DCC4 A036

Julin Shaji

unread,
2:03 AM (15 hours ago) 2:03 AM
to mu-di...@googlegroups.com

> I'd probably just create some context-specific bookmarks or maildir
> shortcuts, but there's also `mu4e-query-rewrite-function', which you can

Thanks. I adapted your function to suit my need.

Also, had not been using bookmarks and shortcuts.
Those seem to be sufficient too.

Cheers!
Reply all
Reply to author
Forward
0 new messages