Re: using notmuch programmatically from emacs

2014-07-21 Thread Alan Schmitt
On 2014-07-18 21:40, David Bremner da...@tethera.net writes:

 Alan Schmitt alan.schm...@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

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

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7


pgp1Rehx6kQ73.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: using notmuch programmatically from emacs

2014-07-18 Thread David Bremner
Alan Schmitt alan.schm...@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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch