From 02a48a7c8ab05ab9444c116d6b0b263e06a866f2 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 1 Jul 2022 23:19:21 -0700 Subject: [PATCH] [notmuch] Automatically create tasks in org-mode for Fido emails --- .../.config/notmuch/default/hooks/post-new | 8 ++++ notmuch/usr/bin/notmuch-collect-tasks | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 notmuch/.config/notmuch/default/hooks/post-new create mode 100755 notmuch/usr/bin/notmuch-collect-tasks diff --git a/notmuch/.config/notmuch/default/hooks/post-new b/notmuch/.config/notmuch/default/hooks/post-new new file mode 100755 index 0000000..28ba263 --- /dev/null +++ b/notmuch/.config/notmuch/default/hooks/post-new @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +# -*- mode: scheme; -*- +IFS=" " +exec scsh -e main -s "$0" "$@" +!# + +(define (main . args) + (run (notmuch-collect-tasks ,(format #f "~a/documents/gtd/inbox.org" (getenv "HOME"))))) diff --git a/notmuch/usr/bin/notmuch-collect-tasks b/notmuch/usr/bin/notmuch-collect-tasks new file mode 100755 index 0000000..4eff658 --- /dev/null +++ b/notmuch/usr/bin/notmuch-collect-tasks @@ -0,0 +1,42 @@ +#!/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"))))