Hi Jorge,
On Saturday Apr 02 2016, Jorge Araya Navarro wrote:
> Hello!
>
> I would like to query the database for the number of new mails of
> certain senders (i.e.: my clients
> of freelance projects). I know how to forge queries (well, kinda know
> how) and I also know the existence of `mu4e-index-updated-hook`,
> however, I'm not aware of the existence of any elisp function provided
> by mu4e to do queries and return its results.
mu4e needs to call out to the mu server to do queries -- that makes it a
bit tricky to quickly (and somewhat expensive) to a query. Mu4e uses a
few tricks to make things seem smooth. Maybe in the emacs 25.x future
(which supports binary modules) we can improve this.
Even now, of course, nothing is impossible, see below for a quick &
dirty way to do arbitrary queries (note that this still needs some
quoting / error handling, but you get the idea)
--8<---------------cut here---------------start------------->8---
(defun mu-query (expr)
"Run a mu query for EXPR, return result as a lisp object."
(let ((obj) (cur 0)
(sexps (shell-command-to-string
(concat "mu find --format=sexp " expr))))
(while (< cur (- (length sexps) 1))
(let ((parsed (read-from-string sexps cur)))
(push (car parsed) obj)
(setq cur (cdr parsed))))
obj))
--8<---------------cut here---------------end--------------->8---
Kind regards,
Dirk.
--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:
www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C