💾 Archived View for idiomdrottning.org › nmatom.scm.txt captured on 2024-08-18 at 17:54:48.
⬅️ Previous capture (2023-12-28)
-=-=-=-=-=-=-
(import shell sxml-serializer (chicken irregex) (chicken port) (chicken string) srfi-1 srfi-13 srfi-42) (define terms 'tag:feed) (define-syntax nm (syntax-rules () ((notmuch command args ...) (with-input-from-string (capture (notmuch command --format=sexp args ...)) read)))) (define nm-sexp (list-ec (: result (nm search --limit=15 ,terms)) (flatten (nm show --include-html ,(string-append "thread:" (second result)))))) (define (grab tag distance e) (distance (find-tail (cut equal? tag <>) e))) (define (entry-date e) (string-chomp (capture (date -Iseconds -d ,(string-append "@" (number->string (grab ':timestamp second e))))))) (define (get-content e) (cond ((member "text/html" e) `(content (@ (type html)) ,(grab "text/html" third e))) ((member "text/plain" e) `(content (@ (type text)) ,(grab "text/plain" third e))) (else '(content (@ (type text)) "Email had no easy content-type")))) (serialize-sxml `(feed (@ (xmlns "http://www.w3.org/2005/Atom")) (title |Notmuch | ,terms) (id e0db61b1-9250-4cdc-bfca-de0eb2c3c42a) (updated ,(entry-date (first nm-sexp))) ,@(list-ec (: e nm-sexp) `(entry (title ,(grab ':Subject second e)) (id ,(grab ':id second e)) (link ,(string-append "mid:" (grab ':id second e))) (updated ,(entry-date e)) ,(get-content e) ,(let ((s (grab ':From second e))) `(author (name ,(irregex-replace " <.*>$" s)) (email ,(irregex-replace "[^<]*<([^>]*)>$" s 1))))))) output: "/tmp/nmfeed.xml")