aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2021-01-04 14:51:32 +0100
committerÓscar Nájera <hi@oscarnajera.com>2021-01-04 14:51:32 +0100
commit61e0046810208047fcca0a1d742787b62b32c448 (patch)
tree3eb8b6c7e9cd07d24aa378d6361f6c2ec744c22c /bin
parentab024cbc16a629c9a29d61807e506a020f6984d3 (diff)
downloaddotfiles-61e0046810208047fcca0a1d742787b62b32c448.tar.gz
dotfiles-61e0046810208047fcca0a1d742787b62b32c448.tar.bz2
dotfiles-61e0046810208047fcca0a1d742787b62b32c448.zip
Using macros for db and query on notmuch
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tagmail57
1 files changed, 28 insertions, 29 deletions
diff --git a/bin/tagmail b/bin/tagmail
index fa6d6a4..2d65365 100755
--- a/bin/tagmail
+++ b/bin/tagmail
@@ -49,15 +49,15 @@
(list subject files)))))
(define (delete-email-files! options)
- (let* ((ffi-db (nm-open-database (assq-ref options 'mail-repo) 0))
- (to-delete (nm-query-db ffi-db "tag:deleted")))
+ (with-nm-database
+ (ffi-db (assq-ref options 'mail-repo) 0)
+ (with-nm-query
+ (ffi-db to-delete "tag:deleted")
(display (string-append
(colorize-string "[DELETE] " 'BOLD 'YELLOW)
(number->string (nm-count-messages to-delete))
" files marked\n"))
- (on-all-messages-filenames to-delete delete-file "rm" (option-ref options 'dry-run #f))
- (notmuch_query_destroy to-delete)
- (notmuch_database_destroy ffi-db)))
+ (on-all-messages-filenames to-delete delete-file "rm" (option-ref options 'dry-run #f)))))
(define (move-mail! options account query start-dir end-dir)
(define (move-file uidvalidity target-folder)
@@ -70,22 +70,21 @@
(unless (option-ref options 'dry-run #f)
(rename-file file target-file)))))
- (let* ((mail-repo (assq-ref options 'mail-repo))
- (ffi-db (nm-open-database mail-repo 0))
- (target-folder (format #f "~a~a/~a" mail-repo account end-dir))
- (uidvalidity (get-folder-uidvalidity target-folder))
- (to-move (nm-query-db ffi-db
- (format #f "~a and folder:~a/~a" query account start-dir))))
- (display (string-append
- (colorize-string "[MOVE] " 'BOLD 'YELLOW)
- (number->string (nm-count-messages to-move))
- " messages marked in "
- (colorize-string account 'GREEN 'BOLD)
- "\n"))
- (on-all-messages-filenames to-move (move-file uidvalidity target-folder) "mv"
- (option-ref options 'dry-run #f))
- (notmuch_query_destroy to-move)
- (notmuch_database_destroy ffi-db)))
+ (let ((mail-repo (assq-ref options 'mail-repo)))
+ (with-nm-database
+ (ffi-db mail-repo 0)
+ (let* ((target-folder (format #f "~a~a/~a" mail-repo account end-dir))
+ (uidvalidity (get-folder-uidvalidity target-folder)))
+ (with-nm-query
+ (ffi-db to-move (format #f "~a and folder:~a/~a" query account start-dir))
+ (display (string-append
+ (colorize-string "[MOVE] " 'BOLD 'YELLOW)
+ (number->string (nm-count-messages to-move))
+ " messages marked in "
+ (colorize-string account 'GREEN 'BOLD)
+ "\n"))
+ (on-all-messages-filenames to-move (move-file uidvalidity target-folder) "mv"
+ (option-ref options 'dry-run #f)))))))
(define (apply-tags-to-message options tags)
(lambda (message)
@@ -204,11 +203,11 @@
(display (colorize-string "[notmuch new]\n" 'BOLD 'YELLOW))
(system "notmuch new"))
- (let ((ffi-db (nm-open-database (assq-ref options 'mail-repo) 1))
- (new (not (option-ref options 'all #f))))
- (list-tag options ffi-db new)
- (display (colorize-string "[TAG rules]\n" 'BOLD 'YELLOW))
- (notmuch-tag options ffi-db tag-rules new)
- (clear-inbox options ffi-db)
- (tag-spam options ffi-db "tag:inbox")
- (notmuch_database_destroy ffi-db))))
+ (with-nm-database
+ (ffi-db (assq-ref options 'mail-repo) 1)
+ (let ((new (not (option-ref options 'all #f))))
+ (list-tag options ffi-db new)
+ (display (colorize-string "[TAG rules]\n" 'BOLD 'YELLOW))
+ (notmuch-tag options ffi-db tag-rules new)
+ (clear-inbox options ffi-db)
+ (tag-spam options ffi-db "tag:inbox")))))