MU-QUERY(7)
πΈ NAME πΈ
okay so this is mu-query from the Miscellaneous Information Manual (section 7) β it's the language for finding messages in mu databases. that's it, that's the whole job. π
β¨ DESCRIPTION β¨
so the mu query language is, like, the language that mu find and mu4e speak when they go looking for messages in mu's Xapian database. it's quite similar to Xapian's default query-parser, but plot twist: it's an independent implementation that's been customized for the mu/mu4e use-case. so yeah, cousin energy, not the same person. π¦
down here we're gonna give you a structured but informal overview of the query language plus examples. and as a little companion to this, we highly recommend running the mu info fields command to get an up-to-date list of the available fields and flags. it's giving "always current", and we love that. β¨
also!! mu find has the --analyze option, which shows how mu interprets your query β and mu4e has a matching command, mu4e-analyze-last-query. head to the ANALYZING QUERIES section down below for the deets. π
NOTE: if you're using queries on the command-line (say, formu find), you need to quote any characters that would otherwise get interpreted by the shell, like",*,(, and). the details are shell-specific bestie, so it depends. and if you're in doubt? the--analyzeoption is right there for you. π«Ά
π TERMS π
the basic building blocks of a query are terms. terms are just normal words like "banana" or "hello"β¦ or words with a field-name prefixed onto them, which makes them apply to just that one field. run mu info fields to see all the available fields, no cap. π
some example queries:
vacation
subject:capybara
maildir:/inbox
terms without an explicit field-prefix (like vacation up there) get interpreted as:
to:vacation or subject:vacation or body:vacation or ...
the language is case-insensitive for terms, and it also tries to "flatten" diacritics β so angtrom matches Γ
ngstrΓΆm. iconic behavior honestly. β¨
if a term has whitespace in it, it needs to be quoted:
subject:"hi there"
that's a so-called phrase query, which means we match against subjects that contain the literal phrase "hi there". phrase queries only work for certain fields β you can spot them because they have the word phrase in their mu info fields search column. π
π Quoting queries for the shell π
remember: you need to escape the quotes on a search query when you're using this from the command-line, or else the shell (or most shells) will process the queries first and mu will never even see them. π
in this case, that means the difference between searching for a subject "hi there" versus a subject "hi" plus some word "there" that can show up in any of the combination fields for <empty> β and yes, combination fields get discussed further down, hang tight. π¦
we can use the --analyze option we mentioned to show the difference:
mu find subject:"hi there" --analyze
query:
subject:hi there
parsed query:
(and (subject "hi") (_ "there"))
parsed query (expanded):
(and (subject "hi") (or (to "there") (cc "there") (bcc "there") (from "there") (subject "there") (body "there") (embed "there")))
Xapian query:
Query((Shi AND (Tthere OR Cthere OR Hthere OR Fthere OR Sthere OR Bthere OR Ethere)))
and with the quotes escaped:
mu find subject:$
query:
subject:"hi there"
parsed query:
(or (subject "hi there") (subject (phrase "hi there")))
Xapian query:
Query((Shi there OR (Shi PHRASE 2 Sthere)))
we won't dwell on the details of the --analyze output here, but hopefully this shows off the difference between quoted and unquoted queries. π«Ά
π₯ LOGICAL OPERATORS π₯
we can combine terms with logical operators β the binary ones: and, or, xor, plus the unary not, all following the conventional rules for precedence and association. and yes, the operators are case-insensitive. β
you can also group things with ( and ) so you can write:
(subject:beethoven or subject:bach) and not body:elvis
and if you don't explicitly put an operator between terms, and is implied β so these two queries are literally equivalent:
subject:chip subject:dale
subject:chip AND subject:dale
for readability, we recommend the second version. bestie, please, your future self will thank you. π
note that a purenotβ like searching fornot applesβ is quite a "heavy" query. π
π¦ WILDCARDS π¦
wildcards are a Xapian built-in mechanism for matching. love that for them. β¨
a search term with a rightmost * (and only in that position) matches any term that starts with the part before the *. they're less powerful than regular expressions, but also much faster:
an example:
$ mu find "hello*"
quoting the"hello*"is recommended β some shells (but not all) would otherwise expand the*to all the files in the current directory. π
π REGULAR EXPRESSIONS π
the query language supports matching basic PCRE regular expressions, as per pcre(3), with some limitations. we're fancy like that. π
regular expressions are enclosed in //. for example:
subject:/h.llo/ # matches hallo, hello, ...
now, notice the difference between "maildir:/foo" and "maildir:/foo/" β the former matches messages in the "/foo" maildir, while the latter matches all messages in all maildirs that match "foo", such as "/foo", "/bar/cuux/foo", "/fooishbar", and so on. tiny slash, big difference. π
regular expressions are more powerful than wildcards, but they're also much slower. and moreover, their behavior in mu can be a bit confusing, thanks to some implementation details. see below for some of the caveats. π
πΈ Whitespace in regular expression literals πΈ
to avoid ambiguities in the query parsing, regular expressions must not contain whitespace. so to search for a message with subject "hello world", you can write:
mu find 'subject:/hello\\040world/'
(with the \040 specifying a space in the regular expression, and an extra \ to escape it). in many cases though:
mu find 'subject:/hello.world/'
may be good enough, and easier to type. we love a low-effort slay. π«Ά
β Anchors in regular expressions β
since the underlying Xapian database doesn't support regular expressions (it does support wildcards), mu implements regular expression search by matching your regular expression against all the "terms" (words or phrases) that exist in the database for a given field. that's the whole trick. π
and that implementation detail is exactly why "anchored" regular expressions β the ones with ^ and $ marking begin/end, respectively β can get unexpected results. π
suppose you want to match all messages that start with "pie", and you search with subject:/^pie/. this also matches messages with subject "apple pie" β since both of those words are indexed as terms separately (as well as phrases), and thus "^pie" matches as well for a message with subject "apple pie". not the vibe you asked for, but it's the vibe you got. π
π FIELDS π
okay bestie so we already bumped into a bunch of search fields earlier β subject: and body: said hi π β but this is the FULL roster. every single one. and if you want the whole table with every detail, including the single-char shortcuts, just run:
mu info fields
Here's every field, with its alias, its short form, what flavour of search it does, whether it carries a value, whether it plays nice with sexps, a lil example query, and what it actually means:
bccβ alias: none Β· short:hΒ· search: phrase Β· value: yes Β· sexp: yes β e.g.bcc:foo@example.comβ Blind carbon-copy recipient πbodyβ alias: none Β· short:bΒ· search: phrase Β· value: no Β· sexp: no β e.g.body:capybaraβ Message plain-text bodyccβ alias: none Β· short:cΒ· search: phrase Β· value: yes Β· sexp: yes β e.g.cc:quinn@example.comβ Carbon-copy recipientchangedβ alias: none Β· short:kΒ· search: range Β· value: yes Β· sexp: yes β e.g.changed:30M..β Last change time β°dateβ alias: none Β· short:dΒ· search: range Β· value: yes Β· sexp: yes β e.g.date:20220101..20220505β Message dateembedβ alias: none Β· short:eΒ· search: phrase Β· value: no Β· sexp: no β e.g.embed:war OR embed:peaceβ Embedded textfileβ alias: none Β· short:jΒ· search: boolean Β· value: no Β· sexp: no β e.g.file:/image\.*.jpg/β Attachment file nameflagsβ alias:flagΒ· short:gΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.flag:unread AND flag:personalβ Message propertiesfromβ alias: none Β· short:fΒ· search: phrase Β· value: yes Β· sexp: yes β e.g.from:jimboβ Message senderlanguageβ alias:langΒ· short:aΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.lang:nlβ ISO 639-1 language code for bodymaildirβ alias: none Β· short:mΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.maildir:/private/archiveβ Maildir path for messagelistβ alias: none Β· short:vΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.list:mu-discuss.example.comβ Mailing list (List-Id:)message-idβ alias:msgidΒ· short:iΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.msgid:abc@123β Message-Idmimeβ alias:mime-typeΒ· short:yΒ· search: boolean Β· value: no Β· sexp: no β e.g.mime:image/jpegβ Attachment MIME-typepathβ alias: none Β· short:lΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.path:/a/b/Maildir/cur/msg:2,Sβ File system path to messagepriorityβ alias:prioΒ· short:pΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.prio:highβ Priorityreferencesβ alias:refΒ· short:rΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.ref:E1rQJDx123@example.comβ References to related messagessizeβ alias: none Β· short:zΒ· search: range Β· value: yes Β· sexp: yes β e.g.size:1M..5Mβ Message size in bytessubjectβ alias: none Β· short:sΒ· search: phrase Β· value: yes Β· sexp: yes β e.g.subject:wombatβ Message subjecttagsβ alias:tagΒ· short:xΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.tag:projectxβ Message tagsthreadβ alias: none Β· short:wΒ· search: boolean Β· value: yes Β· sexp: no β e.g.thread:abcde789@example.comβ Thread a message belongs totoβ alias: none Β· short:tΒ· search: phrase Β· value: yes Β· sexp: yes β e.g.to:flimflam@example.comβ Message recipientlabelsβ alias:labelΒ· short:qΒ· search: boolean Β· value: yes Β· sexp: yes β e.g.label:projectxβ Message label(s)
π¦ combination fields π¦
There are also combi-fields β little squad leaders that let you search a bunch of related fields all at once, no cap:
recipβ coversto,cc,bcccontactβ coversto,cc,bcc,fromrelatedβ coversmessage-id,references<empty>(the bare, no-field-name vibe) β coversto,cc,bcc,from,subject,body,embed
So like, for instance:
contact:fnorb@example.com
is literally equivalent to:
(from:fnorb@example.com or to:fnorb@example.com or
cc:from:fnorb@example.com or bcc:fnorb@example.com)
(paste it exactly like that, bestie, yes even the cc:from: bit β it's giving quirky but it's what it is π
)
π DATE RANGES π
The date: field takes a date-range, written as the lower bound and the upper bound with .. in between, like a lil sandwich π₯ͺ. You can leave out either the lower or the upper (but not both) and boom β open range.
Dates are in local time and use ISO-8601 format (YYYY-MM-DD HH:MM:SS). You're allowed to drop the right-hand part and mu fills in the rest for you, depending on whether it's the beginning or the end of the range β for example, as a lower bound "2015" gets read as the start of that year, and as an upper bound as the end of the year. bestie it knows what you meant β¨
You can also use /, ., -, : and "T" to make dates more human-readable.
Some examples:
date:20170505..20170602
date:2017-05-05..2017-06-02
date:..2017-10-01T12:00
date:2015-06-01..
date:2016..2016
You can also use the special "dates" now and today:
date:20170505..now
date:today..
Finally, there are relative "ago" times β these express some time before now, and they're a number followed by a unit. The units are s for seconds, M for minutes, h for hours, d for days, w for week, m for months and y for years. Some examples:
date:3m..
date:2017.01.01..5w
π SIZE RANGES π
The size or z field lets you match size ranges β that is, match messages that have a byte-size within a certain range. The units are b (for bytes), K (for 1000 bytes) and M (for 1000 * 1000 bytes). Some examples:
size:10k..2m
size:10m..
tiny messages, huge messages, all of them get their moment π
πΈ FLAG FIELD πΈ
okay bestie, the flag/g field is how you match message flags. here's the whole menu:
draftβ shortcutDβ category file β Draft (in progress) πflaggedβ shortcutFβ category file β User-flagged βpassedβ shortcutPβ category file β Forwarded message π¦repliedβ shortcutRβ category file β Replied-to π¬seenβ shortcutSβ category file β Viewed at least once πtrashedβ shortcutTβ category file β Marked for deletion ποΈnewβ shortcutNβ category maildir β New message β¨signedβ shortcutzβ category content β Cryptographically signed πencryptedβ shortcutxβ category content β Encrypted πattachβ shortcutaβ category content β Has at least one attachment πunreadβ shortcutuβ category pseudo β New or not seen message π¬listβ shortcutlβ category content β Mailing list message π§personalβ shortcutqβ category content β Personal message πcalendarβ shortcutcβ category content β Calendar invitation π
some examples:
flag:attach
flag:replied
g:x
encrypted messages may be signed as well, but this is only visible after decrypting and thus invisible to mu. periodt. π
π PRIORITY FIELD π
the message priority field (prio:) has three possible values: low, normal or high. for instance, to match high-priority messages:
prio:high
π¦ MAILDIR π¦
the Maildir field describes the directory path starting after the Maildir root directory, and before the /cur/ or /new/ part. so, for example, if there's a message with the file name ~/Maildir/lists/running/cur/1234.213:2,,, you could find it (and all the other messages in that same maildir) with:
maildir:/lists/running
note the starting /. if you want to match mails in the "root" maildir, you can do with a single /:
maildir:/
if you have maildirs (or any fields) that include spaces, you need to quote them, i.e.,
maildir:"/Sent Items"
and once again, note that when using the command-line, such queries must be quoted:
mu find 'maildir:"/Sent Items"'
also note that you should not end the maildir with a /, or it can be misinterpreted as a regular expression term; see aforementioned.
β¨ MORE EXAMPLES β¨
here are some simple examples of mu queries; you can make many more complicated queries using various logical operators, parentheses and so on, but in the author's experience, it's usually faster to find a message with a simple query just searching for some words. iykyk π
find all messages with both "bee" and "bird" (in any field)
bee AND bird
find all messages with either Frodo or Sam:
Frodo OR Sam
find all messages with the "wombat" as subject, and "capybara" anywhere:
subject:wombat and capybara
find all messages in the "Archive" folder from Fred:
from:fred and maildir:/Archive
find all unread messages with attachments:
flag:attach and flag:unread
find all messages with PDF-attachments:
mime:application/pdf
find all messages with attached images:
mime:image/*
(and beware that on the command-line, you need to put this in quotes or it would expand the *.)
find a messages with the given message-id:
msgid:CAE56pjGU2oNxN-wWku69@mail.gmail.com
find all messages written in Dutch or German with the word "hallo":
hallo and (lang:nl or lang:de)
this is only available if your mu has support for this; see mu info and check for "cld2-support*.
π ANALZYING QUERIES π
despite all the excellent documentation, in some cases it can be non-obvious to understand how mu interprets your query, especially when shell interpretation is involved as well.
for that, you can ask mu to analyze the query -- that is, show how mu interprets the query. we already saw an example of this.
this uses the --analyze option to mu find.
$ mu find subject:wombat AND date:3m.. size:..2000 --analyze
*query:
subject:wombat AND date:3m.. size:..2000
* parsed query:
(and (subject "wombat") (date (range "2023-05-30T06:10:09Z" "")) (size (range "" "2000")))
* Xapian query:
Query((Swombat AND VALUE_GE 4 n64759341 AND VALUE_LE 17 i7d0))
the parsed query is usually the most useful one for understanding how mu interprets your query; it shows the query as mu sees it, in s-expression notation.
in mu4e there is the mu4e-analyze-last-query command, which provides similar information.
π REPORTING BUGS π
please report bugs at https://github.com/djcb/mu/issues.
π AUTHOR π
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
π COPYRIGHT π
this manpage is part of mu 1.14.2.
Copyright Β© 2008-2026 Dirk-Jan C. Binnema. License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
π SEE ALSO π
mu-find(1), mu-info(1), pcre(3)
okay that's the whole mu-query(7) bestie β mu 1.14.2, Β© 2008β2026 Dirk-Jan C. Binnema. slay π β¨
π¦ where this page comes from
- ubuntu stonking: maildir-utils 1.14.2-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms