Alan Schmitt <alan.schmitt@polytechnique.org> writes: > Hello, > > I sometimes have to find a message knowing only its message id. I know > how to use a notmuch search in emacs to find the message, then use > another function to display it in gnus, but I would like to do it > directly without going through the *notmuch-search* buffer. > > Right now I'm doing the following: > > #+begin_src emacs-lisp > (defun as/msgid-to-gnus (msgid) > "Search for the MSGID using notmuch, then open the message with > gnus." > (let ((file (shell-command-to-string (concat "notmuch search --output=files 'id:" msgid "'")))) The structured output formats (sexp, json) include file names, so you should be able to use something like the following (defun notmuch-query-get-message-filenames (&rest search-terms) "Return a list of message-ids of messages that match SEARCH-TERMS" (notmuch-query-map-threads (lambda (msg) (plist-get msg :filename)) (notmuch-query-get-threads search-terms))) This is based on the example at the bottom of notmuch-query.el