If you have queries that you use often, you may want to store them as bookmarks. Bookmark searches are available in the main view (see The main view), header view (see The headers view), and message view (see The message view), using (by default) the key b (M-x mu4e-search-bookmark), or B (M-x mu4e-search-bookmark-edit) which lets you edit the bookmark first.

7.2.1 Setting up bookmarks

mu4e provides a number of default bookmarks. Their definition may be instructive:

(defcustom mu4e-bookmarks
  '(( :name  "Unread messages"
      :query "flag:unread AND NOT flag:trashed"
      :key ?u)
    ( :name "Today's messages"
      :query "date:today..now"
      :key ?t)
    ( :name "Last 7 days"
      :query "date:7d..now"
      :hide-unread t
      :key ?w)
    ( :name "Messages with images"
      :query "mime:image/*"
      :key ?p))
  "List of pre-defined queries that are shown on the main screen.

Each of the list elements is a plist with at least:
:name  - the name of the query
:query - the query expression
:key   - the shortcut key.

Optionally, you add the following:
:hide  - if t, bookmark is hidden from the main-view and speedbar.
:hide-unread - do not show the counts of unread/total number
 of matches for the query. This can be useful if a bookmark uses
 a very slow query. :hide-unread is implied from :hide.
  :type '(repeat (plist))
  :group 'mu4e)

You can replace these or add your own items, by putting in your configuration (~/.emacs) something like:

(add-to-list 'mu4e-bookmarks
  '( :name  "Big messages"
     :query "size:5M..500M"
     :key   ?b))

This prepends your bookmark to the list, and assigns the key b to it. If you want to append your bookmark, you can use t as the third argument to add-to-list.

In the various mu4e views, pressing b lists all the bookmarks defined in the echo area, with the shortcut key highlighted. So, to invoke the bookmark we just defined (to get the list of "Big Messages"), all you need to type is bb.

7.2.2 Lisp expressions or functions as bookmarks

Instead of using strings, it is also possible to use Lisp expressions as bookmarks. Either the expression evaluates to a query string or the expression is a function taking no argument that returns a query string.

For example, to get all the messages that are at most a week old in your inbox:

(add-to-list 'mu4e-bookmarks
  '( :name  "Inbox messages in the last 7 days"
     :query (lambda () (concat "maildir:/inbox AND date:"
            (format-time-string "%Y%m%d"
                (subtract-time (current-time) (days-to-time 7)))))
     :key   ?w) t)

Another example where the user is prompted how many days old messages should be shown:

(defun my/mu4e-bookmark-num-days-old-query (days-old)
  (interactive (list (read-number "Show days old messages: " 7)))
  (let ((start-date (subtract-time (current-time) (days-to-time days-old))))
    (concat "maildir:/inbox AND date:"
            (format-time-string "%Y%m%d" start-date))))

(add-to-list 'mu4e-bookmarks
  `(:name  "Inbox messages in the last 7 days"
    :query ,(lambda () (call-interactively 'my/mu4e-bookmark-num-days-old-query))
    :key  ?o) t)

It is defining a function to make the code more readable.

7.2.3 Editing bookmarks before searching

There is also M-x mu4e-search-bookmark-edit (key B), which lets you edit the bookmarked query before invoking it. This can be useful if you have many similar queries, but need to change some parameter. For example, you could have a bookmark ‘"date:today..now AND "13, which limits any result to today’s messages.



Not a valid search query by itself