aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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")))))