mu-query - Man Page

a language for finding messages in mu databases.


The mu query language is a language used by mu find and mu4e to find messages in mu's Xapian databases. The language is quite similar to Xapian's default query-parser, but is an independent implementation that is customized for the mu/mu4e use-case.

In this article, we give a structured but informal overview of the query language and provide examples.

As a companion to this, we recommend the mu fields and mu flags commands to get an up-to-date list of the available fields and flags.

NOTE: if you use queries on the command-line (say, for mu find), you need to quote any characters that would otherwise be interpreted by the shell, such as "", ( and ) and whitespace.


The basic building blocks of a query are terms; these are just normal words like to just that field. See mu find for all the available fields.

Some example queries:


Terms without an explicit field-prefix, (like 'vacation' above) are interpreted like:

to:vacation or subject:vacation or body:vacation or ...

The language is case-insensitive for terms and attempts to 'flatten' any diacritics, so angtrom matches Ångström.

If terms contain whitespace, they need to be quoted:

subject:"hi there"

This is a so-called phrase query, which means that we match against subjects that contain the literal phrase "hi there".

Remember that you need to escape those quotes when using this from the command-line:

mu find subject:\"hi there\"

Logical Operators

We can combine terms with logical operators -- binary ones: and, or, xor and the unary not, with the conventional rules for precedence and association, and are case-insensitive.

You can also group things with ( and ), so you can do things like:

(subject:beethoven or subject:bach) and not body:elvis

If you do not explicitly specify an operator between terms, and is implied, so the queries

subject:chip subject:dale
subject:chip AND subject:dale

are equivalent. For readability, we recommend the second version.

Note that a pure not - e.g. searching for not apples is quite a 'heavy' query.

Regular Expressions and Wildcards

The language supports matching basic PCRE regular expressions, see pcre(3).

Regular expressions are enclosed in //. Some examples:

subject:/h.llo/		# match hallo, hello, ...

Note 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' etc.

Wildcards are an older mechanism for matching where a term with a rightmost * (and only in that position) matches any term that starts with the part before the *; they are supported for backward compatibility and mu translates them to regular expressions internally:


is equivalent to


As a note of caution, certain wild-cards and regular expression can take quite a bit longer than 'normal' queries.


We already saw a number of search fields, such as subject: and body:. For the full table, see mu-fields(1).

bcc,h           Bcc (blind-carbon-copy) recipient(s)
body,b          Message body
cc,c            Cc (carbon-copy) recipient(s)
changed,k       Last change to message file (range)
date,d          Send date (range)
embed,e         Search inside embedded text parts
file,j          Attachment filename
flag,g          Message Flags
from,f          Message sender
list,v          Mailing list (e.g. the List-Id value)
maildir,m       Maildir
mime,y          MIME-type of one or more message parts
msgid,i         Message-ID
prio,p          Message priority (=low=, =normal= or =high=)
size,z          Message size range
subject,s       Message subject
tag,x           Tags for the message
thread,w        Thread a message belongs to
to,t            To: recipient(s)

The shortcut character can be used instead of the full name:


is the same as


For queries that are not one-off, we would recommend the longer name for readability.

There are also the special fields contact:, which matches all contact-fields (from, to, cc and bcc), and recip, which matches all recipient-fields (to, cc and bcc). Hence, for instance,

is equivalent to

( or or or

Date Ranges

The date: field takes a date-range, expressed as the lower and upper bound, separated by ... Either lower or upper (but not both) can be omitted to create an open range.

Dates are expressed in local time and using ISO-8601 format (YYYY-MM-DD HH:MM:SS); you can leave out the right part, and mu adds the rest, depending on whether this is the beginning or end of the range (e.g., as a lower bound, end of the year).

You can use '/' , '.', '-' and 'T' to make dates more human readable.

Some examples:


You can also use the special 'dates' now and today:

Finally, you can use relative 'ago' times which express some time before now and consist of a number followed by a unit, with units s for seconds, M for minutes, h for hours, d for days, w for week, m for months and y for years. Some examples:


Size Ranges

The size or z field allows you to match size ranges -- that is, match messages that have a byte-size within a certain range. Units (b (for bytes), K (for 1000 bytes) and M (for 1000 * 1000 bytes) are supported). Some examples:


Flag Field

The flag/g field allows you to match message flags. The following fields are available:

a,attach        Message with attachment
d,draft         Draft Message
f,flagged       Flagged
l,list          Mailing-list message
n,new           New message (in new/ Maildir)
p,passed        Passed ('Handled')
r,replied       Replied
s,seen          Seen
t,trashed       Marked for deletion
u,unread        new OR NOT seen
x,encrypted     Encrypted message
z,signed        Signed message

Some examples:


Encrypted messages may be signed as well, but this is only visible after decrypting and thus invisible to mu.

Priority Field

The message priority field (prio:) has three possible values: low, normal or high. For instance, to match high-priority messages:



The Maildir field describes the directory path starting after the Maildir-base path, 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 the same maildir) with:


Note the starting ''. If you want to match mails in the 'root' maildir, you can do with a single '':


If you have maildirs (or any fields) that include spaces, you need to quote them, ie.

maildir:"/Sent Items"

Note that from the command-line, such queries must be quoted:

mu find 'maildir:"/Sent Items"'

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.

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:


Find all messages with attached images:



With current Xapian versions, the apostroph character is considered part of a word. Thus, you cannot find D'Artagnan by searching for Artagnan. So, include the apostroph in search or use a regexp search.

Matching on spaces has changed compared to the old query-parser; this applies e.g. to Maildirs that have spaces in their name, such as Sent Items. See Maildir above.

Reporting Bugs

Please report bugs at


Dirk-Jan C. Binnema <>

See Also

mu-find(1), mu-fields(1), *pcre(3)

Referenced By

mu(1), mu-find(1).