Previous: Utility procedures, Up: Contacts   [Contents]


4.4 Example - mutt export

Let’s see how we could export the addresses in the mu database to the addressbook format of the venerable mutt6 e-mail client.

The addressbook format that mutt uses is a sequence of lines that look something like:

alias <nick> [<name>] "<" <email> ">"

mu guile provides the procedure (mu:contact->string <mu:contact> format) that we can use to do the conversion.

We may want to focus on people with whom we have frequent correspondence; so we may want to limit ourselves to people we have seen at least 10 times in the last year.

It is a bit hard to guess the nick name for e-mail contacts, but mu:contact->string tries something based on the name. You can always adjust them later by hand, obviously.

#!/bin/sh
exec guile -s $0 $ !#

(use-modules (mu))
(mu:initialize)

;; Get a list of contacts that were seen at least 20 times since 2010
(define (selected-contacts)
  (let  ((addrs '())
	  (start (car (mktime (car (strptime "%F" "2010-01-01")))))
	  (minfreq 20))
    (mu:for-each-contact
      (lambda (contact)
	(if (and (mu:email contact)
	      (>= (mu:frequency contact) minfreq)
	      (>= (mu:last-seen contact) start))
	  (set! addrs (cons contact addrs)))))
      addrs))

(for-each
  (lambda (contact)
    (format #t "~a\n" (mu:contact->string contact "mutt-alias")))
  (selected-contacts))

This simple program could be improved in many ways; this is left as an excercise to the reader.


Footnotes

(6)

http://www.mutt.org/