aboutsummaryrefslogtreecommitdiffstats
path: root/bin/tagmail
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2021-01-04 15:12:52 +0100
committerÓscar Nájera <hi@oscarnajera.com>2021-01-04 15:12:52 +0100
commit930b01bd09f42be77520b753c6068b7710c98c4e (patch)
tree276e0af87507ed0d742dfa6f47680646906e4fdd /bin/tagmail
parent61e0046810208047fcca0a1d742787b62b32c448 (diff)
downloaddotfiles-930b01bd09f42be77520b753c6068b7710c98c4e.tar.gz
dotfiles-930b01bd09f42be77520b753c6068b7710c98c4e.tar.bz2
dotfiles-930b01bd09f42be77520b753c6068b7710c98c4e.zip
Macros for queries
Diffstat (limited to 'bin/tagmail')
-rwxr-xr-xbin/tagmail62
1 files changed, 32 insertions, 30 deletions
diff --git a/bin/tagmail b/bin/tagmail
index 2d65365..d8cda62 100755
--- a/bin/tagmail
+++ b/bin/tagmail
@@ -24,6 +24,7 @@
(ice-9 regex)
(ice-9 receive)
(mail-tools)
+ (utils)
(srfi srfi-1)
(system ffi-help-rt)
(system foreign)
@@ -95,32 +96,32 @@
(define (notmuch-tag options ffi-db rules new)
(map (lambda (rule)
(match-let* (((tags query-str) (with-new rule new))
- (info (if (null? (cddr rule)) query-str (caddr rule)))
- (query (nm-query-db ffi-db query-str)))
- (simple-format #t " ~a messages: ~a~a~%"
- (nm-count-messages query)
- (if (string=? info query-str) ""
- (string-append info " | "))
- tags)
- (nm-iter messages (nm-result-messages query) (apply-tags-to-message options tags))
- (notmuch_query_destroy query)))
+ (info (if (null? (cddr rule)) query-str (caddr rule))))
+ (with-nm-query
+ (ffi-db query query-str)
+ (simple-format #t " ~a messages: ~a~a~%"
+ (nm-count-messages query)
+ (if (string=? info query-str) ""
+ (string-append info " | "))
+ tags)
+ (nm-iter messages (nm-result-messages query) (apply-tags-to-message options tags)))))
rules))
(define (list-tag options ffi-db new)
(display (colorize-string "[LISTS filters]\n" 'BOLD 'YELLOW))
(match-let* (((tags-str query-str) (with-new '("+lists" "not tag:lists") new))
- (reg (make-regexp "<([a-z0-9=_-]+)\\." regexp/icase))
- (query (nm-query-db ffi-db query-str))
- (result (nm-iter
- messages (nm-result-messages query)
- (lambda (msg*)
- (and-let* ((list-id (regexp-exec reg (nm-header msg* "list-id")))
- (tags (format #f "~a +lists/~a" tags-str
- (string-downcase (match:substring list-id 1)))))
- ((apply-tags-to-message options tags) msg*))))))
- (simple-format #t " ~a messages belonging to lists~%"
- (length (filter identity result)))
- (notmuch_query_destroy query)))
+ (reg (make-regexp "<([a-z0-9=_-]+)\\." regexp/icase)))
+ (with-nm-query
+ (ffi-db query query-str)
+ (->> (lambda (msg*)
+ (and-let* ((list-id (regexp-exec reg (nm-header msg* "list-id")))
+ (tags (format #f "~a +lists/~a" tags-str
+ (string-downcase (match:substring list-id 1)))))
+ ((apply-tags-to-message options tags) msg*)))
+ (nm-iter messages (nm-result-messages query))
+ (filter identity)
+ length
+ (simple-format #t " ~a messages belonging to lists~%")))))
(define (spam-channel push result)
(setvbuf push 'line)
@@ -145,15 +146,16 @@
"bogofilter -bTv"
(lambda (push result)
(display (colorize-string "[SPAM Flag]\n" 'BOLD 'YELLOW))
- (let* ((spam? (spam-channel push result))
- (query (nm-query-db ffi-db query-str))
- (result (nm-iter messages (nm-result-messages query)
- (lambda (message)
- (when (spam? (pointer->string (notmuch_message_get_filename message)))
- ((apply-tags-to-message options "+spam -inbox") message))))))
- (format #t " ~a messages added to spam~%"
- (length (filter boolean? result)))
- (notmuch_query_destroy query)))))
+ (let ((spam? (spam-channel push result)))
+ (with-nm-query
+ (ffi-db query query-str)
+ (->> (lambda (message)
+ (when (spam? (pointer->string (notmuch_message_get_filename message)))
+ ((apply-tags-to-message options "+spam -inbox") message)))
+ (nm-iter messages (nm-result-messages query))
+ (filter boolean?)
+ length
+ (format #t " ~a messages added to spam~%")))))))
(define tag-rules
'(("+ci" "from:travis-ci.com or from:travis-ci.org or from:appveyor.com or from:circleci.com or from:mg.gitlab.com and subject:Pipeline")