Advertisement
Guest User

mailsync mcron example

a guest
Jun 24th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.32 KB | None | 0 0
  1. (define-module (tdev mcron mailsync)
  2.   #:use-module (guix gexp))
  3.  
  4. (define-public %mailsync-job
  5.   #~(job
  6.      '(next-minute-from (next-minute) (range 0 60 15))
  7.      #$(program-file
  8.         "mailsync-job.scm"
  9.         #~(begin
  10.             (use-modules (ice-9 popen)
  11.                          (ice-9 rdelim)
  12.                          (ice-9 format))
  13.  
  14.             (define (nm-tag terms)
  15.               (system* "notmuch" "tag" (car terms) "--" (cdr terms)))
  16.  
  17.             ;; TODO make tagging recursive.
  18.             (define %mailsync-default-terms
  19.               '(("+inbox" . "path:/.*\\/INBOX/")
  20.                 ("+draft" . "path:/.*\\/Drafts/")
  21.                 ("+sent"  . "path:/.*\\/Sent/")
  22.                 ("+trash" . "path:/.*\\/Trash/")
  23.                 ("+spam"  . "path:/.*\\/Spam/")
  24.  
  25.                 ;; Flat todos
  26.                 ("+todo"  . "tag:inbox and tag:sent")
  27.                 ("-inbox" . "tag:inbox and tag:sent")
  28.                 ("-sent"  . "tag:inbox and tag:sent")
  29.  
  30.                 ;; Remove tags for moved messages
  31.                 ("-inbox" . "not path:/.*\\/INBOX/")
  32.                 ("-trash" . "not path:/.*\\/Trash/")
  33.                 ("-spam"  . "not path:/.*\\/Spam/")
  34.                 ("+work"  . "to:EML")
  35.                 ("+work"  . "to:EML")
  36.                 ("+work"  . "from:EML")
  37.                 ("+work"  . "from:EML")))
  38.  
  39.             (define (mailsync-update tags)
  40.               (system* "mbsync" "-a")
  41.               (nm-tag '("-new" . "tag:new"))
  42.               (system* "notmuch" "new")
  43.               (map nm-tag tags))
  44.  
  45.             (define (mailsync-count-new-messages)
  46.               (let* ((port (open-input-pipe "notmuch count tag:new"))
  47.                      (newcount (read-line port)))
  48.                 (close-pipe port)
  49.                 (string->number newcount)))
  50.  
  51.             (define (mailsync-notify count)
  52.               (cond ((> count 0)
  53.                      (system* "notify-send"
  54.                               "-c" "email.arrived"
  55.                               "-t" (number->string (* 1000 60 14))
  56.                               "-i" #$(local-file "../../../assets/envelope.png")
  57.                               (format #f "You have ~d new messages" count)))))
  58.  
  59.             (mailsync-update %mailsync-default-terms)
  60.             (mailsync-notify (mailsync-count-new-messages))))))
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement