|
| 1 | +;; |
| 2 | +;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema <[email protected]> |
| 3 | +;; |
| 4 | +;; This program is free software; you can redistribute it and/or modify it |
| 5 | +;; under the terms of the GNU General Public License as published by the |
| 6 | +;; Free Software Foundation; either version 3, or (at your option) any |
| 7 | +;; later version. |
| 8 | +;; |
| 9 | +;; This program is distributed in the hope that it will be useful, |
| 10 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +;; GNU General Public License for more details. |
| 13 | +;; |
| 14 | + |
| 15 | +;; You should have received a copy of the GNU General Public License |
| 16 | +;; along with this program; if not, write to the Free Software Foundation, |
| 17 | +;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + |
| 19 | +(define-module (mu message) |
| 20 | + :use-module (oop goops) |
| 21 | + :use-module (mu) |
| 22 | + :export ( |
| 23 | + <mu-message> |
| 24 | + body |
| 25 | + header |
| 26 | + contacts |
| 27 | + )) |
| 28 | + |
| 29 | +(define-class <mu-message> () |
| 30 | + (msg #:init-keyword #:msg)) ;; the MuMsg-smob we're wrapping |
| 31 | + |
| 32 | +(define-syntax define-getter |
| 33 | + (syntax-rules () |
| 34 | + ((define-getter method-name field) |
| 35 | + (begin |
| 36 | + (define-method (method-name (msg <mu-message>)) |
| 37 | + (mu:msg:field (slot-ref msg 'msg) field)) |
| 38 | + (export method-name))))) |
| 39 | + |
| 40 | +(define-getter bcc mu:bcc) |
| 41 | +(define-getter body-html mu:body-html) |
| 42 | +(define-getter body-txt mu:body-txt) |
| 43 | +(define-getter cc mu:cc) |
| 44 | +(define-getter date mu:date) |
| 45 | +(define-getter flags mu:flags) |
| 46 | +(define-getter from mu:from) |
| 47 | +(define-getter maildir mu:maildir) |
| 48 | +(define-getter message-id mu:message-id) |
| 49 | +(define-getter path mu:path) |
| 50 | +(define-getter priority mu:prio) |
| 51 | +(define-getter references mu:refs) |
| 52 | +(define-getter size mu:size) |
| 53 | +(define-getter subject mu:subject) |
| 54 | +(define-getter tags mu:tags) |
| 55 | +(define-getter to mu:to) |
| 56 | + |
| 57 | +(define-method (body (msg <mu-message>)) |
| 58 | + (or (body-txt msg) (body-html msg))) |
| 59 | + |
| 60 | +(define-method (header (msg <mu-message>) (hdr <string>)) |
| 61 | + "Get an arbitrary header HDR from message MSG." |
| 62 | + (mu:msg:header (slot-ref msg 'msg) hdr)) |
| 63 | + |
| 64 | +(define-method (contacts (msg <mu-message>) contact-type) |
| 65 | + (mu:msg:contacts (slot-ref msg 'msg) contact-type)) |
0 commit comments