Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 17B4F431FB6 for ; Fri, 18 Jul 2014 12:41:00 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oEPvXTcHBXEw for ; Fri, 18 Jul 2014 12:40:52 -0700 (PDT) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C7FD7431FAE for ; Fri, 18 Jul 2014 12:40:52 -0700 (PDT) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1X8E1Q-0001lg-8G; Fri, 18 Jul 2014 16:40:48 -0300 Received: (nullmailer pid 32294 invoked by uid 1000); Fri, 18 Jul 2014 19:40:44 -0000 From: David Bremner To: Alan Schmitt , notmuch Subject: Re: using notmuch programmatically from emacs In-Reply-To: References: User-Agent: Notmuch/0.18.1+6~g1ba7098 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Fri, 18 Jul 2014 16:40:44 -0300 Message-ID: <871ttisber.fsf@tethera.net> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2014 19:41:00 -0000 Alan Schmitt 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