Re: using notmuch programmatically from emacs
authorAlan Schmitt <alan.schmitt@polytechnique.org>
Mon, 21 Jul 2014 15:10:42 +0000 (17:10 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:03:49 +0000 (10:03 -0800)
d6/1b2ae8f12db7f6588b10dc2e7af5a03d09de29 [new file with mode: 0644]

diff --git a/d6/1b2ae8f12db7f6588b10dc2e7af5a03d09de29 b/d6/1b2ae8f12db7f6588b10dc2e7af5a03d09de29
new file mode 100644 (file)
index 0000000..f91cdb9
--- /dev/null
@@ -0,0 +1,130 @@
+Return-Path: <alan.schmitt@polytechnique.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 25463431FBD\r
+       for <notmuch@notmuchmail.org>; Mon, 21 Jul 2014 13:20:18 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -3.924\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-3.924 tagged_above=-999 required=5\r
+       tests=[DATE_IN_PAST_03_06=1.076, RCVD_IN_DNSWL_HI=-5]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 7Fp9+Uu5dQEP for <notmuch@notmuchmail.org>;\r
+       Mon, 21 Jul 2014 13:20:12 -0700 (PDT)\r
+Received: from mail2-relais-roc.national.inria.fr\r
+       (mail2-relais-roc.national.inria.fr [192.134.164.83])\r
+       (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 0796B431FAE\r
+       for <notmuch@notmuchmail.org>; Mon, 21 Jul 2014 13:20:11 -0700 (PDT)\r
+X-IronPort-AV: E=Sophos;i="5.01,703,1400018400"; d="scan'208";a="86357625"\r
+Received: from cbg35-2-78-242-14-140.fbx.proxad.net (HELO top.local)\r
+       ([78.242.14.140])\r
+       by mail2-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA;\r
+       21 Jul 2014 22:20:08 +0200\r
+From: Alan Schmitt <alan.schmitt@polytechnique.org>\r
+To: David Bremner <david@tethera.net>\r
+Subject: Re: using notmuch programmatically from emacs\r
+In-Reply-To: <871ttisber.fsf@tethera.net> (David Bremner's message of "Fri, 18\r
+       Jul 2014 16:40:44 -0300")\r
+Date: Mon, 21 Jul 2014 17:10:42 +0200\r
+Message-ID: <m27g36iw7h.fsf@polytechnique.org>\r
+References: <m2r41iyfs4.fsf@polytechnique.org> <871ttisber.fsf@tethera.net>\r
+User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin)\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha512; protocol="application/pgp-signature"\r
+Cc: notmuch <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 21 Jul 2014 20:20:18 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On 2014-07-18 21:40, David Bremner <david@tethera.net> writes:\r
+\r
+> Alan Schmitt <alan.schmitt@polytechnique.org> writes:\r
+>\r
+>> Hello,\r
+>>\r
+>> I sometimes have to find a message knowing only its message id. I know\r
+>> how to use a notmuch search in emacs to find the message, then use\r
+>> another function to display it in gnus, but I would like to do it\r
+>> directly without going through the *notmuch-search* buffer.\r
+>>\r
+>> Right now I'm doing the following:\r
+>>\r
+>> #+begin_src emacs-lisp\r
+>>   (defun as/msgid-to-gnus (msgid)\r
+>>     "Search for the MSGID using notmuch, then open the message with\r
+>>   gnus."\r
+>>     (let ((file (shell-command-to-string (concat "notmuch search --outpu=\r
+t=3Dfiles 'id:" msgid "'"))))\r
+>\r
+> The structured output formats (sexp, json) include file names, so you\r
+> should be able to use something like the following\r
+>\r
+> (defun notmuch-query-get-message-filenames (&rest search-terms)\r
+>   "Return a list of message-ids of messages that match SEARCH-TERMS"\r
+>   (notmuch-query-map-threads\r
+>    (lambda (msg) (plist-get msg :filename))\r
+>    (notmuch-query-get-threads search-terms)))\r
+>\r
+> This is based on the example at the bottom of notmuch-query.el\r
+\r
+Thanks a lot, this put me on the right track. I had to slightly modify\r
+your example as it returns every message in the thread (and not just\r
+the matching one). So I first test for id, and the filter the list to\r
+return only the matching message. Here is the code I wrote.\r
+\r
+#+begin_src emacs-lisp\r
+  (defun notmuch-query-get-message-filenames (msgid)\r
+    "Return the message filename where the message id matches MSGID\r
+  and `nil' if no such message is found"\r
+    (car (remove nil\r
+                 (notmuch-query-map-threads\r
+                  (lambda (msg) (if (equal (plist-get msg :id) msgid)\r
+                                    (plist-get msg :filename)\r
+                                  nil))\r
+                  (notmuch-query-get-threads (list (concat "id:" msgid)))))=\r
+))\r
+#+end_src\r
+\r
+Thanks again,\r
+\r
+Alan\r
+\r
+=2D-=20\r
+OpenPGP Key ID : 040D0A3B4ED2E5C7\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG/MacGPG2 v2.0.22 (Darwin)\r
+\r
+iQEcBAEBCgAGBQJTzS12AAoJEAQNCjtO0uXHVcYIAIlMX56IQa/zhCLZVeAbBeDl\r
+yKwFFtHuzWAJtKI4++0X6fwKx1m7BuXhLyr2eXDAUOkNH5Rh4bvpYafVK3iHJFvE\r
+TF+elmRI9wdVmDTBNYeYqN4q+34ymXo3zA63KCrB0xAFAjPB8UMdTq2bnYZgLY/s\r
+jBSViMsIk8da18KYVn4n8rBAOTj8zujQod8P/MJwKopvQCqyaO5LWXJGr/ByFxvP\r
+Xpf0b7JRLE+iqvJi6vr7n2XKGSGJZ4nCj7Ulm3BRri7fk93FcPa8GUxFbl0vvsXQ\r
+jX/M+rNA3QsIRWnuEM04yyRfgfjyVP4doPtbedrCU6Jvpa/PxHdi7wWks8GfjO8=\r
+=QZ0x\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r