Previous: Parts and their methods, Up: Attachments and other parts [Contents]
Let’s look at some small example. Let’s get a list of the biggest attachments in messages about Luxemburg:
#!/bin/sh
exec guile -s $0 $ !#
(use-modules (mu))
(mu:initialize)
(define (all-attachments expr)
"Return a list of (name . size) for all attachments in messages
matching EXPR."
(let ((pairs '()))
(mu:for-each-message
(lambda (msg)
(for-each
(lambda (att) ;; add (filename . size) to the list
(set! pairs (cons (cons (mu:name att) (or (mu:size att) 0)) pairs)))
(mu:attachments msg)))
expr)
pairs))
(for-each
(lambda (att)
(format #t "~a: ~,1fKb\n"
(car att) (exact->inexact (/ (cdr att) 1024))))
(sort (all-attachments "Luxemburg")
(lambda (att1 att2)
(< (cdr att1) (cdr att2)))))
As an exercise for the reader, you might want to re-rewrite the
all-attachments in terms of mu:message-list, which would
probably be a bit more elegant.