Previous: Message methods, Up: Messages [Contents]
Now, let’s write a little example – let’s find out what is the longest subject of any e-mail messages we received in the year 2011. You can try this if you put the following in a separate file, make it executable, and run it like any program.
#!/bin/sh
exec guile -s $0 $ !#
(use-modules (mu))
(use-modules (srfi srfi-1))
(mu:initialize)
;; note: (subject msg) => #f if there is no subject
(define list-of-subjects
(map (lambda (msg)
(or (mu:subject msg) "")) (mu:message-list "date:2011..2011")))
;; see the mu-find manpage for the date syntax
(define longest-subject
(fold (lambda (subj1 subj2)
(if (> (string-length subj1) (string-length subj2))
subj1 subj2))
"" list-of-subjects))
(format #t "Longest subject: ~s\n" longest-subject)
There are many other ways to solve the same problem, for example by using an
iterative approach with mu:for-each-message, but it should show how one
can easily write little programs to answer specific questions about your
e-mail corpus.