Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define-module (tdev mcron mailsync)
- #:use-module (guix gexp))
- (define-public %mailsync-job
- #~(job
- '(next-minute-from (next-minute) (range 0 60 15))
- #$(program-file
- "mailsync-job.scm"
- #~(begin
- (use-modules (ice-9 popen)
- (ice-9 rdelim)
- (ice-9 format))
- (define (nm-tag terms)
- (system* "notmuch" "tag" (car terms) "--" (cdr terms)))
- ;; TODO make tagging recursive.
- (define %mailsync-default-terms
- '(("+inbox" . "path:/.*\\/INBOX/")
- ("+draft" . "path:/.*\\/Drafts/")
- ("+sent" . "path:/.*\\/Sent/")
- ("+trash" . "path:/.*\\/Trash/")
- ("+spam" . "path:/.*\\/Spam/")
- ;; Flat todos
- ("+todo" . "tag:inbox and tag:sent")
- ("-inbox" . "tag:inbox and tag:sent")
- ("-sent" . "tag:inbox and tag:sent")
- ;; Remove tags for moved messages
- ("-inbox" . "not path:/.*\\/INBOX/")
- ("-trash" . "not path:/.*\\/Trash/")
- ("-spam" . "not path:/.*\\/Spam/")
- ("+work" . "to:EML")
- ("+work" . "to:EML")
- ("+work" . "from:EML")
- ("+work" . "from:EML")))
- (define (mailsync-update tags)
- (system* "mbsync" "-a")
- (nm-tag '("-new" . "tag:new"))
- (system* "notmuch" "new")
- (map nm-tag tags))
- (define (mailsync-count-new-messages)
- (let* ((port (open-input-pipe "notmuch count tag:new"))
- (newcount (read-line port)))
- (close-pipe port)
- (string->number newcount)))
- (define (mailsync-notify count)
- (cond ((> count 0)
- (system* "notify-send"
- "-c" "email.arrived"
- "-t" (number->string (* 1000 60 14))
- "-i" #$(local-file "../../../assets/envelope.png")
- (format #f "You have ~d new messages" count)))))
- (mailsync-update %mailsync-default-terms)
- (mailsync-notify (mailsync-count-new-messages))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement