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 25463431FBD for ; Mon, 21 Jul 2014 13:20:18 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -3.924 X-Spam-Level: X-Spam-Status: No, score=-3.924 tagged_above=-999 required=5 tests=[DATE_IN_PAST_03_06=1.076, RCVD_IN_DNSWL_HI=-5] 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 7Fp9+Uu5dQEP for ; Mon, 21 Jul 2014 13:20:12 -0700 (PDT) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 0796B431FAE for ; Mon, 21 Jul 2014 13:20:11 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.01,703,1400018400"; d="scan'208";a="86357625" Received: from cbg35-2-78-242-14-140.fbx.proxad.net (HELO top.local) ([78.242.14.140]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA; 21 Jul 2014 22:20:08 +0200 From: Alan Schmitt To: David Bremner Subject: Re: using notmuch programmatically from emacs In-Reply-To: <871ttisber.fsf@tethera.net> (David Bremner's message of "Fri, 18 Jul 2014 16:40:44 -0300") Date: Mon, 21 Jul 2014 17:10:42 +0200 Message-ID: References: <871ttisber.fsf@tethera.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Cc: notmuch 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: Mon, 21 Jul 2014 20:20:18 -0000 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 2014-07-18 21:40, David Bremner writes: > 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 --outpu= t=3Dfiles '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 Thanks a lot, this put me on the right track. I had to slightly modify your example as it returns every message in the thread (and not just the matching one). So I first test for id, and the filter the list to return only the matching message. Here is the code I wrote. #+begin_src emacs-lisp (defun notmuch-query-get-message-filenames (msgid) "Return the message filename where the message id matches MSGID and `nil' if no such message is found" (car (remove nil (notmuch-query-map-threads (lambda (msg) (if (equal (plist-get msg :id) msgid) (plist-get msg :filename) nil)) (notmuch-query-get-threads (list (concat "id:" msgid)))))= )) #+end_src Thanks again, Alan =2D-=20 OpenPGP Key ID : 040D0A3B4ED2E5C7 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iQEcBAEBCgAGBQJTzS12AAoJEAQNCjtO0uXHVcYIAIlMX56IQa/zhCLZVeAbBeDl yKwFFtHuzWAJtKI4++0X6fwKx1m7BuXhLyr2eXDAUOkNH5Rh4bvpYafVK3iHJFvE TF+elmRI9wdVmDTBNYeYqN4q+34ymXo3zA63KCrB0xAFAjPB8UMdTq2bnYZgLY/s jBSViMsIk8da18KYVn4n8rBAOTj8zujQod8P/MJwKopvQCqyaO5LWXJGr/ByFxvP Xpf0b7JRLE+iqvJi6vr7n2XKGSGJZ4nCj7Ulm3BRri7fk93FcPa8GUxFbl0vvsXQ jX/M+rNA3QsIRWnuEM04yyRfgfjyVP4doPtbedrCU6Jvpa/PxHdi7wWks8GfjO8= =QZ0x -----END PGP SIGNATURE----- --=-=-=--