diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2017-11-15 22:24:59 +0100 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2017-11-15 22:24:59 +0100 |
commit | b44fbf62575ccc6d8955d558dadb3889b3e33164 (patch) | |
tree | 435466e331a3cf4c8d0aee7d0f8281e118d8b37b | |
parent | 7111edab4f2f5bf8860f3a640021c94607516749 (diff) |
debbugs: Parse emails.
* debbugs/email.scm: New file.
* Makefile.am (SOURCES): Add it.
* debbugs/operations.scm (get-bug-log): Use it.
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | debbugs/email.scm | 63 | ||||
-rw-r--r-- | debbugs/operations.scm | 4 |
3 files changed, 68 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index 3731f6c..7f0cede 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,10 +21,11 @@ godir=$(libdir)/guile/@GUILE_EFFECTIVE_VERSION@/ccache SOURCES = \ debbugs/base64.scm \ + debbugs/bug.scm \ debbugs/config.scm \ + debbugs/email.scm \ debbugs/operations.scm \ - debbugs/soap.scm \ - debbugs/bug.scm + debbugs/soap.scm TEST_EXTENSIONS = .scm diff --git a/debbugs/email.scm b/debbugs/email.scm new file mode 100644 index 0000000..3cc605f --- /dev/null +++ b/debbugs/email.scm @@ -0,0 +1,63 @@ +;;; Guile-Debbugs --- Guile bindings for Debbugs +;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> +;;; +;;; This file is part of Guile-Debbugs. +;;; +;;; Guile-Debbugs is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; Guile-Debbugs is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Guile-Debbugs. If not, see <http://www.gnu.org/licenses/>. + +(define-module (debbugs email) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) + #:use-module (srfi srfi-9 gnu) + #:use-module (srfi srfi-19) + #:use-module (ice-9 match) + #:use-module (debbugs soap) + #:export (email + email? + email-header + email-body + email-msg-num + email-attachments + + soap-email->email)) + +(define-record-type <email> + (make-email header body msg-num attachments) + email? + (header email-header) + (body email-body) + (msg-num email-msg-num) + (attachments email-attachments)) + +(set-record-type-printer! <email> + (lambda (record port) + (simple-format port "#<email ~s ~a>" + (email-msg-num record) + (number->string (object-address record) 16)))) + +(define (parse-header header-text) + "Parse the email headers and return them as an alist." + ;; TODO + header-text) + +(define* (email #:key header body msg-num (attachments '())) + (make-email (parse-header header) body msg-num attachments)) + +(define (soap-email->email email-item) + (let ((email-properties (map soap->scheme (cdr email-item)))) + (apply email + (append-map (match-lambda + ((key . value) + (list (symbol->keyword key) value))) + email-properties)))) diff --git a/debbugs/operations.scm b/debbugs/operations.scm index a97fca0..c76660d 100644 --- a/debbugs/operations.scm +++ b/debbugs/operations.scm @@ -19,6 +19,7 @@ (define-module (debbugs operations) #:use-module (debbugs soap) #:use-module (debbugs bug) + #:use-module (debbugs email) #:use-module (sxml xpath) #:use-module (sxml match) #:use-module (srfi srfi-1) @@ -87,8 +88,7 @@ Boolean value)." (let ((emails ((sxpath '(// urn:Debbugs/SOAP:get_bug_logResponse http://schemas.xmlsoap.org/soap/encoding/:Array urn:Debbugs/SOAP:item)) response-body))) - ;; TODO: parse into record - emails)))) + (map soap-email->email emails))))) (define-public (get-usertag email) "Return an association list of tag names to lists of bug numbers for |