Next: , Up: Messages   [Contents]


3.1 Finding messages

Now we are ready to retrieve some messages from the system. There are two main procedures to do this:

The first procedure, mu:message-list returns a list of all messages matching <search-expression>; if you leave <search-expression> out, it returns all messages. For example, to get all messages with coffee in the subject line:

scheme@(guile-user)> (mu:message-list "subject:coffee")
$1 = (#<<mu:message> 9040640> #<<mu:message> 9040630>
      #<<mu:message> 9040570>)

Apparently, we have three messages matching subject:coffee, so we get a list of three <mu:message> objects. Let’s just use the mu:subject procedure (’method’) provided by <mu:message> objects to retrieve the subject-field (more about methods in the next section).

For your convenience, guile has saved the result of our last query in a variable called $1, so to get the subject of the first message in the list, we can do:

scheme@(guile-user)> (mu:subject (car $1))
$2 = "Re: best coffee ever!"

The second procedure we mentioned, mu:for-each-message, executes some procedure for each message matched by the search expression (or all messages if the search expression is omitted):

scheme@(guile-user)> (mu:for-each-message
                       (lambda(msg)
                         (display (mu:subject msg))
                         (newline))
                      "subject:coffee")
Re: best coffee ever!
best coffee ever!
Coffee beans
scheme@(guile-user)>

Using mu:message-list and/or mu:for-each-message5 and a couple of <mu:message> methods, together with what Guile/Scheme provides, should allow for many interesting programs.


Footnotes

(5)

Implementation node: mu:message-list is implemented in terms of mu:for-each-message, not the other way around. Due to the way mu works, mu:for-each-message is rather more efficient than a combination of for-each and mu:message-list