42 lines
1.2 KiB
Scheme
Executable file
42 lines
1.2 KiB
Scheme
Executable file
#!/usr/bin/env sh
|
|
# -*- mode: scheme; -*-
|
|
IFS=" "
|
|
exec scsh -e main -s "$0" "$@"
|
|
!#
|
|
|
|
(define message-query
|
|
'(from:fidobill@fidomobile.ca
|
|
and "subject:Your Fido bill is ready"))
|
|
|
|
(define processed-tag-name "processed")
|
|
|
|
(define (message->task message)
|
|
(let ((query (caadr (member ':query message)))
|
|
(subject (cadr (member ':subject message)))
|
|
(date (format-date "~Y-~m-~d ~a ~H:~M" (date))))
|
|
(format #f "* TODO ~a
|
|
:PROPERTIES:
|
|
:CREATED: [~a]
|
|
:END:
|
|
|
|
[[notmuch:~a][~a]]" subject date query subject)))
|
|
|
|
(define (print-task task)
|
|
(format #t "~a~%~%" task))
|
|
|
|
(define (main args)
|
|
(let ((output-file (cadr args))
|
|
(messages (run/sexp
|
|
(notmuch search --format=sexp
|
|
,@message-query
|
|
and not ,(format #f "tag:~a" processed-tag-name)))))
|
|
(with-current-output-port
|
|
(open-output-file output-file (file-options create append))
|
|
(for-each (lambda (message)
|
|
(print-task (message->task message)))
|
|
messages))
|
|
(run (notmuch tag ,(format #f "+~a" processed-tag-name) ,@message-query)
|
|
(> /dev/null))
|
|
(format #t "Created ~a task~a~%"
|
|
(length messages)
|
|
(if (= 1 (length messages)) "" "s"))))
|