From 82446b9c17ef384caca76de31437a430e12d8c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Mon, 23 Aug 2021 11:03:12 +0200 Subject: tagmail at work doesn't need specific folder --- bin/tagmail | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/tagmail b/bin/tagmail index 9f639b3..992bec1 100755 --- a/bin/tagmail +++ b/bin/tagmail @@ -17,6 +17,7 @@ (ffi notmuch) (ice-9 and-let-star) (ice-9 ftw) + (ice-9 format) (ice-9 getopt-long) (ice-9 match) (ice-9 popen) @@ -187,24 +188,30 @@ (notmuch-tag options ffi-db `(("+sent" ,sent "Emails I have sent") ("+inbox" "*" "Inbox for the rest")) #t))) + (define (main args) - (let* ((option-spec '((version (single-char #\V) (value #f)) + (let* ((mail-repo (string-append + (passwd:dir (getpwuid (geteuid))) + "/.mail/" )) + (option-spec '((version (single-char #\V) (value #f)) (help (single-char #\h) (value #f)) (all (value #f)) (dry-run (single-char #\n) (value #f)))) - (options (cons (cons 'mail-repo (string-append - (passwd:dir (getpwuid (geteuid))) - "/.mail/" )) + (options (cons (cons 'mail-repo mail-repo) (getopt-long args option-spec))) - (account (if (null? (assq-ref options '())) "hi_pers" (car (assq-ref options '()))))) + (account (assq-ref options '()) )) (delete-email-files! options) - (if (string=? account "hi_pers") - (move-mail! options account "tag:spam" "Inbox" "Junk")) + + (when (or (and (null? '()) + (access? (string-append mail-repo "hi_pers") W_OK)) + (and (string? account) + (string=? account "hi_pers"))) + (move-mail! options "hi_pers" "tag:spam" "Inbox" "Junk")) (unless (option-ref options 'dry-run #f) (display (colorize-string "[SYNC]\n" 'BOLD 'YELLOW)) - (system (string-append "mbsync " (if (null? (assq-ref options '())) " -a" account))) + (system (string-append "mbsync " (if (null? account) " -a" account))) (display (colorize-string "[notmuch new]\n" 'BOLD 'YELLOW)) (system "notmuch new")) -- cgit v1.2.3